Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Unified Diff: chrome/browser/ui/webui/gcm_internals_ui.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f70263f1da540e5728fd7f7fb74e4dd42a9a7e61 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,77 @@
namespace {
+void SetCheckinInfos(
+ const std::vector<gcm::GCMStatsRecorder::CheckinActivity>& checkins,
+ base::ListValue* checkinInfo) {
+ for (std::vector<gcm::GCMStatsRecorder::CheckinActivity>::const_iterator it =
+ checkins.begin();
+ it < checkins.end();
jianli 2014/03/18 23:53:23 nit: !=
juyik 2014/03/20 01:09:53 Done.
+ ++it) {
+ base::ListValue* row = new base::ListValue();
+ checkinInfo->Append(row);
+
+ row->AppendDouble(it->time.ToJsTime());
+ row->AppendString(it->GetTypeString());
+ row->AppendString(base::StringPrintf("%" PRId64, it->android_id));
+ row->AppendString(it->details);
+ }
+}
+
+void SetRegisterInfo(
+ const std::vector<gcm::GCMStatsRecorder::RegisterActivity>& registers,
+ base::ListValue* registerInfo) {
+ for (std::vector<gcm::GCMStatsRecorder::RegisterActivity>::const_iterator it =
+ registers.begin();
+ it < registers.end();
+ ++it) {
+ base::ListValue* row = new base::ListValue();
+ registerInfo->Append(row);
+
+ row->AppendDouble(it->time.ToJsTime());
+ row->AppendString(it->GetTypeString());
+ row->AppendString(it->app_id);
+ row->AppendString(it->sender_id);
+ row->AppendString(it->details);
+ }
+}
+
+void SetSendInfo(
+ const std::vector<gcm::GCMStatsRecorder::SendMessageActivity>& sends,
+ base::ListValue* sendInfo) {
+ std::vector<gcm::GCMStatsRecorder::SendMessageActivity>::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->GetTypeString());
+ row->AppendString(it->app_id);
+ row->AppendString(it->receiver_id);
+ row->AppendString(it->message_id);
+ row->AppendString(it->details);
+ }
+}
+
+void SetReceiveInfo(
+ const std::vector<gcm::GCMStatsRecorder::ReceiveMessageActivity>& receives,
+ base::ListValue* sendInfo) {
+ std::vector<gcm::GCMStatsRecorder::ReceiveMessageActivity>::const_iterator
+ it = receives.begin();
+ for (; it < receives.end(); ++it) {
+ base::ListValue* row = new base::ListValue();
+ sendInfo->Append(row);
+
+ row->AppendDouble(it->time.ToJsTime());
+ row->AppendString(it->GetTypeString());
+ row->AppendString(it->sender_id);
+ row->AppendString(it->app_id);
+ row->AppendInteger(it->message_size);
+ row->AppendString(it->details);
+ }
+}
+
// Class acting as a controller of the chrome://gcm-internals WebUI.
class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler {
public:
@@ -42,6 +115,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;
@@ -62,6 +138,7 @@ void GcmInternalsUIMessageHandler::ReturnResults(
gcm::GCMProfileService* profile_service,
const gcm::GCMClient::GCMStatistics* stats) const {
base::DictionaryValue results;
+ results.SetBoolean("isRecording", stats->is_recording);
base::DictionaryValue* device_info = new base::DictionaryValue();
results.Set("deviceInfo", device_info);
@@ -80,12 +157,38 @@ void GcmInternalsUIMessageHandler::ReturnResults(
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->checkins.size() > 0) {
+ base::ListValue* checkinInfo = new base::ListValue();
+ results.Set("checkinInfo", checkinInfo);
+ SetCheckinInfos(stats->checkins, checkinInfo);
+ }
+ if (stats->registers.size() > 0) {
+ base::ListValue* registerInfo = new base::ListValue();
+ results.Set("registerInfo", registerInfo);
+ SetRegisterInfo(stats->registers, registerInfo);
+ }
+ if (stats->sent_messages.size() > 0) {
+ base::ListValue* sendInfo = new base::ListValue();
+ results.Set("sendInfo", sendInfo);
+ SetSendInfo(stats->sent_messages, sendInfo);
+ }
+ if (stats->received_messages.size() > 0) {
+ base::ListValue* receiveInfo = new base::ListValue();
+ results.Set("receiveInfo", receiveInfo);
+ SetReceiveInfo(stats->received_messages, receiveInfo);
+ }
}
web_ui()->CallJavascriptFunction("gcmInternals.setGcmInternalsInfo",
results);
@@ -93,6 +196,41 @@ 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) {
fgorski 2014/03/18 21:28:37 this is the place we identified as a problem.
juyik 2014/03/20 01:09:53 I looked into it deeper and now it doesn't seemed
+ ReturnResults(profile, NULL, 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);
@@ -100,9 +238,12 @@ void GcmInternalsUIMessageHandler::RequestAllInfo(
if (!profile_service) {
ReturnResults(profile, NULL, 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 +262,10 @@ void GcmInternalsUIMessageHandler::RegisterMessages() {
"getGcmInternalsInfo",
base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "setGcmInternalsRecording",
+ base::Bind(&GcmInternalsUIMessageHandler::SetRecording,
+ base::Unretained(this)));
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698