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/gcm_internals_ui.h" | 5 #include "chrome/browser/ui/webui/gcm_internals_ui.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/services/gcm/gcm_driver.h" |
17 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 18 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
20 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
21 #include "content/public/browser/web_ui_controller.h" | 22 #include "content/public/browser/web_ui_controller.h" |
22 #include "content/public/browser/web_ui_data_source.h" | 23 #include "content/public/browser/web_ui_data_source.h" |
23 #include "content/public/browser/web_ui_message_handler.h" | 24 #include "content/public/browser/web_ui_message_handler.h" |
24 #include "google_apis/gcm/gcm_client.h" | 25 #include "google_apis/gcm/gcm_client.h" |
25 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
26 | 27 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 base::DictionaryValue results; | 155 base::DictionaryValue results; |
155 base::DictionaryValue* device_info = new base::DictionaryValue(); | 156 base::DictionaryValue* device_info = new base::DictionaryValue(); |
156 results.Set("deviceInfo", device_info); | 157 results.Set("deviceInfo", device_info); |
157 | 158 |
158 device_info->SetBoolean("profileServiceCreated", profile_service != NULL); | 159 device_info->SetBoolean("profileServiceCreated", profile_service != NULL); |
159 device_info->SetString("gcmEnabledState", | 160 device_info->SetString("gcmEnabledState", |
160 gcm::GCMProfileService::GetGCMEnabledStateString( | 161 gcm::GCMProfileService::GetGCMEnabledStateString( |
161 gcm::GCMProfileService::GetGCMEnabledState(profile))); | 162 gcm::GCMProfileService::GetGCMEnabledState(profile))); |
162 if (profile_service) { | 163 if (profile_service) { |
163 device_info->SetString("signedInUserName", | 164 device_info->SetString("signedInUserName", |
164 profile_service->SignedInUserName()); | 165 profile_service->driver()->SignedInUserName()); |
165 device_info->SetBoolean("gcmClientReady", | 166 device_info->SetBoolean("gcmClientReady", |
166 profile_service->IsGCMClientReady()); | 167 profile_service->driver()->IsGCMClientReady()); |
167 } | 168 } |
168 if (stats) { | 169 if (stats) { |
169 results.SetBoolean("isRecording", stats->is_recording); | 170 results.SetBoolean("isRecording", stats->is_recording); |
170 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); | 171 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); |
171 device_info->SetString("gcmClientState", stats->gcm_client_state); | 172 device_info->SetString("gcmClientState", stats->gcm_client_state); |
172 device_info->SetBoolean("connectionClientCreated", | 173 device_info->SetBoolean("connectionClientCreated", |
173 stats->connection_client_created); | 174 stats->connection_client_created); |
174 device_info->SetString("registeredAppIds", | 175 device_info->SetString("registeredAppIds", |
175 JoinString(stats->registered_app_ids, ",")); | 176 JoinString(stats->registered_app_ids, ",")); |
176 if (stats->connection_client_created) | 177 if (stats->connection_client_created) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 NOTREACHED(); | 228 NOTREACHED(); |
228 return; | 229 return; |
229 } | 230 } |
230 | 231 |
231 Profile* profile = Profile::FromWebUI(web_ui()); | 232 Profile* profile = Profile::FromWebUI(web_ui()); |
232 gcm::GCMProfileService* profile_service = | 233 gcm::GCMProfileService* profile_service = |
233 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 234 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
234 | 235 |
235 if (!profile_service) { | 236 if (!profile_service) { |
236 ReturnResults(profile, NULL, NULL); | 237 ReturnResults(profile, NULL, NULL); |
237 } else if (profile_service->SignedInUserName().empty()) { | 238 } else if (profile_service->driver()->SignedInUserName().empty()) { |
238 ReturnResults(profile, profile_service, NULL); | 239 ReturnResults(profile, profile_service, NULL); |
239 } else { | 240 } else { |
240 profile_service->GetGCMStatistics( | 241 profile_service->driver()->GetGCMStatistics( |
241 base::Bind(&GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, | 242 base::Bind(&GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
242 weak_ptr_factory_.GetWeakPtr()), | 243 weak_ptr_factory_.GetWeakPtr()), |
243 clear_logs); | 244 clear_logs); |
244 } | 245 } |
245 } | 246 } |
246 | 247 |
247 void GcmInternalsUIMessageHandler::SetRecording(const base::ListValue* args) { | 248 void GcmInternalsUIMessageHandler::SetRecording(const base::ListValue* args) { |
248 if (args->GetSize() != 1) { | 249 if (args->GetSize() != 1) { |
249 NOTREACHED(); | 250 NOTREACHED(); |
250 return; | 251 return; |
251 } | 252 } |
252 bool recording = false; | 253 bool recording = false; |
253 if (!args->GetBoolean(0, &recording)) { | 254 if (!args->GetBoolean(0, &recording)) { |
254 NOTREACHED(); | 255 NOTREACHED(); |
255 return; | 256 return; |
256 } | 257 } |
257 | 258 |
258 Profile* profile = Profile::FromWebUI(web_ui()); | 259 Profile* profile = Profile::FromWebUI(web_ui()); |
259 gcm::GCMProfileService* profile_service = | 260 gcm::GCMProfileService* profile_service = |
260 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 261 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
261 | 262 |
262 if (!profile_service) { | 263 if (!profile_service) { |
263 ReturnResults(profile, NULL, NULL); | 264 ReturnResults(profile, NULL, NULL); |
264 return; | 265 return; |
265 } | 266 } |
266 if (profile_service->SignedInUserName().empty()) { | 267 if (profile_service->driver()->SignedInUserName().empty()) { |
267 ReturnResults(profile, profile_service, NULL); | 268 ReturnResults(profile, profile_service, NULL); |
268 return; | 269 return; |
269 } | 270 } |
270 // Get fresh stats after changing recording setting. | 271 // Get fresh stats after changing recording setting. |
271 profile_service->SetGCMRecording( | 272 profile_service->driver()->SetGCMRecording( |
272 base::Bind( | 273 base::Bind( |
273 &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, | 274 &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
274 weak_ptr_factory_.GetWeakPtr()), | 275 weak_ptr_factory_.GetWeakPtr()), |
275 recording); | 276 recording); |
276 } | 277 } |
277 | 278 |
278 void GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished( | 279 void GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished( |
279 const gcm::GCMClient::GCMStatistics& stats) const { | 280 const gcm::GCMClient::GCMStatistics& stats) const { |
280 Profile* profile = Profile::FromWebUI(web_ui()); | 281 Profile* profile = Profile::FromWebUI(web_ui()); |
281 DCHECK(profile); | 282 DCHECK(profile); |
(...skipping 30 matching lines...) Expand all Loading... |
312 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); | 313 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); |
313 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); | 314 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); |
314 | 315 |
315 Profile* profile = Profile::FromWebUI(web_ui); | 316 Profile* profile = Profile::FromWebUI(web_ui); |
316 content::WebUIDataSource::Add(profile, html_source); | 317 content::WebUIDataSource::Add(profile, html_source); |
317 | 318 |
318 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); | 319 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); |
319 } | 320 } |
320 | 321 |
321 GCMInternalsUI::~GCMInternalsUI() {} | 322 GCMInternalsUI::~GCMInternalsUI() {} |
OLD | NEW |