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/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_observer.h" |
14 #include "content/public/browser/web_ui_message_handler.h" | 15 #include "content/public/browser/web_ui_message_handler.h" |
15 #include "sync/js/js_controller.h" | 16 #include "sync/js/js_controller.h" |
16 #include "sync/js/js_event_handler.h" | 17 #include "sync/js/js_event_handler.h" |
17 #include "sync/js/js_reply_handler.h" | 18 #include "sync/js/js_reply_handler.h" |
18 | 19 |
19 class ProfileSyncService; | 20 class ProfileSyncService; |
20 | 21 |
21 // The implementation for the chrome://sync-internals page. | 22 // The implementation for the chrome://sync-internals page. |
22 class SyncInternalsMessageHandler | 23 class SyncInternalsMessageHandler |
23 : public content::WebUIMessageHandler, | 24 : public content::WebUIMessageHandler, |
24 public syncer::JsEventHandler, | 25 public syncer::JsEventHandler, |
25 public syncer::JsReplyHandler { | 26 public syncer::JsReplyHandler, |
| 27 public ProfileSyncServiceObserver { |
26 public: | 28 public: |
27 SyncInternalsMessageHandler(); | 29 SyncInternalsMessageHandler(); |
28 virtual ~SyncInternalsMessageHandler(); | 30 virtual ~SyncInternalsMessageHandler(); |
29 | 31 |
30 virtual void RegisterMessages() OVERRIDE; | 32 virtual void RegisterMessages() OVERRIDE; |
31 | 33 |
| 34 // Forwards requests to the JsController. |
32 void ForwardToJsController(const std::string& name, const base::ListValue*); | 35 void ForwardToJsController(const std::string& name, const base::ListValue*); |
33 void OnGetAboutInfo(const base::ListValue*); | 36 |
34 void OnGetListOfTypes(const base::ListValue*); | 37 // Fires an event to send updated info back to the page. |
| 38 void HandleRequestUpdatedAboutInfo(const base::ListValue* args); |
| 39 |
| 40 // Fires and event to send the list of types back to the page. |
| 41 void HandleRequestListOfTypes(const base::ListValue* args); |
35 | 42 |
36 // syncer::JsEventHandler implementation. | 43 // syncer::JsEventHandler implementation. |
37 virtual void HandleJsEvent( | 44 virtual void HandleJsEvent( |
38 const std::string& name, | 45 const std::string& name, |
39 const syncer::JsEventDetails& details) OVERRIDE; | 46 const syncer::JsEventDetails& details) OVERRIDE; |
40 | 47 |
41 // syncer::JsReplyHandler implementation. | 48 // syncer::JsReplyHandler implementation. |
42 virtual void HandleJsReply( | 49 virtual void HandleJsReply( |
43 const std::string& name, | 50 const std::string& name, |
44 const syncer::JsArgList& args) OVERRIDE; | 51 const syncer::JsArgList& args) OVERRIDE; |
45 | 52 |
| 53 // ProfileSyncServiceObserver implementation. |
| 54 virtual void OnStateChanged() OVERRIDE; |
| 55 |
46 private: | 56 private: |
| 57 // Helper function to register JsController function callbacks. |
47 void RegisterJsControllerCallback(const std::string& name); | 58 void RegisterJsControllerCallback(const std::string& name); |
| 59 |
| 60 // Fetches updated aboutInfo and sends it to the page in the form of an |
| 61 // onAboutInfoUpdated event. |
| 62 void SendAboutInfo(); |
| 63 |
48 ProfileSyncService* GetProfileSyncService(); | 64 ProfileSyncService* GetProfileSyncService(); |
49 | 65 |
50 base::WeakPtr<syncer::JsController> js_controller_; | 66 base::WeakPtr<syncer::JsController> js_controller_; |
51 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; | 67 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; |
52 | 68 |
53 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); | 69 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); |
54 }; | 70 }; |
55 | 71 |
56 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 72 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
OLD | NEW |