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/internal_api/public/sessions/type_debug_info_observer.h" |
18 #include "sync/js/js_controller.h" | 19 #include "sync/js/js_controller.h" |
19 #include "sync/js/js_event_handler.h" | 20 #include "sync/js/js_event_handler.h" |
20 | 21 |
21 class ProfileSyncService; | 22 class ProfileSyncService; |
22 | 23 |
23 // The implementation for the chrome://sync-internals page. | 24 // The implementation for the chrome://sync-internals page. |
24 class SyncInternalsMessageHandler | 25 class SyncInternalsMessageHandler : public content::WebUIMessageHandler, |
25 : public content::WebUIMessageHandler, | 26 public syncer::JsEventHandler, |
26 public syncer::JsEventHandler, | 27 public ProfileSyncServiceObserver, |
27 public ProfileSyncServiceObserver, | 28 public browser_sync::ProtocolEventObserver, |
28 public browser_sync::ProtocolEventObserver { | 29 public syncer::TypeDebugInfoObserver { |
29 public: | 30 public: |
30 SyncInternalsMessageHandler(); | 31 SyncInternalsMessageHandler(); |
31 virtual ~SyncInternalsMessageHandler(); | 32 virtual ~SyncInternalsMessageHandler(); |
32 | 33 |
33 virtual void RegisterMessages() OVERRIDE; | 34 virtual void RegisterMessages() OVERRIDE; |
34 | 35 |
35 // Sets up observers to receive events and forward them to the UI. | 36 // Sets up observers to receive events and forward them to the UI. |
36 void HandleRegisterForEvents(const base::ListValue* args); | 37 void HandleRegisterForEvents(const base::ListValue* args); |
37 | 38 |
| 39 // Sets up observers to receive per-type counters and forward them to the UI. |
| 40 void HandleRegisterForPerTypeCounters(const base::ListValue* args); |
| 41 |
38 // Fires an event to send updated info back to the page. | 42 // Fires an event to send updated info back to the page. |
39 void HandleRequestUpdatedAboutInfo(const base::ListValue* args); | 43 void HandleRequestUpdatedAboutInfo(const base::ListValue* args); |
40 | 44 |
41 // Fires and event to send the list of types back to the page. | 45 // Fires and event to send the list of types back to the page. |
42 void HandleRequestListOfTypes(const base::ListValue* args); | 46 void HandleRequestListOfTypes(const base::ListValue* args); |
43 | 47 |
44 // Handler for getAllNodes message. Needs a |request_id| argument. | 48 // Handler for getAllNodes message. Needs a |request_id| argument. |
45 void HandleGetAllNodes(const base::ListValue* args); | 49 void HandleGetAllNodes(const base::ListValue* args); |
46 | 50 |
47 // syncer::JsEventHandler implementation. | 51 // syncer::JsEventHandler implementation. |
48 virtual void HandleJsEvent( | 52 virtual void HandleJsEvent( |
49 const std::string& name, | 53 const std::string& name, |
50 const syncer::JsEventDetails& details) OVERRIDE; | 54 const syncer::JsEventDetails& details) OVERRIDE; |
51 | 55 |
52 // Callback used in GetAllNodes. | 56 // Callback used in GetAllNodes. |
53 void OnReceivedAllNodes(int request_id, scoped_ptr<base::ListValue> nodes); | 57 void OnReceivedAllNodes(int request_id, scoped_ptr<base::ListValue> nodes); |
54 | 58 |
55 // ProfileSyncServiceObserver implementation. | 59 // ProfileSyncServiceObserver implementation. |
56 virtual void OnStateChanged() OVERRIDE; | 60 virtual void OnStateChanged() OVERRIDE; |
57 | 61 |
58 // ProtocolEventObserver implementation. | 62 // ProtocolEventObserver implementation. |
59 virtual void OnProtocolEvent(const syncer::ProtocolEvent& e) OVERRIDE; | 63 virtual void OnProtocolEvent(const syncer::ProtocolEvent& e) OVERRIDE; |
60 | 64 |
| 65 // TypeDebugInfoObserver implementation. |
| 66 virtual void OnCommitCountersUpdated( |
| 67 syncer::ModelType type, |
| 68 const syncer::CommitCounters& counters) OVERRIDE; |
| 69 virtual void OnUpdateCountersUpdated( |
| 70 syncer::ModelType type, |
| 71 const syncer::UpdateCounters& counters) OVERRIDE; |
| 72 virtual void OnStatusCountersUpdated( |
| 73 syncer::ModelType type, |
| 74 const syncer::StatusCounters& counters) OVERRIDE; |
| 75 |
| 76 // Helper to emit counter updates. |
| 77 // |
| 78 // Used in implementation of On*CounterUpdated methods. Emits the given |
| 79 // dictionary value with additional data to specify the model type and |
| 80 // counter type. |
| 81 void EmitCounterUpdate(syncer::ModelType type, |
| 82 const std::string& counter_type, |
| 83 scoped_ptr<base::DictionaryValue> value); |
| 84 |
61 private: | 85 private: |
62 // Fetches updated aboutInfo and sends it to the page in the form of an | 86 // Fetches updated aboutInfo and sends it to the page in the form of an |
63 // onAboutInfoUpdated event. | 87 // onAboutInfoUpdated event. |
64 void SendAboutInfo(); | 88 void SendAboutInfo(); |
65 | 89 |
66 ProfileSyncService* GetProfileSyncService(); | 90 ProfileSyncService* GetProfileSyncService(); |
67 | 91 |
68 base::WeakPtr<syncer::JsController> js_controller_; | 92 base::WeakPtr<syncer::JsController> js_controller_; |
69 | 93 |
70 // A flag used to prevent double-registration with ProfileSyncService. | 94 // A flag used to prevent double-registration with ProfileSyncService. |
71 bool is_registered_; | 95 bool is_registered_; |
72 | 96 |
| 97 // A flag used to prevent double-registration as TypeDebugInfoObserver with |
| 98 // ProfileSyncService. |
| 99 bool is_registered_for_counters_; |
| 100 |
73 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; | 101 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; |
74 | 102 |
75 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); | 103 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); |
76 }; | 104 }; |
77 | 105 |
78 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 106 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
OLD | NEW |