summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui
diff options
context:
space:
mode:
authorjuyik@chromium.org <juyik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-16 21:41:44 +0000
committerjuyik@chromium.org <juyik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-16 21:41:44 +0000
commit268d23f13de7d41e2dc42b90205fbd86a66676a0 (patch)
tree445afa9ef278cd1462bdab4eb13dd12c555dbe09 /chrome/browser/ui/webui
parente888193914dc13c6961a64c810852fd0d6268afb (diff)
downloadchromium_src-268d23f13de7d41e2dc42b90205fbd86a66676a0.zip
chromium_src-268d23f13de7d41e2dc42b90205fbd86a66676a0.tar.gz
chromium_src-268d23f13de7d41e2dc42b90205fbd86a66676a0.tar.bz2
Add activity recording capability to gcm internals page. User can refresh, start/stop recording, and clear recording logs.
Also added more information to the device info section and fixed a bug there. arv: owner review of chrome/browser/resources/*. jianli & fgorski please review the rest of the code, and zea for owner review of these code. BUG=341256 Review URL: https://codereview.chromium.org/202083005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r--chrome/browser/ui/webui/gcm_internals_ui.cc91
1 files changed, 87 insertions, 4 deletions
diff --git a/chrome/browser/ui/webui/gcm_internals_ui.cc b/chrome/browser/ui/webui/gcm_internals_ui.cc
index be9fe84..2130cd8 100644
--- a/chrome/browser/ui/webui/gcm_internals_ui.cc
+++ b/chrome/browser/ui/webui/gcm_internals_ui.cc
@@ -4,10 +4,13 @@
#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"
#include "base/memory/weak_ptr.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
@@ -23,6 +26,24 @@
namespace {
+void SetSendingInfo(
+ const std::vector<gcm::GCMStatsRecorder::SendingActivity>& sends,
+ base::ListValue* send_info) {
+ std::vector<gcm::GCMStatsRecorder::SendingActivity>::const_iterator it =
+ sends.begin();
+ for (; it < sends.end(); ++it) {
+ base::ListValue* row = new base::ListValue();
+ send_info->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 +63,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 +100,27 @@ 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("registeredAppIds",
+ JoinString(stats->registered_app_ids, ","));
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));
}
+ device_info->SetInteger("sendQueueSize", stats->send_queue_size);
+ device_info->SetInteger("resendQueueSize", stats->resend_queue_size);
+
+ if (stats->sending_activities.size() > 0) {
+ base::ListValue* send_info = new base::ListValue();
+ results.Set("sendInfo", send_info);
+ SetSendingInfo(stats->sending_activities, send_info);
+ }
}
web_ui()->CallJavascriptFunction("gcmInternals.setGcmInternalsInfo",
results);
@@ -93,17 +128,61 @@ 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()));
+ profile_service->GetGCMStatistics(
+ 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);
+
+ if (!profile_service) {
+ ReturnResults(profile, NULL, NULL);
+ return;
+ }
+ if (profile_service->SignedInUserName().empty()) {
+ ReturnResults(profile, profile_service, NULL);
+ return;
}
+ // Get fresh stats after changing recording setting.
+ profile_service->SetGCMRecording(
+ base::Bind(
+ &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished,
+ weak_ptr_factory_.GetWeakPtr()),
+ recording);
}
void GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished(
@@ -120,7 +199,11 @@ void GcmInternalsUIMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getGcmInternalsInfo",
base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo,
- base::Unretained(this)));
+ weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "setGcmInternalsRecording",
+ base::Bind(&GcmInternalsUIMessageHandler::SetRecording,
+ weak_ptr_factory_.GetWeakPtr()));
}
} // namespace