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

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

Issue 176823009: Show device information in chrome://gcm-internals page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 b9966204b060485cd8c46fa6164b58e255fa1523..ebf15d4efa64baf9be829879a0c86f1a6c12e71e 100644
--- a/chrome/browser/ui/webui/gcm_internals_ui.cc
+++ b/chrome/browser/ui/webui/gcm_internals_ui.cc
@@ -4,11 +4,70 @@
#include "chrome/browser/ui/webui/gcm_internals_ui.h"
+#include "base/bind.h"
+#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/services/gcm/gcm_profile_service.h"
+#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
+#include "content/public/browser/web_ui_message_handler.h"
+#include "google_apis/gcm/gcm_client.h"
#include "grit/browser_resources.h"
+namespace {
+
+// Class acting as a controller of the chrome://gcm-internals WebUI.
+class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler {
+ public:
+ GcmInternalsUIMessageHandler();
+ virtual ~GcmInternalsUIMessageHandler();
+
+ // WebUIMessageHandler implementation.
+ virtual void RegisterMessages() OVERRIDE;
+
+ private:
jianli 2014/02/27 00:49:34 nit: add DISALLOW_COPY_AND_ASSIGN
juyik 2014/03/01 00:21:57 Done.
+ // Gets all of the GCM related infos and returns them to the caller using
+ // Javascript callback function
+ // |gcm-internals.returnInfo()|.
+ void GetAllInfo(const base::ListValue* args);
jianli 2014/02/27 00:49:34 nit: add const modifier
juyik 2014/03/01 00:21:57 Done.
+};
+
+GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() {}
+
+GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {}
+
+void GcmInternalsUIMessageHandler::GetAllInfo(const base::ListValue* args) {
+ base::DictionaryValue results;
+ base::DictionaryValue* device_info = new base::DictionaryValue();
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ gcm::GCMProfileService* profile_service =
jianli 2014/02/27 00:49:34 profile_service could be null, like in incognito m
juyik 2014/03/01 00:21:57 Done.
+ gcm::GCMProfileServiceFactory::GetForProfile(profile);
+ gcm::GCMClient* gcm_client = profile_service->GetGCMClient();
+
+ device_info->SetBoolean("gcmEnabled",
+ gcm::GCMProfileService::IsGCMEnabled(profile));
+ device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn());
fgorski 2014/02/26 23:38:19 this is duplicated.
juyik 2014/03/01 00:21:57 Done.
+ device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn());
+ device_info->SetBoolean("gcmClientCreated", gcm_client != NULL);
+ if (gcm_client)
+ device_info->SetBoolean("gcmClientReady", gcm_client->IsReady());
jianli 2014/02/27 00:49:34 IsReady is going to be removed from GCMClient inte
juyik 2014/03/01 00:21:57 Done.
+
+ results.Set("deviceInfo", device_info);
+ web_ui()->CallJavascriptFunction("gcm_internals.returnInfos", results);
+}
+
+void GcmInternalsUIMessageHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("gcmInternalsGetInfo",
fgorski 2014/02/26 23:38:19 call it getGcmInternalsInfo
juyik 2014/03/01 00:21:57 Done.
+ base::Bind(&GcmInternalsUIMessageHandler::GetAllInfo,
+ base::Unretained(this)));
+}
+
+} // namespace
+
GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
// Set up the chrome://gcm-internals source.
@@ -25,6 +84,8 @@ GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui)
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, html_source);
+
+ web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler());
}
GCMInternalsUI::~GCMInternalsUI() {}

Powered by Google App Engine
This is Rietveld 408576698