• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "content/public/browser/web_ui_message_handler.h"
14 #include "sync/notifier/invalidation_util.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   virtual ~InvalidationsMessageHandler();
33 
34   // Implementation of InvalidationLoggerObserver.
35   virtual void OnRegistrationChange(
36       const std::multiset<std::string>& registered_handlers) OVERRIDE;
37   virtual void OnStateChange(const syncer::InvalidatorState& new_state,
38                              const base::Time& last_change_timestamp)
39       OVERRIDE;
40   virtual void OnUpdateIds(const std::string& handler_name,
41                            const syncer::ObjectIdCountMap& ids_set) OVERRIDE;
42   virtual void OnDebugMessage(const base::DictionaryValue& details) OVERRIDE;
43   virtual void OnInvalidation(
44       const syncer::ObjectIdInvalidationMap& new_invalidations) OVERRIDE;
45   virtual void OnDetailedStatus(const base::DictionaryValue& network_details)
46       OVERRIDE;
47 
48   // Implementation of WebUIMessageHandler.
49   virtual void RegisterMessages() OVERRIDE;
50 
51   // Triggers the logger to send the current state and objects ids.
52   void UpdateContent(const base::ListValue* args);
53 
54   // Called by the javascript whenever the page is ready to receive messages.
55   void UIReady(const base::ListValue* args);
56 
57   // Calls the InvalidationService for any internal details.
58   void HandleRequestDetailedStatus(const base::ListValue* args);
59 
60  private:
61   // The pointer to the internal InvalidatorService InvalidationLogger.
62   // Used to get the information necessary to display to the JS and to
63   // register ourselves as Observers for any notifications.
64   invalidation::InvalidationLogger* logger_;
65 
66   base::WeakPtrFactory<InvalidationsMessageHandler> weak_ptr_factory_;
67 
68   DISALLOW_COPY_AND_ASSIGN(InvalidationsMessageHandler);
69 };
70 
71 #endif  // CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_
72