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 <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/sync_driver/protocol_event_observer.h" | 16 #include "components/sync_driver/protocol_event_observer.h" |
17 #include "components/sync_driver/sync_service_observer.h" | 17 #include "components/sync_driver/sync_service_observer.h" |
18 #include "content/public/browser/web_ui_message_handler.h" | 18 #include "content/public/browser/web_ui_message_handler.h" |
19 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" | 19 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" |
20 #include "sync/js/js_controller.h" | 20 #include "sync/js/js_controller.h" |
21 #include "sync/js/js_event_handler.h" | 21 #include "sync/js/js_event_handler.h" |
22 | 22 |
23 class ProfileSyncService; | 23 class ProfileSyncService; |
24 class SigninManagerBase; | 24 class SigninManagerBase; |
25 | 25 |
26 namespace sync_driver { | 26 namespace sync_driver { |
27 class SyncService; | 27 class SyncService; |
28 } // namespace sync_driver | 28 } // namespace sync_driver |
29 | 29 |
30 // Interface to abstract away the creation of the about-sync value dictionary. | 30 // Interface to abstract away the creation of the about-sync value dictionary. |
31 class AboutSyncDataExtractor { | 31 class AboutSyncDataExtractor { |
32 public: | 32 public: |
33 // Given state about sync, extracts various interesting fields and populates | 33 // Given state about sync, extracts various interesting fields and populates |
34 // a tree of base::Value objects. | 34 // a tree of base::Value objects. |
35 virtual scoped_ptr<base::DictionaryValue> ConstructAboutInformation( | 35 virtual std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( |
36 sync_driver::SyncService* service, | 36 sync_driver::SyncService* service, |
37 SigninManagerBase* signin) = 0; | 37 SigninManagerBase* signin) = 0; |
38 virtual ~AboutSyncDataExtractor() {} | 38 virtual ~AboutSyncDataExtractor() {} |
39 }; | 39 }; |
40 | 40 |
41 // The implementation for the chrome://sync-internals page. | 41 // The implementation for the chrome://sync-internals page. |
42 class SyncInternalsMessageHandler : public content::WebUIMessageHandler, | 42 class SyncInternalsMessageHandler : public content::WebUIMessageHandler, |
43 public syncer::JsEventHandler, | 43 public syncer::JsEventHandler, |
44 public sync_driver::SyncServiceObserver, | 44 public sync_driver::SyncServiceObserver, |
45 public browser_sync::ProtocolEventObserver, | 45 public browser_sync::ProtocolEventObserver, |
(...skipping 17 matching lines...) Expand all Loading... |
63 void HandleRequestListOfTypes(const base::ListValue* args); | 63 void HandleRequestListOfTypes(const base::ListValue* args); |
64 | 64 |
65 // Handler for getAllNodes message. Needs a |request_id| argument. | 65 // Handler for getAllNodes message. Needs a |request_id| argument. |
66 void HandleGetAllNodes(const base::ListValue* args); | 66 void HandleGetAllNodes(const base::ListValue* args); |
67 | 67 |
68 // syncer::JsEventHandler implementation. | 68 // syncer::JsEventHandler implementation. |
69 void HandleJsEvent(const std::string& name, | 69 void HandleJsEvent(const std::string& name, |
70 const syncer::JsEventDetails& details) override; | 70 const syncer::JsEventDetails& details) override; |
71 | 71 |
72 // Callback used in GetAllNodes. | 72 // Callback used in GetAllNodes. |
73 void OnReceivedAllNodes(int request_id, scoped_ptr<base::ListValue> nodes); | 73 void OnReceivedAllNodes(int request_id, |
| 74 std::unique_ptr<base::ListValue> nodes); |
74 | 75 |
75 // sync_driver::SyncServiceObserver implementation. | 76 // sync_driver::SyncServiceObserver implementation. |
76 void OnStateChanged() override; | 77 void OnStateChanged() override; |
77 | 78 |
78 // ProtocolEventObserver implementation. | 79 // ProtocolEventObserver implementation. |
79 void OnProtocolEvent(const syncer::ProtocolEvent& e) override; | 80 void OnProtocolEvent(const syncer::ProtocolEvent& e) override; |
80 | 81 |
81 // TypeDebugInfoObserver implementation. | 82 // TypeDebugInfoObserver implementation. |
82 void OnCommitCountersUpdated(syncer::ModelType type, | 83 void OnCommitCountersUpdated(syncer::ModelType type, |
83 const syncer::CommitCounters& counters) override; | 84 const syncer::CommitCounters& counters) override; |
84 void OnUpdateCountersUpdated(syncer::ModelType type, | 85 void OnUpdateCountersUpdated(syncer::ModelType type, |
85 const syncer::UpdateCounters& counters) override; | 86 const syncer::UpdateCounters& counters) override; |
86 void OnStatusCountersUpdated(syncer::ModelType type, | 87 void OnStatusCountersUpdated(syncer::ModelType type, |
87 const syncer::StatusCounters& counters) override; | 88 const syncer::StatusCounters& counters) override; |
88 | 89 |
89 // Helper to emit counter updates. | 90 // Helper to emit counter updates. |
90 // | 91 // |
91 // Used in implementation of On*CounterUpdated methods. Emits the given | 92 // Used in implementation of On*CounterUpdated methods. Emits the given |
92 // dictionary value with additional data to specify the model type and | 93 // dictionary value with additional data to specify the model type and |
93 // counter type. | 94 // counter type. |
94 void EmitCounterUpdate(syncer::ModelType type, | 95 void EmitCounterUpdate(syncer::ModelType type, |
95 const std::string& counter_type, | 96 const std::string& counter_type, |
96 scoped_ptr<base::DictionaryValue> value); | 97 std::unique_ptr<base::DictionaryValue> value); |
97 | 98 |
98 protected: | 99 protected: |
99 // Constructor used for unit testing to override the about sync info. | 100 // Constructor used for unit testing to override the about sync info. |
100 SyncInternalsMessageHandler( | 101 SyncInternalsMessageHandler( |
101 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor); | 102 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor); |
102 | 103 |
103 private: | 104 private: |
104 // Fetches updated aboutInfo and sends it to the page in the form of an | 105 // Fetches updated aboutInfo and sends it to the page in the form of an |
105 // onAboutInfoUpdated event. | 106 // onAboutInfoUpdated event. |
106 void SendAboutInfo(); | 107 void SendAboutInfo(); |
107 | 108 |
108 ProfileSyncService* GetProfileSyncService(); | 109 ProfileSyncService* GetProfileSyncService(); |
109 | 110 |
110 base::WeakPtr<syncer::JsController> js_controller_; | 111 base::WeakPtr<syncer::JsController> js_controller_; |
111 | 112 |
112 // A flag used to prevent double-registration with ProfileSyncService. | 113 // A flag used to prevent double-registration with ProfileSyncService. |
113 bool is_registered_ = false; | 114 bool is_registered_ = false; |
114 | 115 |
115 // A flag used to prevent double-registration as TypeDebugInfoObserver with | 116 // A flag used to prevent double-registration as TypeDebugInfoObserver with |
116 // ProfileSyncService. | 117 // ProfileSyncService. |
117 bool is_registered_for_counters_ = false; | 118 bool is_registered_for_counters_ = false; |
118 | 119 |
119 // An abstraction of who creates the about sync info value map. | 120 // An abstraction of who creates the about sync info value map. |
120 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor_; | 121 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor_; |
121 | 122 |
122 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; | 123 base::WeakPtrFactory<SyncInternalsMessageHandler> weak_ptr_factory_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); | 125 DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); |
125 }; | 126 }; |
126 | 127 |
127 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ | 128 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ |
OLD | NEW |