| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/invalidation/invalidation_logger_observer.h" | 11 #include "chrome/browser/invalidation/invalidation_logger_observer.h" |
| 12 #include "content/public/browser/web_ui_message_handler.h" | 12 #include "content/public/browser/web_ui_message_handler.h" |
| 13 #include "sync/notifier/invalidation_util.h" |
| 13 | 14 |
| 14 class Profile; | 15 class Profile; |
| 15 | 16 |
| 16 namespace invalidation { | 17 namespace invalidation { |
| 17 class InvalidationLogger; | 18 class InvalidationLogger; |
| 18 } // namespace invalidation | 19 } // namespace invalidation |
| 19 | 20 |
| 21 namespace syncer { |
| 22 class InvalidationHandler; |
| 23 } // namespace syncer |
| 24 |
| 20 // The implementation for the chrome://invalidations page. | 25 // The implementation for the chrome://invalidations page. |
| 21 class InvalidationsMessageHandler | 26 class InvalidationsMessageHandler |
| 22 : public content::WebUIMessageHandler, | 27 : public content::WebUIMessageHandler, |
| 23 public invalidation::InvalidationLoggerObserver { | 28 public invalidation::InvalidationLoggerObserver { |
| 24 public: | 29 public: |
| 25 InvalidationsMessageHandler(); | 30 InvalidationsMessageHandler(); |
| 26 virtual ~InvalidationsMessageHandler(); | 31 virtual ~InvalidationsMessageHandler(); |
| 27 | 32 |
| 28 // Implementation of InvalidationLoggerObserver | 33 // Implementation of InvalidationLoggerObserver. |
| 29 virtual void OnRegistration(const base::DictionaryValue& details) OVERRIDE; | 34 virtual void OnRegistration(const base::DictionaryValue& details) OVERRIDE; |
| 30 virtual void OnUnregistration(const base::DictionaryValue& details) OVERRIDE; | 35 virtual void OnUnregistration(const base::DictionaryValue& details) OVERRIDE; |
| 31 virtual void OnStateChange(const syncer::InvalidatorState& newState) OVERRIDE; | 36 virtual void OnStateChange(const syncer::InvalidatorState& new_state) |
| 32 virtual void OnUpdateIds(const base::DictionaryValue& details) OVERRIDE; | 37 OVERRIDE; |
| 38 virtual void OnUpdateIds(const std::string& handler_name, |
| 39 const syncer::ObjectIdSet& ids_set) OVERRIDE; |
| 33 virtual void OnDebugMessage(const base::DictionaryValue& details) OVERRIDE; | 40 virtual void OnDebugMessage(const base::DictionaryValue& details) OVERRIDE; |
| 34 virtual void OnInvalidation( | 41 virtual void OnInvalidation( |
| 35 const syncer::ObjectIdInvalidationMap& newInvalidations) OVERRIDE; | 42 const syncer::ObjectIdInvalidationMap& new_invalidations) OVERRIDE; |
| 36 | 43 |
| 37 // Implementation of WebUIMessageHandler | 44 // Implementation of WebUIMessageHandler. |
| 38 virtual void RegisterMessages() OVERRIDE; | 45 virtual void RegisterMessages() OVERRIDE; |
| 39 | 46 |
| 47 // Triggers the logger to send the current state and objects ids. |
| 40 void UpdateContent(const base::ListValue* args); | 48 void UpdateContent(const base::ListValue* args); |
| 49 |
| 50 // Called by the javascript whenever the page is ready to receive messages. |
| 41 void UIReady(const base::ListValue* args); | 51 void UIReady(const base::ListValue* args); |
| 42 | 52 |
| 43 private: | 53 private: |
| 54 // Transforms a set to a ListValue in order to be automatically |
| 55 // transformed to a JavaScript array of objects. |
| 56 scoped_ptr<base::ListValue> ObjectIdSetToList( |
| 57 const syncer::ObjectIdSet& ids_set); |
| 58 |
| 44 // The pointer to the internal InvalidatorService InvalidationLogger. | 59 // The pointer to the internal InvalidatorService InvalidationLogger. |
| 45 // Used to get the information necessary to display to the JS and to | 60 // Used to get the information necessary to display to the JS and to |
| 46 // register ourselves as Observers for any notifications. | 61 // register ourselves as Observers for any notifications. |
| 47 invalidation::InvalidationLogger* logger_; | 62 invalidation::InvalidationLogger* logger_; |
| 48 // Check to see if we are already registered as an observer | 63 |
| 49 bool isRegistered; | 64 // Check to see if we are already registered as an observer. |
| 65 bool is_registered_; |
| 66 |
| 50 DISALLOW_COPY_AND_ASSIGN(InvalidationsMessageHandler); | 67 DISALLOW_COPY_AND_ASSIGN(InvalidationsMessageHandler); |
| 51 }; | 68 }; |
| 52 | 69 |
| 53 #endif // CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ | 70 #endif // CHROME_BROWSER_UI_WEBUI_INVALIDATIONS_MESSAGE_HANDLER_H_ |
| OLD | NEW |