Chromium Code Reviews| Index: chrome/browser/ui/webui/gcm_internals_ui.cc |
| diff --git a/chrome/browser/ui/webui/gcm_internals_ui.cc b/chrome/browser/ui/webui/gcm_internals_ui.cc |
| index be9fe84efe1af28a6bd8e202681256ebf156d18c..c23c83829ce50153d44874ea7e27f69ccc5c2b38 100644 |
| --- a/chrome/browser/ui/webui/gcm_internals_ui.cc |
| +++ b/chrome/browser/ui/webui/gcm_internals_ui.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/ui/webui/gcm_internals_ui.h" |
| +#include <vector> |
| + |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/format_macros.h" |
| @@ -23,6 +25,24 @@ |
| namespace { |
| +void SetSendingInfo( |
| + const std::vector<gcm::GCMStatsRecorder::SendingActivity>& sends, |
| + base::ListValue* sendInfo) { |
|
jianli
2014/03/21 18:25:27
nit: send_info
juyik
2014/03/26 04:06:03
Done.
|
| + std::vector<gcm::GCMStatsRecorder::SendingActivity>::const_iterator it = |
| + sends.begin(); |
| + for (; it < sends.end(); ++it) { |
| + base::ListValue* row = new base::ListValue(); |
| + sendInfo->Append(row); |
| + |
| + row->AppendDouble(it->time.ToJsTime()); |
| + row->AppendString(it->app_id); |
| + row->AppendString(it->receiver_id); |
| + row->AppendString(it->message_id); |
| + row->AppendString(it->event); |
| + row->AppendString(it->details); |
| + } |
| +} |
| + |
| // Class acting as a controller of the chrome://gcm-internals WebUI. |
| class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler { |
| public: |
| @@ -42,6 +62,9 @@ class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler { |
| // Request all of the GCM related infos through gcm profile service. |
| void RequestAllInfo(const base::ListValue* args); |
| + // Enables/disables GCM activity recording through gcm profile service. |
| + void SetRecording(const base::ListValue* args); |
| + |
| // Callback function of the request for all gcm related infos. |
| void RequestGCMStatisticsFinished( |
| const gcm::GCMClient::GCMStatistics& args) const; |
| @@ -76,16 +99,28 @@ void GcmInternalsUIMessageHandler::ReturnResults( |
| profile_service->IsGCMClientReady()); |
| } |
| if (stats) { |
| + results.SetBoolean("isRecording", stats->is_recording); |
| device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); |
| device_info->SetString("gcmClientState", stats->gcm_client_state); |
| device_info->SetBoolean("connectionClientCreated", |
| stats->connection_client_created); |
| + device_info->SetString("appIdsCached", stats->app_ids_cached); |
| if (stats->connection_client_created) |
| device_info->SetString("connectionState", stats->connection_state); |
| if (stats->android_id > 0) { |
| device_info->SetString("androidId", |
| base::StringPrintf("0x%" PRIx64, stats->android_id)); |
| } |
| + if (stats->send_queue_size > 0) |
| + device_info->SetInteger("sendQueueSize", stats->send_queue_size); |
| + if (stats->unacked_queue_size > 0) |
| + device_info->SetInteger("unackedQueueSize", stats->unacked_queue_size); |
| + |
| + if (stats->sending.size() > 0) { |
| + base::ListValue* sendInfo = new base::ListValue(); |
|
jianli
2014/03/21 18:25:27
nit: send_info
juyik
2014/03/26 04:06:03
Done.
|
| + results.Set("sendInfo", sendInfo); |
| + SetSendingInfo(stats->sending, sendInfo); |
| + } |
| } |
| web_ui()->CallJavascriptFunction("gcmInternals.setGcmInternalsInfo", |
| results); |
| @@ -93,16 +128,58 @@ void GcmInternalsUIMessageHandler::ReturnResults( |
| void GcmInternalsUIMessageHandler::RequestAllInfo( |
| const base::ListValue* args) { |
| + if (args->GetSize() != 1) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + bool clear_logs = false; |
| + if (!args->GetBoolean(0, &clear_logs)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + gcm::GCMProfileService* profile_service = |
| + gcm::GCMProfileServiceFactory::GetForProfile(profile); |
| + |
| + if (!profile_service) { |
| + ReturnResults(profile, NULL, NULL); |
| + } else if (profile_service->SignedInUserName().empty()) { |
| + ReturnResults(profile, profile_service, NULL); |
| + } else { |
| + profile_service->RequestGCMStatistics( |
| + base::Bind(&GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + clear_logs); |
| + } |
| +} |
| + |
| +void GcmInternalsUIMessageHandler::SetRecording(const base::ListValue* args) { |
| + if (args->GetSize() != 1) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + bool recording = false; |
| + if (!args->GetBoolean(0, &recording)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| Profile* profile = Profile::FromWebUI(web_ui()); |
| gcm::GCMProfileService* profile_service = |
| gcm::GCMProfileServiceFactory::GetForProfile(profile); |
|
jianli
2014/03/21 18:25:27
nit: indentation
juyik
2014/03/26 04:06:03
Done.
|
| if (!profile_service) { |
| ReturnResults(profile, NULL, NULL); |
| + } else if (profile_service->SignedInUserName().empty()) { |
| + ReturnResults(profile, profile_service, NULL); |
| } else { |
| - profile_service->RequestGCMStatistics(base::Bind( |
| - &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
| - weak_ptr_factory_.GetWeakPtr())); |
| + // Get fresh stats after changing recording setting. |
| + profile_service->SetGCMRecording( |
| + base::Bind( |
| + &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + recording); |
| } |
| } |
| @@ -121,6 +198,10 @@ void GcmInternalsUIMessageHandler::RegisterMessages() { |
| "getGcmInternalsInfo", |
| base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo, |
| base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "setGcmInternalsRecording", |
| + base::Bind(&GcmInternalsUIMessageHandler::SetRecording, |
| + base::Unretained(this))); |
|
jianli
2014/03/21 18:25:27
Please use weak_ptr_factory_.
juyik
2014/03/26 04:06:03
Done.
|
| } |
| } // namespace |