| 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" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const gcm::GCMClient::GCMStatistics* stats) const { | 149 const gcm::GCMClient::GCMStatistics* stats) const { |
| 150 base::DictionaryValue results; | 150 base::DictionaryValue results; |
| 151 base::DictionaryValue* device_info = new base::DictionaryValue(); | 151 base::DictionaryValue* device_info = new base::DictionaryValue(); |
| 152 results.Set("deviceInfo", device_info); | 152 results.Set("deviceInfo", device_info); |
| 153 | 153 |
| 154 device_info->SetBoolean("profileServiceCreated", profile_service != NULL); | 154 device_info->SetBoolean("profileServiceCreated", profile_service != NULL); |
| 155 device_info->SetBoolean("gcmEnabled", | 155 device_info->SetBoolean("gcmEnabled", |
| 156 gcm::GCMProfileService::IsGCMEnabled(profile)); | 156 gcm::GCMProfileService::IsGCMEnabled(profile)); |
| 157 if (profile_service) { | 157 if (profile_service) { |
| 158 device_info->SetString("signedInUserName", | 158 device_info->SetString("signedInUserName", |
| 159 profile_service->driver()->SignedInUserName()); | 159 profile_service->SignedInUserName()); |
| 160 device_info->SetBoolean("gcmClientReady", | 160 device_info->SetBoolean("gcmClientReady", |
| 161 profile_service->driver()->IsGCMClientReady()); | 161 profile_service->driver()->IsGCMClientReady()); |
| 162 } | 162 } |
| 163 if (stats) { | 163 if (stats) { |
| 164 results.SetBoolean("isRecording", stats->is_recording); | 164 results.SetBoolean("isRecording", stats->is_recording); |
| 165 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); | 165 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); |
| 166 device_info->SetString("gcmClientState", stats->gcm_client_state); | 166 device_info->SetString("gcmClientState", stats->gcm_client_state); |
| 167 device_info->SetBoolean("connectionClientCreated", | 167 device_info->SetBoolean("connectionClientCreated", |
| 168 stats->connection_client_created); | 168 stats->connection_client_created); |
| 169 device_info->SetString("registeredAppIds", | 169 device_info->SetString("registeredAppIds", |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 NOTREACHED(); | 222 NOTREACHED(); |
| 223 return; | 223 return; |
| 224 } | 224 } |
| 225 | 225 |
| 226 Profile* profile = Profile::FromWebUI(web_ui()); | 226 Profile* profile = Profile::FromWebUI(web_ui()); |
| 227 gcm::GCMProfileService* profile_service = | 227 gcm::GCMProfileService* profile_service = |
| 228 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 228 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
| 229 | 229 |
| 230 if (!profile_service) { | 230 if (!profile_service) { |
| 231 ReturnResults(profile, NULL, NULL); | 231 ReturnResults(profile, NULL, NULL); |
| 232 } else if (profile_service->driver()->SignedInUserName().empty()) { | 232 } else if (profile_service->SignedInUserName().empty()) { |
| 233 ReturnResults(profile, profile_service, NULL); | 233 ReturnResults(profile, profile_service, NULL); |
| 234 } else { | 234 } else { |
| 235 profile_service->driver()->GetGCMStatistics( | 235 profile_service->driver()->GetGCMStatistics( |
| 236 base::Bind(&GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, | 236 base::Bind(&GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
| 237 weak_ptr_factory_.GetWeakPtr()), | 237 weak_ptr_factory_.GetWeakPtr()), |
| 238 clear_logs); | 238 clear_logs); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 void GcmInternalsUIMessageHandler::SetRecording(const base::ListValue* args) { | 242 void GcmInternalsUIMessageHandler::SetRecording(const base::ListValue* args) { |
| 243 if (args->GetSize() != 1) { | 243 if (args->GetSize() != 1) { |
| 244 NOTREACHED(); | 244 NOTREACHED(); |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 bool recording = false; | 247 bool recording = false; |
| 248 if (!args->GetBoolean(0, &recording)) { | 248 if (!args->GetBoolean(0, &recording)) { |
| 249 NOTREACHED(); | 249 NOTREACHED(); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 | 252 |
| 253 Profile* profile = Profile::FromWebUI(web_ui()); | 253 Profile* profile = Profile::FromWebUI(web_ui()); |
| 254 gcm::GCMProfileService* profile_service = | 254 gcm::GCMProfileService* profile_service = |
| 255 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 255 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
| 256 | 256 |
| 257 if (!profile_service) { | 257 if (!profile_service) { |
| 258 ReturnResults(profile, NULL, NULL); | 258 ReturnResults(profile, NULL, NULL); |
| 259 return; | 259 return; |
| 260 } | 260 } |
| 261 if (profile_service->driver()->SignedInUserName().empty()) { | 261 if (profile_service->SignedInUserName().empty()) { |
| 262 ReturnResults(profile, profile_service, NULL); | 262 ReturnResults(profile, profile_service, NULL); |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 // Get fresh stats after changing recording setting. | 265 // Get fresh stats after changing recording setting. |
| 266 profile_service->driver()->SetGCMRecording( | 266 profile_service->driver()->SetGCMRecording( |
| 267 base::Bind( | 267 base::Bind( |
| 268 &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, | 268 &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
| 269 weak_ptr_factory_.GetWeakPtr()), | 269 weak_ptr_factory_.GetWeakPtr()), |
| 270 recording); | 270 recording); |
| 271 } | 271 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); | 307 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); |
| 308 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); | 308 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); |
| 309 | 309 |
| 310 Profile* profile = Profile::FromWebUI(web_ui); | 310 Profile* profile = Profile::FromWebUI(web_ui); |
| 311 content::WebUIDataSource::Add(profile, html_source); | 311 content::WebUIDataSource::Add(profile, html_source); |
| 312 | 312 |
| 313 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); | 313 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); |
| 314 } | 314 } |
| 315 | 315 |
| 316 GCMInternalsUI::~GCMInternalsUI() {} | 316 GCMInternalsUI::~GCMInternalsUI() {} |
| OLD | NEW |