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 "base/values.h" | 10 #include "base/values.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 void SyncInternalsMessageHandler::HandleRequestListOfTypes( | 120 void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
121 const base::ListValue* args) { | 121 const base::ListValue* args) { |
122 DCHECK(args->empty()); | 122 DCHECK(args->empty()); |
123 base::DictionaryValue event_details; | 123 base::DictionaryValue event_details; |
124 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); | 124 std::unique_ptr<base::ListValue> type_list(new base::ListValue()); |
125 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | 125 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
126 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); | 126 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); |
127 it.Inc()) { | 127 it.Inc()) { |
128 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); | 128 type_list->Append(new base::Value(ModelTypeToString(it.Get()))); |
129 } | 129 } |
130 event_details.Set(syncer::sync_ui_util::kTypes, type_list.release()); | 130 event_details.Set(syncer::sync_ui_util::kTypes, type_list.release()); |
131 web_ui()->CallJavascriptFunction( | 131 web_ui()->CallJavascriptFunction( |
132 syncer::sync_ui_util::kDispatchEvent, | 132 syncer::sync_ui_util::kDispatchEvent, |
133 base::StringValue(syncer::sync_ui_util::kOnReceivedListOfTypes), | 133 base::Value(syncer::sync_ui_util::kOnReceivedListOfTypes), event_details); |
134 event_details); | |
135 } | 134 } |
136 | 135 |
137 void SyncInternalsMessageHandler::HandleGetAllNodes( | 136 void SyncInternalsMessageHandler::HandleGetAllNodes( |
138 const base::ListValue* args) { | 137 const base::ListValue* args) { |
139 DCHECK_EQ(1U, args->GetSize()); | 138 DCHECK_EQ(1U, args->GetSize()); |
140 int request_id = 0; | 139 int request_id = 0; |
141 bool success = ExtractIntegerValue(args, &request_id); | 140 bool success = ExtractIntegerValue(args, &request_id); |
142 DCHECK(success); | 141 DCHECK(success); |
143 | 142 |
144 syncer::SyncService* service = GetSyncService(); | 143 syncer::SyncService* service = GetSyncService(); |
(...skipping 15 matching lines...) Expand all Loading... |
160 void SyncInternalsMessageHandler::OnStateChanged(syncer::SyncService* sync) { | 159 void SyncInternalsMessageHandler::OnStateChanged(syncer::SyncService* sync) { |
161 SendAboutInfo(); | 160 SendAboutInfo(); |
162 } | 161 } |
163 | 162 |
164 void SyncInternalsMessageHandler::OnProtocolEvent( | 163 void SyncInternalsMessageHandler::OnProtocolEvent( |
165 const syncer::ProtocolEvent& event) { | 164 const syncer::ProtocolEvent& event) { |
166 std::unique_ptr<base::DictionaryValue> value( | 165 std::unique_ptr<base::DictionaryValue> value( |
167 syncer::ProtocolEvent::ToValue(event)); | 166 syncer::ProtocolEvent::ToValue(event)); |
168 web_ui()->CallJavascriptFunction( | 167 web_ui()->CallJavascriptFunction( |
169 syncer::sync_ui_util::kDispatchEvent, | 168 syncer::sync_ui_util::kDispatchEvent, |
170 base::StringValue(syncer::sync_ui_util::kOnProtocolEvent), *value); | 169 base::Value(syncer::sync_ui_util::kOnProtocolEvent), *value); |
171 } | 170 } |
172 | 171 |
173 void SyncInternalsMessageHandler::OnCommitCountersUpdated( | 172 void SyncInternalsMessageHandler::OnCommitCountersUpdated( |
174 syncer::ModelType type, | 173 syncer::ModelType type, |
175 const syncer::CommitCounters& counters) { | 174 const syncer::CommitCounters& counters) { |
176 EmitCounterUpdate(type, syncer::sync_ui_util::kCommit, counters.ToValue()); | 175 EmitCounterUpdate(type, syncer::sync_ui_util::kCommit, counters.ToValue()); |
177 } | 176 } |
178 | 177 |
179 void SyncInternalsMessageHandler::OnUpdateCountersUpdated( | 178 void SyncInternalsMessageHandler::OnUpdateCountersUpdated( |
180 syncer::ModelType type, | 179 syncer::ModelType type, |
(...skipping 10 matching lines...) Expand all Loading... |
191 void SyncInternalsMessageHandler::EmitCounterUpdate( | 190 void SyncInternalsMessageHandler::EmitCounterUpdate( |
192 syncer::ModelType type, | 191 syncer::ModelType type, |
193 const std::string& counter_type, | 192 const std::string& counter_type, |
194 std::unique_ptr<base::DictionaryValue> value) { | 193 std::unique_ptr<base::DictionaryValue> value) { |
195 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 194 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
196 details->SetString(syncer::sync_ui_util::kModelType, ModelTypeToString(type)); | 195 details->SetString(syncer::sync_ui_util::kModelType, ModelTypeToString(type)); |
197 details->SetString(syncer::sync_ui_util::kCounterType, counter_type); | 196 details->SetString(syncer::sync_ui_util::kCounterType, counter_type); |
198 details->Set(syncer::sync_ui_util::kCounters, value.release()); | 197 details->Set(syncer::sync_ui_util::kCounters, value.release()); |
199 web_ui()->CallJavascriptFunction( | 198 web_ui()->CallJavascriptFunction( |
200 syncer::sync_ui_util::kDispatchEvent, | 199 syncer::sync_ui_util::kDispatchEvent, |
201 base::StringValue(syncer::sync_ui_util::kOnCountersUpdated), *details); | 200 base::Value(syncer::sync_ui_util::kOnCountersUpdated), *details); |
202 } | 201 } |
203 | 202 |
204 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, | 203 void SyncInternalsMessageHandler::HandleJsEvent(const std::string& name, |
205 const JsEventDetails& details) { | 204 const JsEventDetails& details) { |
206 DVLOG(1) << "Handling event: " << name << " with details " | 205 DVLOG(1) << "Handling event: " << name << " with details " |
207 << details.ToString(); | 206 << details.ToString(); |
208 web_ui()->CallJavascriptFunction(syncer::sync_ui_util::kDispatchEvent, | 207 web_ui()->CallJavascriptFunction(syncer::sync_ui_util::kDispatchEvent, |
209 base::StringValue(name), details.Get()); | 208 base::Value(name), details.Get()); |
210 } | 209 } |
211 | 210 |
212 void SyncInternalsMessageHandler::SendAboutInfo() { | 211 void SyncInternalsMessageHandler::SendAboutInfo() { |
213 ios::ChromeBrowserState* browser_state = | 212 ios::ChromeBrowserState* browser_state = |
214 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | 213 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); |
215 SigninManager* signin_manager = | 214 SigninManager* signin_manager = |
216 ios::SigninManagerFactory::GetForBrowserState(browser_state); | 215 ios::SigninManagerFactory::GetForBrowserState(browser_state); |
217 syncer::SyncService* sync_service = GetSyncService(); | 216 syncer::SyncService* sync_service = GetSyncService(); |
218 std::unique_ptr<base::DictionaryValue> value = | 217 std::unique_ptr<base::DictionaryValue> value = |
219 syncer::sync_ui_util::ConstructAboutInformation( | 218 syncer::sync_ui_util::ConstructAboutInformation( |
220 sync_service, signin_manager, GetChannel()); | 219 sync_service, signin_manager, GetChannel()); |
221 web_ui()->CallJavascriptFunction( | 220 web_ui()->CallJavascriptFunction( |
222 syncer::sync_ui_util::kDispatchEvent, | 221 syncer::sync_ui_util::kDispatchEvent, |
223 base::StringValue(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); | 222 base::Value(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); |
224 } | 223 } |
225 | 224 |
226 // Gets the SyncService of the underlying original profile. May return null. | 225 // Gets the SyncService of the underlying original profile. May return null. |
227 syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() { | 226 syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() { |
228 ios::ChromeBrowserState* browser_state = | 227 ios::ChromeBrowserState* browser_state = |
229 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | 228 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); |
230 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( | 229 return IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
231 browser_state->GetOriginalChromeBrowserState()); | 230 browser_state->GetOriginalChromeBrowserState()); |
232 } | 231 } |
OLD | NEW |