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