| 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_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_observer.h" | 15 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 16 #include "chrome/browser/sync/protocol_event_observer.h" | 16 #include "chrome/browser/sync/protocol_event_observer.h" |
| 17 #include "content/public/browser/web_ui_message_handler.h" | 17 #include "content/public/browser/web_ui_message_handler.h" |
| 18 #include "sync/js/js_controller.h" | 18 #include "sync/js/js_controller.h" |
| 19 #include "sync/js/js_event_handler.h" | 19 #include "sync/js/js_event_handler.h" |
| 20 #include "sync/js/js_reply_handler.h" | |
| 21 | 20 |
| 22 class ProfileSyncService; | 21 class ProfileSyncService; |
| 23 | 22 |
| 24 // The implementation for the chrome://sync-internals page. | 23 // The implementation for the chrome://sync-internals page. |
| 25 class SyncInternalsMessageHandler | 24 class SyncInternalsMessageHandler |
| 26 : public content::WebUIMessageHandler, | 25 : public content::WebUIMessageHandler, |
| 27 public syncer::JsEventHandler, | 26 public syncer::JsEventHandler, |
| 28 public syncer::JsReplyHandler, | |
| 29 public ProfileSyncServiceObserver, | 27 public ProfileSyncServiceObserver, |
| 30 public browser_sync::ProtocolEventObserver { | 28 public browser_sync::ProtocolEventObserver { |
| 31 public: | 29 public: |
| 32 SyncInternalsMessageHandler(); | 30 SyncInternalsMessageHandler(); |
| 33 virtual ~SyncInternalsMessageHandler(); | 31 virtual ~SyncInternalsMessageHandler(); |
| 34 | 32 |
| 35 virtual void RegisterMessages() OVERRIDE; | 33 virtual void RegisterMessages() OVERRIDE; |
| 36 | 34 |
| 37 // Forwards requests to the JsController. | |
| 38 void ForwardToJsController(const std::string& name, const base::ListValue*); | |
| 39 | |
| 40 // Sets up observers to receive events and forward them to the UI. | 35 // Sets up observers to receive events and forward them to the UI. |
| 41 void HandleRegisterForEvents(const base::ListValue* args); | 36 void HandleRegisterForEvents(const base::ListValue* args); |
| 42 | 37 |
| 43 // Fires an event to send updated info back to the page. | 38 // Fires an event to send updated info back to the page. |
| 44 void HandleRequestUpdatedAboutInfo(const base::ListValue* args); | 39 void HandleRequestUpdatedAboutInfo(const base::ListValue* args); |
| 45 | 40 |
| 46 // Fires and event to send the list of types back to the page. | 41 // Fires and event to send the list of types back to the page. |
| 47 void HandleRequestListOfTypes(const base::ListValue* args); | 42 void HandleRequestListOfTypes(const base::ListValue* args); |
| 48 | 43 |
| 44 // Handler for getAllNodes message. Needs a |request_id| argument. |
| 45 void HandleGetAllNodes(const base::ListValue* args); |
| 46 |
| 49 // syncer::JsEventHandler implementation. | 47 // syncer::JsEventHandler implementation. |
| 50 virtual void HandleJsEvent( | 48 virtual void HandleJsEvent( |
| 51 const std::string& name, | 49 const std::string& name, |
| 52 const syncer::JsEventDetails& details) OVERRIDE; | 50 const syncer::JsEventDetails& details) OVERRIDE; |
| 53 | 51 |
| 54 // syncer::JsReplyHandler implementation. | 52 // Callback used in GetAllNodes. |
| 55 virtual void HandleJsReply( | 53 void OnReceivedAllNodes(int request_id, scoped_ptr<base::ListValue> nodes); |
| 56 const std::string& name, | |
| 57 const syncer::JsArgList& args) OVERRIDE; | |
| 58 | 54 |
| 59 // ProfileSyncServiceObserver implementation. | 55 // ProfileSyncServiceObserver implementation. |
| 60 virtual void OnStateChanged() OVERRIDE; | 56 virtual void OnStateChanged() OVERRIDE; |
| 61 | 57 |
| 62 // ProtocolEventObserver implementation. | 58 // ProtocolEventObserver implementation. |
| 63 virtual void OnProtocolEvent(const syncer::ProtocolEvent& e) OVERRIDE; | 59 virtual void OnProtocolEvent(const syncer::ProtocolEvent& e) OVERRIDE; |
| 64 | 60 |
| 65 private: | 61 private: |
| 66 // Helper function to register JsController function callbacks. | |
| 67 void RegisterJsControllerCallback(const std::string& name); | |
| 68 | |
| 69 // Fetches updated aboutInfo and sends it to the page in the form of an | 62 // Fetches updated aboutInfo and sends it to the page in the form of an |
| 70 // onAboutInfoUpdated event. | 63 // onAboutInfoUpdated event. |
| 71 void SendAboutInfo(); | 64 void SendAboutInfo(); |
| 72 | 65 |
| 73 ProfileSyncService* GetProfileSyncService(); | 66 ProfileSyncService* GetProfileSyncService(); |
| 74 | 67 |
| 75 base::WeakPtr<syncer::JsController> js_controller_; | 68 base::WeakPtr<syncer::JsController> js_controller_; |
| 76 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; | 69 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; |
| 77 | 70 |
| 78 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); | 71 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); |
| 79 }; | 72 }; |
| 80 | 73 |
| 81 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 74 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
| OLD | NEW |