Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / invalidations_message_handler.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "components/invalidation/invalidation_logger_observer.h"
13 #include "components/invalidation/invalidation_util.h"
14 #include "content/public/browser/web_ui_message_handler.h"
15
16 class Profile;
17
18 namespace invalidation {
19 class InvalidationLogger;
20 }  // namespace invalidation
21
22 namespace syncer {
23 class InvalidationHandler;
24 }  // namespace syncer
25
26 // The implementation for the chrome://invalidations page.
27 class InvalidationsMessageHandler
28     : public content::WebUIMessageHandler,
29       public invalidation::InvalidationLoggerObserver {
30  public:
31   InvalidationsMessageHandler();
32   ~InvalidationsMessageHandler() override;
33
34   // Implementation of InvalidationLoggerObserver.
35   void OnRegistrationChange(
36       const std::multiset<std::string>& registered_handlers) override;
37   void OnStateChange(const syncer::InvalidatorState& new_state,
38                      const base::Time& last_change_timestamp) override;
39   void OnUpdateIds(const std::string& handler_name,
40                    const syncer::ObjectIdCountMap& ids_set) override;
41   void OnDebugMessage(const base::DictionaryValue& details) override;
42   void OnInvalidation(
43       const syncer::ObjectIdInvalidationMap& new_invalidations) override;
44   void OnDetailedStatus(const base::DictionaryValue& network_details) override;
45
46   // Implementation of WebUIMessageHandler.
47   void RegisterMessages() override;
48
49   // Triggers the logger to send the current state and objects ids.
50   void UpdateContent(const base::ListValue* args);
51
52   // Called by the javascript whenever the page is ready to receive messages.
53   void UIReady(const base::ListValue* args);
54
55   // Calls the InvalidationService for any internal details.
56   void HandleRequestDetailedStatus(const base::ListValue* args);
57
58  private:
59   // The pointer to the internal InvalidatorService InvalidationLogger.
60   // Used to get the information necessary to display to the JS and to
61   // register ourselves as Observers for any notifications.
62   invalidation::InvalidationLogger* logger_;
63
64   base::WeakPtrFactory<InvalidationsMessageHandler> weak_ptr_factory_;
65
66   DISALLOW_COPY_AND_ASSIGN(InvalidationsMessageHandler);
67 };
68
69 #endif  // CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_