| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/browser_sync/browser/profile_sync_service.h" | 10 #include "components/browser_sync/browser/profile_sync_service.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( | 113 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( |
| 114 const base::ListValue* args) { | 114 const base::ListValue* args) { |
| 115 DCHECK(args->empty()); | 115 DCHECK(args->empty()); |
| 116 SendAboutInfo(); | 116 SendAboutInfo(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void SyncInternalsMessageHandler::HandleRequestListOfTypes( | 119 void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
| 120 const base::ListValue* args) { | 120 const base::ListValue* args) { |
| 121 DCHECK(args->empty()); | 121 DCHECK(args->empty()); |
| 122 base::DictionaryValue event_details; | 122 base::DictionaryValue event_details; |
| 123 scoped_ptr<base::ListValue> type_list(new base::ListValue()); | 123 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); |
| 124 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | 124 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
| 125 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); | 125 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); |
| 126 it.Inc()) { | 126 it.Inc()) { |
| 127 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); | 127 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); |
| 128 } | 128 } |
| 129 event_details.Set(sync_driver::sync_ui_util::kTypes, type_list.release()); | 129 event_details.Set(sync_driver::sync_ui_util::kTypes, type_list.release()); |
| 130 web_ui()->CallJavascriptFunction( | 130 web_ui()->CallJavascriptFunction( |
| 131 sync_driver::sync_ui_util::kDispatchEvent, | 131 sync_driver::sync_ui_util::kDispatchEvent, |
| 132 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), | 132 base::StringValue(sync_driver::sync_ui_util::kOnReceivedListOfTypes), |
| 133 event_details); | 133 event_details); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void SyncInternalsMessageHandler::HandleGetAllNodes( | 136 void SyncInternalsMessageHandler::HandleGetAllNodes( |
| 137 const base::ListValue* args) { | 137 const base::ListValue* args) { |
| 138 DCHECK_EQ(1U, args->GetSize()); | 138 DCHECK_EQ(1U, args->GetSize()); |
| 139 int request_id = 0; | 139 int request_id = 0; |
| 140 bool success = args->GetInteger(0, &request_id); | 140 bool success = args->GetInteger(0, &request_id); |
| 141 DCHECK(success); | 141 DCHECK(success); |
| 142 | 142 |
| 143 sync_driver::SyncService* service = GetSyncService(); | 143 sync_driver::SyncService* service = GetSyncService(); |
| 144 if (service) { | 144 if (service) { |
| 145 service->GetAllNodes( | 145 service->GetAllNodes( |
| 146 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, | 146 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, |
| 147 weak_ptr_factory_.GetWeakPtr(), request_id)); | 147 weak_ptr_factory_.GetWeakPtr(), request_id)); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void SyncInternalsMessageHandler::OnReceivedAllNodes( | 151 void SyncInternalsMessageHandler::OnReceivedAllNodes( |
| 152 int request_id, | 152 int request_id, |
| 153 scoped_ptr<base::ListValue> nodes) { | 153 std::unique_ptr<base::ListValue> nodes) { |
| 154 base::FundamentalValue id(request_id); | 154 base::FundamentalValue id(request_id); |
| 155 web_ui()->CallJavascriptFunction( | 155 web_ui()->CallJavascriptFunction( |
| 156 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); | 156 sync_driver::sync_ui_util::kGetAllNodesCallback, id, *nodes); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void SyncInternalsMessageHandler::OnStateChanged() { | 159 void SyncInternalsMessageHandler::OnStateChanged() { |
| 160 SendAboutInfo(); | 160 SendAboutInfo(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void SyncInternalsMessageHandler::OnProtocolEvent( | 163 void SyncInternalsMessageHandler::OnProtocolEvent( |
| 164 const syncer::ProtocolEvent& event) { | 164 const syncer::ProtocolEvent& event) { |
| 165 scoped_ptr<base::DictionaryValue> value( | 165 std::unique_ptr<base::DictionaryValue> value( |
| 166 syncer::ProtocolEvent::ToValue(event)); | 166 syncer::ProtocolEvent::ToValue(event)); |
| 167 web_ui()->CallJavascriptFunction( | 167 web_ui()->CallJavascriptFunction( |
| 168 sync_driver::sync_ui_util::kDispatchEvent, | 168 sync_driver::sync_ui_util::kDispatchEvent, |
| 169 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); | 169 base::StringValue(sync_driver::sync_ui_util::kOnProtocolEvent), *value); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void SyncInternalsMessageHandler::OnCommitCountersUpdated( | 172 void SyncInternalsMessageHandler::OnCommitCountersUpdated( |
| 173 syncer::ModelType type, | 173 syncer::ModelType type, |
| 174 const syncer::CommitCounters& counters) { | 174 const syncer::CommitCounters& counters) { |
| 175 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, | 175 EmitCounterUpdate(type, sync_driver::sync_ui_util::kCommit, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 void SyncInternalsMessageHandler::OnStatusCountersUpdated( | 186 void SyncInternalsMessageHandler::OnStatusCountersUpdated( |
| 187 syncer::ModelType type, | 187 syncer::ModelType type, |
| 188 const syncer::StatusCounters& counters) { | 188 const syncer::StatusCounters& counters) { |
| 189 EmitCounterUpdate(type, sync_driver::sync_ui_util::kStatus, | 189 EmitCounterUpdate(type, sync_driver::sync_ui_util::kStatus, |
| 190 counters.ToValue()); | 190 counters.ToValue()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void SyncInternalsMessageHandler::EmitCounterUpdate( | 193 void SyncInternalsMessageHandler::EmitCounterUpdate( |
| 194 syncer::ModelType type, | 194 syncer::ModelType type, |
| 195 const std::string& counter_type, | 195 const std::string& counter_type, |
| 196 scoped_ptr<base::DictionaryValue> value) { | 196 std::unique_ptr<base::DictionaryValue> value) { |
| 197 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 197 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
| 198 details->SetString(sync_driver::sync_ui_util::kModelType, | 198 details->SetString(sync_driver::sync_ui_util::kModelType, |
| 199 ModelTypeToString(type)); | 199 ModelTypeToString(type)); |
| 200 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); | 200 details->SetString(sync_driver::sync_ui_util::kCounterType, counter_type); |
| 201 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); | 201 details->Set(sync_driver::sync_ui_util::kCounters, value.release()); |
| 202 web_ui()->CallJavascriptFunction( | 202 web_ui()->CallJavascriptFunction( |
| 203 sync_driver::sync_ui_util::kDispatchEvent, | 203 sync_driver::sync_ui_util::kDispatchEvent, |
| 204 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), | 204 base::StringValue(sync_driver::sync_ui_util::kOnCountersUpdated), |
| 205 *details); | 205 *details); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, | 208 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, |
| 209 const JsEventDetails& details) { | 209 const JsEventDetails& details) { |
| 210 DVLOG(1) << "Handling event: " << name << " with details " | 210 DVLOG(1) << "Handling event: " << name << " with details " |
| 211 << details.ToString(); | 211 << details.ToString(); |
| 212 web_ui()->CallJavascriptFunction(sync_driver::sync_ui_util::kDispatchEvent, | 212 web_ui()->CallJavascriptFunction(sync_driver::sync_ui_util::kDispatchEvent, |
| 213 base::StringValue(name), details.Get()); | 213 base::StringValue(name), details.Get()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void SyncInternalsMessageHandler::SendAboutInfo() { | 216 void SyncInternalsMessageHandler::SendAboutInfo() { |
| 217 ios::ChromeBrowserState* browser_state = | 217 ios::ChromeBrowserState* browser_state = |
| 218 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | 218 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); |
| 219 SigninManager* signin_manager = | 219 SigninManager* signin_manager = |
| 220 ios::SigninManagerFactory::GetForBrowserState(browser_state); | 220 ios::SigninManagerFactory::GetForBrowserState(browser_state); |
| 221 sync_driver::SyncService* sync_service = GetSyncService(); | 221 sync_driver::SyncService* sync_service = GetSyncService(); |
| 222 scoped_ptr<base::DictionaryValue> value = | 222 std::unique_ptr<base::DictionaryValue> value = |
| 223 sync_driver::sync_ui_util::ConstructAboutInformation( | 223 sync_driver::sync_ui_util::ConstructAboutInformation( |
| 224 sync_service, signin_manager, GetChannel()); | 224 sync_service, signin_manager, GetChannel()); |
| 225 web_ui()->CallJavascriptFunction( | 225 web_ui()->CallJavascriptFunction( |
| 226 sync_driver::sync_ui_util::kDispatchEvent, | 226 sync_driver::sync_ui_util::kDispatchEvent, |
| 227 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), | 227 base::StringValue(sync_driver::sync_ui_util::kOnAboutInfoUpdated), |
| 228 *value); | 228 *value); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Gets the SyncService of the underlying original profile. May return null. | 231 // Gets the SyncService of the underlying original profile. May return null. |
| 232 sync_driver::SyncService* SyncInternalsMessageHandler::GetSyncService() { | 232 sync_driver::SyncService* SyncInternalsMessageHandler::GetSyncService() { |
| 233 ios::ChromeBrowserState* browser_state = | 233 ios::ChromeBrowserState* browser_state = |
| 234 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | 234 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); |
| 235 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( | 235 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
| 236 browser_state->GetOriginalChromeBrowserState()); | 236 browser_state->GetOriginalChromeBrowserState()); |
| 237 } | 237 } |
| OLD | NEW |