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 #include "chrome/browser/ui/webui/sync_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
13 #include "chrome/common/channel_info.h" | 14 #include "chrome/common/channel_info.h" |
14 #include "components/browser_sync/browser/profile_sync_service.h" | 15 #include "components/browser_sync/browser/profile_sync_service.h" |
15 #include "components/signin/core/browser/signin_manager_base.h" | 16 #include "components/signin/core/browser/signin_manager_base.h" |
16 #include "components/sync_driver/about_sync_util.h" | 17 #include "components/sync_driver/about_sync_util.h" |
17 #include "components/sync_driver/sync_service.h" | 18 #include "components/sync_driver/sync_service.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
20 #include "sync/internal_api/public/events/protocol_event.h" | 21 #include "sync/internal_api/public/events/protocol_event.h" |
21 #include "sync/internal_api/public/sessions/commit_counters.h" | 22 #include "sync/internal_api/public/sessions/commit_counters.h" |
22 #include "sync/internal_api/public/sessions/status_counters.h" | 23 #include "sync/internal_api/public/sessions/status_counters.h" |
23 #include "sync/internal_api/public/sessions/update_counters.h" | 24 #include "sync/internal_api/public/sessions/update_counters.h" |
24 #include "sync/internal_api/public/util/weak_handle.h" | 25 #include "sync/internal_api/public/util/weak_handle.h" |
25 #include "sync/js/js_event_details.h" | 26 #include "sync/js/js_event_details.h" |
26 | 27 |
27 using syncer::JsEventDetails; | 28 using syncer::JsEventDetails; |
28 using syncer::ModelTypeSet; | 29 using syncer::ModelTypeSet; |
29 using syncer::WeakHandle; | 30 using syncer::WeakHandle; |
30 | 31 |
31 namespace { | 32 namespace { |
32 class UtilAboutSyncDataExtractor : public AboutSyncDataExtractor { | 33 class UtilAboutSyncDataExtractor : public AboutSyncDataExtractor { |
33 public: | 34 public: |
34 scoped_ptr<base::DictionaryValue> ConstructAboutInformation( | 35 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( |
35 sync_driver::SyncService* service, | 36 sync_driver::SyncService* service, |
36 SigninManagerBase* signin) override { | 37 SigninManagerBase* signin) override { |
37 return sync_driver::sync_ui_util::ConstructAboutInformation( | 38 return sync_driver::sync_ui_util::ConstructAboutInformation( |
38 service, signin, chrome::GetChannel()); | 39 service, signin, chrome::GetChannel()); |
39 } | 40 } |
40 }; | 41 }; |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 SyncInternalsMessageHandler::SyncInternalsMessageHandler() | 44 SyncInternalsMessageHandler::SyncInternalsMessageHandler() |
44 : SyncInternalsMessageHandler( | 45 : SyncInternalsMessageHandler( |
45 make_scoped_ptr(new UtilAboutSyncDataExtractor())) {} | 46 base::WrapUnique(new UtilAboutSyncDataExtractor())) {} |
46 | 47 |
47 SyncInternalsMessageHandler::SyncInternalsMessageHandler( | 48 SyncInternalsMessageHandler::SyncInternalsMessageHandler( |
48 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor) | 49 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor) |
49 : about_sync_data_extractor_(std::move(about_sync_data_extractor)), | 50 : about_sync_data_extractor_(std::move(about_sync_data_extractor)), |
50 weak_ptr_factory_(this) {} | 51 weak_ptr_factory_(this) {} |
51 | 52 |
52 SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { | 53 SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { |
53 if (js_controller_) | 54 if (js_controller_) |
54 js_controller_->RemoveJsEventHandler(this); | 55 js_controller_->RemoveJsEventHandler(this); |
55 | 56 |
56 ProfileSyncService* service = GetProfileSyncService(); | 57 ProfileSyncService* service = GetProfileSyncService(); |
57 if (service && service->HasObserver(this)) { | 58 if (service && service->HasObserver(this)) { |
58 service->RemoveObserver(this); | 59 service->RemoveObserver(this); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( | 130 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( |
130 const base::ListValue* args) { | 131 const base::ListValue* args) { |
131 DCHECK(args->empty()); | 132 DCHECK(args->empty()); |
132 SendAboutInfo(); | 133 SendAboutInfo(); |
133 } | 134 } |
134 | 135 |
135 void SyncInternalsMessageHandler::HandleRequestListOfTypes( | 136 void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
136 const base::ListValue* args) { | 137 const base::ListValue* args) { |
137 DCHECK(args->empty()); | 138 DCHECK(args->empty()); |
138 base::DictionaryValue event_details; | 139 base::DictionaryValue event_details; |
139 scoped_ptr<base::ListValue> type_list(new base::ListValue()); | 140 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); |
140 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | 141 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
141 for (ModelTypeSet::Iterator it = protocol_types.First(); | 142 for (ModelTypeSet::Iterator it = protocol_types.First(); |
142 it.Good(); it.Inc()) { | 143 it.Good(); it.Inc()) { |
143 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); | 144 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); |
144 } | 145 } |
145 event_details.Set(sync_driver::sync_ui_util::kTypes, type_list.release()); | 146 event_details.Set(sync_driver::sync_ui_util::kTypes, type_list.release()); |
146 web_ui()->CallJavascriptFunction( | 147 web_ui()->CallJavascriptFunction( |
147 sync_driver::sync_ui_util::kDispatchEvent, | 148 sync_driver::sync_ui_util::kDispatchEvent, |
148 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), | 149 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), |
149 event_details); | 150 event_details); |
150 } | 151 } |
151 | 152 |
152 void SyncInternalsMessageHandler::HandleGetAllNodes( | 153 void SyncInternalsMessageHandler::HandleGetAllNodes( |
153 const base::ListValue* args) { | 154 const base::ListValue* args) { |
154 DCHECK_EQ(1U, args->GetSize()); | 155 DCHECK_EQ(1U, args->GetSize()); |
155 int request_id = 0; | 156 int request_id = 0; |
156 bool success = args->GetInteger(0, &request_id); | 157 bool success = args->GetInteger(0, &request_id); |
157 DCHECK(success); | 158 DCHECK(success); |
158 | 159 |
159 ProfileSyncService* service = GetProfileSyncService(); | 160 ProfileSyncService* service = GetProfileSyncService(); |
160 if (service) { | 161 if (service) { |
161 service->GetAllNodes( | 162 service->GetAllNodes( |
162 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, | 163 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, |
163 weak_ptr_factory_.GetWeakPtr(), request_id)); | 164 weak_ptr_factory_.GetWeakPtr(), request_id)); |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
167 void SyncInternalsMessageHandler::OnReceivedAllNodes( | 168 void SyncInternalsMessageHandler::OnReceivedAllNodes( |
168 int request_id, | 169 int request_id, |
169 scoped_ptr<base::ListValue> nodes) { | 170 std::unique_ptr<base::ListValue> nodes) { |
170 base::FundamentalValue id(request_id); | 171 base::FundamentalValue id(request_id); |
171 web_ui()->CallJavascriptFunction( | 172 web_ui()->CallJavascriptFunction( |
172 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); | 173 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); |
173 } | 174 } |
174 | 175 |
175 void SyncInternalsMessageHandler::OnStateChanged() { | 176 void SyncInternalsMessageHandler::OnStateChanged() { |
176 SendAboutInfo(); | 177 SendAboutInfo(); |
177 } | 178 } |
178 | 179 |
179 void SyncInternalsMessageHandler::OnProtocolEvent( | 180 void SyncInternalsMessageHandler::OnProtocolEvent( |
180 const syncer::ProtocolEvent& event) { | 181 const syncer::ProtocolEvent& event) { |
181 scoped_ptr<base::DictionaryValue> value( | 182 std::unique_ptr<base::DictionaryValue> value( |
182 syncer::ProtocolEvent::ToValue(event)); | 183 syncer::ProtocolEvent::ToValue(event)); |
183 web_ui()->CallJavascriptFunction( | 184 web_ui()->CallJavascriptFunction( |
184 sync_driver::sync_ui_util::kDispatchEvent, | 185 sync_driver::sync_ui_util::kDispatchEvent, |
185 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); | 186 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); |
186 } | 187 } |
187 | 188 |
188 void SyncInternalsMessageHandler::OnCommitCountersUpdated( | 189 void SyncInternalsMessageHandler::OnCommitCountersUpdated( |
189 syncer::ModelType type, | 190 syncer::ModelType type, |
190 const syncer::CommitCounters& counters) { | 191 const syncer::CommitCounters& counters) { |
191 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, | 192 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, |
(...skipping 10 matching lines...) Expand all Loading... |
202 void SyncInternalsMessageHandler::OnStatusCountersUpdated( | 203 void SyncInternalsMessageHandler::OnStatusCountersUpdated( |
203 syncer::ModelType type, | 204 syncer::ModelType type, |
204 const syncer::StatusCounters& counters) { | 205 const syncer::StatusCounters& counters) { |
205 EmitCounterUpdate(type, sync_driver::sync_ui_util::kStatus, | 206 EmitCounterUpdate(type, sync_driver::sync_ui_util::kStatus, |
206 counters.ToValue()); | 207 counters.ToValue()); |
207 } | 208 } |
208 | 209 |
209 void SyncInternalsMessageHandler::EmitCounterUpdate( | 210 void SyncInternalsMessageHandler::EmitCounterUpdate( |
210 syncer::ModelType type, | 211 syncer::ModelType type, |
211 const std::string& counter_type, | 212 const std::string& counter_type, |
212 scoped_ptr<base::DictionaryValue> value) { | 213 std::unique_ptr<base::DictionaryValue> value) { |
213 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 214 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
214 details->SetString(sync_driver::sync_ui_util::kModelType, | 215 details->SetString(sync_driver::sync_ui_util::kModelType, |
215 ModelTypeToString(type)); | 216 ModelTypeToString(type)); |
216 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); | 217 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); |
217 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); | 218 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); |
218 web_ui()->CallJavascriptFunction( | 219 web_ui()->CallJavascriptFunction( |
219 sync_driver::sync_ui_util::kDispatchEvent, | 220 sync_driver::sync_ui_util::kDispatchEvent, |
220 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), | 221 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), |
221 *details); | 222 *details); |
222 } | 223 } |
223 | 224 |
224 void SyncInternalsMessageHandler::HandleJsEvent( | 225 void SyncInternalsMessageHandler::HandleJsEvent( |
225 const std::string& name, | 226 const std::string& name, |
226 const JsEventDetails& details) { | 227 const JsEventDetails& details) { |
227 DVLOG(1) << "Handling event: " << name | 228 DVLOG(1) << "Handling event: " << name |
228 << " with details " << details.ToString(); | 229 << " with details " << details.ToString(); |
229 web_ui()->CallJavascriptFunction(sync_driver::sync_ui_util::kDispatchEvent, | 230 web_ui()->CallJavascriptFunction(sync_driver::sync_ui_util::kDispatchEvent, |
230 base::StringValue(name), details.Get()); | 231 base::StringValue(name), details.Get()); |
231 } | 232 } |
232 | 233 |
233 void SyncInternalsMessageHandler::SendAboutInfo() { | 234 void SyncInternalsMessageHandler::SendAboutInfo() { |
234 ProfileSyncService* sync_service = GetProfileSyncService(); | 235 ProfileSyncService* sync_service = GetProfileSyncService(); |
235 SigninManagerBase* signin = sync_service ? sync_service->signin() : nullptr; | 236 SigninManagerBase* signin = sync_service ? sync_service->signin() : nullptr; |
236 scoped_ptr<base::DictionaryValue> value = | 237 std::unique_ptr<base::DictionaryValue> value = |
237 about_sync_data_extractor_->ConstructAboutInformation(sync_service, | 238 about_sync_data_extractor_->ConstructAboutInformation(sync_service, |
238 signin); | 239 signin); |
239 web_ui()->CallJavascriptFunction( | 240 web_ui()->CallJavascriptFunction( |
240 sync_driver::sync_ui_util::kDispatchEvent, | 241 sync_driver::sync_ui_util::kDispatchEvent, |
241 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), | 242 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), |
242 *value); | 243 *value); |
243 } | 244 } |
244 | 245 |
245 // Gets the ProfileSyncService of the underlying original profile. | 246 // Gets the ProfileSyncService of the underlying original profile. |
246 // May return NULL (e.g., if sync is disabled on the command line). | 247 // May return NULL (e.g., if sync is disabled on the command line). |
247 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { | 248 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { |
248 Profile* profile = Profile::FromWebUI(web_ui()); | 249 Profile* profile = Profile::FromWebUI(web_ui()); |
249 return ProfileSyncServiceFactory::GetForProfile( | 250 return ProfileSyncServiceFactory::GetForProfile( |
250 profile->GetOriginalProfile()); | 251 profile->GetOriginalProfile()); |
251 } | 252 } |
OLD | NEW |