| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ui/webui/sync_internals/sync_internals_message_hand
ler.h" | 5 #include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_message_hand
ler.h" |
| 6 | 6 |
| 7 #include <utility> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "components/browser_sync/profile_sync_service.h" | 12 #include "components/browser_sync/profile_sync_service.h" |
| 12 #include "components/sync/base/weak_handle.h" | 13 #include "components/sync/base/weak_handle.h" |
| 13 #include "components/sync/driver/about_sync_util.h" | 14 #include "components/sync/driver/about_sync_util.h" |
| 14 #include "components/sync/driver/sync_service.h" | 15 #include "components/sync/driver/sync_service.h" |
| 15 #include "components/sync/engine/cycle/commit_counters.h" | 16 #include "components/sync/engine/cycle/commit_counters.h" |
| 16 #include "components/sync/engine/cycle/status_counters.h" | 17 #include "components/sync/engine/cycle/status_counters.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 void SyncInternalsMessageHandler::HandleRequestListOfTypes( | 119 void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
| 119 const base::ListValue* args) { | 120 const base::ListValue* args) { |
| 120 DCHECK(args->empty()); | 121 DCHECK(args->empty()); |
| 121 base::DictionaryValue event_details; | 122 base::DictionaryValue event_details; |
| 122 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); | 123 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); |
| 123 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | 124 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
| 124 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); | 125 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); |
| 125 it.Inc()) { | 126 it.Inc()) { |
| 126 type_list->AppendString(ModelTypeToString(it.Get())); | 127 type_list->AppendString(ModelTypeToString(it.Get())); |
| 127 } | 128 } |
| 128 event_details.Set(syncer::sync_ui_util::kTypes, type_list.release()); | 129 event_details.Set(syncer::sync_ui_util::kTypes, std::move(type_list)); |
| 129 web_ui()->CallJavascriptFunction( | 130 web_ui()->CallJavascriptFunction( |
| 130 syncer::sync_ui_util::kDispatchEvent, | 131 syncer::sync_ui_util::kDispatchEvent, |
| 131 base::Value(syncer::sync_ui_util::kOnReceivedListOfTypes), event_details); | 132 base::Value(syncer::sync_ui_util::kOnReceivedListOfTypes), event_details); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void SyncInternalsMessageHandler::HandleGetAllNodes( | 135 void SyncInternalsMessageHandler::HandleGetAllNodes( |
| 135 const base::ListValue* args) { | 136 const base::ListValue* args) { |
| 136 DCHECK_EQ(1U, args->GetSize()); | 137 DCHECK_EQ(1U, args->GetSize()); |
| 137 int request_id = 0; | 138 int request_id = 0; |
| 138 bool success = ExtractIntegerValue(args, &request_id); | 139 bool success = ExtractIntegerValue(args, &request_id); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 EmitCounterUpdate(type, syncer::sync_ui_util::kStatus, counters.ToValue()); | 186 EmitCounterUpdate(type, syncer::sync_ui_util::kStatus, counters.ToValue()); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void SyncInternalsMessageHandler::EmitCounterUpdate( | 189 void SyncInternalsMessageHandler::EmitCounterUpdate( |
| 189 syncer::ModelType type, | 190 syncer::ModelType type, |
| 190 const std::string& counter_type, | 191 const std::string& counter_type, |
| 191 std::unique_ptr<base::DictionaryValue> value) { | 192 std::unique_ptr<base::DictionaryValue> value) { |
| 192 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 193 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
| 193 details->SetString(syncer::sync_ui_util::kModelType, ModelTypeToString(type)); | 194 details->SetString(syncer::sync_ui_util::kModelType, ModelTypeToString(type)); |
| 194 details->SetString(syncer::sync_ui_util::kCounterType, counter_type); | 195 details->SetString(syncer::sync_ui_util::kCounterType, counter_type); |
| 195 details->Set(syncer::sync_ui_util::kCounters, value.release()); | 196 details->Set(syncer::sync_ui_util::kCounters, std::move(value)); |
| 196 web_ui()->CallJavascriptFunction( | 197 web_ui()->CallJavascriptFunction( |
| 197 syncer::sync_ui_util::kDispatchEvent, | 198 syncer::sync_ui_util::kDispatchEvent, |
| 198 base::Value(syncer::sync_ui_util::kOnCountersUpdated), *details); | 199 base::Value(syncer::sync_ui_util::kOnCountersUpdated), *details); |
| 199 } | 200 } |
| 200 | 201 |
| 201 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, | 202 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, |
| 202 const JsEventDetails& details) { | 203 const JsEventDetails& details) { |
| 203 DVLOG(1) << "Handling event: " << name << " with details " | 204 DVLOG(1) << "Handling event: " << name << " with details " |
| 204 << details.ToString(); | 205 << details.ToString(); |
| 205 web_ui()->CallJavascriptFunction(syncer::sync_ui_util::kDispatchEvent, | 206 web_ui()->CallJavascriptFunction(syncer::sync_ui_util::kDispatchEvent, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 216 base::Value(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); | 217 base::Value(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); |
| 217 } | 218 } |
| 218 | 219 |
| 219 // Gets the SyncService of the underlying original profile. May return null. | 220 // Gets the SyncService of the underlying original profile. May return null. |
| 220 syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() { | 221 syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() { |
| 221 ios::ChromeBrowserState* browser_state = | 222 ios::ChromeBrowserState* browser_state = |
| 222 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | 223 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); |
| 223 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( | 224 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
| 224 browser_state->GetOriginalChromeBrowserState()); | 225 browser_state->GetOriginalChromeBrowserState()); |
| 225 } | 226 } |
| OLD | NEW |