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" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 const base::ListValue* args) { | 137 const base::ListValue* args) { |
138 DCHECK(args->empty()); | 138 DCHECK(args->empty()); |
139 base::DictionaryValue event_details; | 139 base::DictionaryValue event_details; |
140 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); | 140 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); |
141 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | 141 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
142 for (ModelTypeSet::Iterator it = protocol_types.First(); | 142 for (ModelTypeSet::Iterator it = protocol_types.First(); |
143 it.Good(); it.Inc()) { | 143 it.Good(); it.Inc()) { |
144 type_list->AppendString(ModelTypeToString(it.Get())); | 144 type_list->AppendString(ModelTypeToString(it.Get())); |
145 } | 145 } |
146 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()); |
147 web_ui()->CallJavascriptFunction( | 147 web_ui()->CallJavascriptFunctionUnsafe( |
148 sync_driver::sync_ui_util::kDispatchEvent, | 148 sync_driver::sync_ui_util::kDispatchEvent, |
149 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), | 149 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), |
150 event_details); | 150 event_details); |
151 } | 151 } |
152 | 152 |
153 void SyncInternalsMessageHandler::HandleGetAllNodes( | 153 void SyncInternalsMessageHandler::HandleGetAllNodes( |
154 const base::ListValue* args) { | 154 const base::ListValue* args) { |
155 DCHECK_EQ(1U, args->GetSize()); | 155 DCHECK_EQ(1U, args->GetSize()); |
156 int request_id = 0; | 156 int request_id = 0; |
157 bool success = args->GetInteger(0, &request_id); | 157 bool success = args->GetInteger(0, &request_id); |
158 DCHECK(success); | 158 DCHECK(success); |
159 | 159 |
160 ProfileSyncService* service = GetProfileSyncService(); | 160 ProfileSyncService* service = GetProfileSyncService(); |
161 if (service) { | 161 if (service) { |
162 service->GetAllNodes( | 162 service->GetAllNodes( |
163 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, | 163 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, |
164 weak_ptr_factory_.GetWeakPtr(), request_id)); | 164 weak_ptr_factory_.GetWeakPtr(), request_id)); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 void SyncInternalsMessageHandler::OnReceivedAllNodes( | 168 void SyncInternalsMessageHandler::OnReceivedAllNodes( |
169 int request_id, | 169 int request_id, |
170 std::unique_ptr<base::ListValue> nodes) { | 170 std::unique_ptr<base::ListValue> nodes) { |
171 base::FundamentalValue id(request_id); | 171 base::FundamentalValue id(request_id); |
172 web_ui()->CallJavascriptFunction( | 172 web_ui()->CallJavascriptFunctionUnsafe( |
173 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); | 173 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); |
174 } | 174 } |
175 | 175 |
176 void SyncInternalsMessageHandler::OnStateChanged() { | 176 void SyncInternalsMessageHandler::OnStateChanged() { |
177 SendAboutInfo(); | 177 SendAboutInfo(); |
178 } | 178 } |
179 | 179 |
180 void SyncInternalsMessageHandler::OnProtocolEvent( | 180 void SyncInternalsMessageHandler::OnProtocolEvent( |
181 const syncer::ProtocolEvent& event) { | 181 const syncer::ProtocolEvent& event) { |
182 std::unique_ptr<base::DictionaryValue> value( | 182 std::unique_ptr<base::DictionaryValue> value( |
183 syncer::ProtocolEvent::ToValue(event)); | 183 syncer::ProtocolEvent::ToValue(event)); |
184 web_ui()->CallJavascriptFunction( | 184 web_ui()->CallJavascriptFunctionUnsafe( |
185 sync_driver::sync_ui_util::kDispatchEvent, | 185 sync_driver::sync_ui_util::kDispatchEvent, |
186 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); | 186 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); |
187 } | 187 } |
188 | 188 |
189 void SyncInternalsMessageHandler::OnCommitCountersUpdated( | 189 void SyncInternalsMessageHandler::OnCommitCountersUpdated( |
190 syncer::ModelType type, | 190 syncer::ModelType type, |
191 const syncer::CommitCounters& counters) { | 191 const syncer::CommitCounters& counters) { |
192 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, | 192 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, |
193 counters.ToValue()); | 193 counters.ToValue()); |
194 } | 194 } |
(...skipping 14 matching lines...) Expand all Loading... |
209 | 209 |
210 void SyncInternalsMessageHandler::EmitCounterUpdate( | 210 void SyncInternalsMessageHandler::EmitCounterUpdate( |
211 syncer::ModelType type, | 211 syncer::ModelType type, |
212 const std::string& counter_type, | 212 const std::string& counter_type, |
213 std::unique_ptr<base::DictionaryValue> value) { | 213 std::unique_ptr<base::DictionaryValue> value) { |
214 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 214 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
215 details->SetString(sync_driver::sync_ui_util::kModelType, | 215 details->SetString(sync_driver::sync_ui_util::kModelType, |
216 ModelTypeToString(type)); | 216 ModelTypeToString(type)); |
217 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); | 217 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); |
218 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); | 218 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); |
219 web_ui()->CallJavascriptFunction( | 219 web_ui()->CallJavascriptFunctionUnsafe( |
220 sync_driver::sync_ui_util::kDispatchEvent, | 220 sync_driver::sync_ui_util::kDispatchEvent, |
221 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), | 221 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), |
222 *details); | 222 *details); |
223 } | 223 } |
224 | 224 |
225 void SyncInternalsMessageHandler::HandleJsEvent( | 225 void SyncInternalsMessageHandler::HandleJsEvent( |
226 const std::string& name, | 226 const std::string& name, |
227 const JsEventDetails& details) { | 227 const JsEventDetails& details) { |
228 DVLOG(1) << "Handling event: " << name | 228 DVLOG(1) << "Handling event: " << name |
229 << " with details " << details.ToString(); | 229 << " with details " << details.ToString(); |
230 web_ui()->CallJavascriptFunction(sync_driver::sync_ui_util::kDispatchEvent, | 230 web_ui()->CallJavascriptFunctionUnsafe( |
231 base::StringValue(name), details.Get()); | 231 sync_driver::sync_ui_util::kDispatchEvent, base::StringValue(name), |
| 232 details.Get()); |
232 } | 233 } |
233 | 234 |
234 void SyncInternalsMessageHandler::SendAboutInfo() { | 235 void SyncInternalsMessageHandler::SendAboutInfo() { |
235 ProfileSyncService* sync_service = GetProfileSyncService(); | 236 ProfileSyncService* sync_service = GetProfileSyncService(); |
236 SigninManagerBase* signin = sync_service ? sync_service->signin() : nullptr; | 237 SigninManagerBase* signin = sync_service ? sync_service->signin() : nullptr; |
237 std::unique_ptr<base::DictionaryValue> value = | 238 std::unique_ptr<base::DictionaryValue> value = |
238 about_sync_data_extractor_->ConstructAboutInformation(sync_service, | 239 about_sync_data_extractor_->ConstructAboutInformation(sync_service, |
239 signin); | 240 signin); |
240 web_ui()->CallJavascriptFunction( | 241 web_ui()->CallJavascriptFunctionUnsafe( |
241 sync_driver::sync_ui_util::kDispatchEvent, | 242 sync_driver::sync_ui_util::kDispatchEvent, |
242 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), | 243 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), |
243 *value); | 244 *value); |
244 } | 245 } |
245 | 246 |
246 // Gets the ProfileSyncService of the underlying original profile. | 247 // Gets the ProfileSyncService of the underlying original profile. |
247 // May return NULL (e.g., if sync is disabled on the command line). | 248 // May return NULL (e.g., if sync is disabled on the command line). |
248 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { | 249 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { |
249 Profile* profile = Profile::FromWebUI(web_ui()); | 250 Profile* profile = Profile::FromWebUI(web_ui()); |
250 return ProfileSyncServiceFactory::GetForProfile( | 251 return ProfileSyncServiceFactory::GetForProfile( |
251 profile->GetOriginalProfile()); | 252 profile->GetOriginalProfile()); |
252 } | 253 } |
OLD | NEW |