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

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..d5d4609ef5ed41d309b8642434b3c55d0c4b76ee 100644
--- a/chrome/browser/ui/webui/gcm_internals_ui.cc
+++ b/chrome/browser/ui/webui/gcm_internals_ui.cc
@@ -4,11 +4,115 @@
#include "chrome/browser/ui/webui/gcm_internals_ui.h"
+#include "base/bind.h"
+#include "base/bind_helpers.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:
+ // Return all of the GCM related infos to the gcm-internals page by calling
+ // Javascript callback function
+ // |gcm-internals.returnInfo()|.
+ void ReturnResults(Profile* profile, gcm::GCMProfileService* profile_service,
+ const gcm::GCMClient::GCMStatistics* stats) const;
+
+ // Request all of the GCM related infos through gcm profile service.
+ void RequestAllInfo(const base::ListValue* args) const;
+
+ // Callback function of the request for all gcm related infos.
+ void RequestAllInfoFinished(const gcm::GCMClient::GCMStatistics& args) const;
+
+ DISALLOW_COPY_AND_ASSIGN(GcmInternalsUIMessageHandler);
+};
+
+GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() {}
+
+GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {}
+
+void GcmInternalsUIMessageHandler::ReturnResults(
+ Profile* profile,
+ gcm::GCMProfileService* profile_service,
+ const gcm::GCMClient::GCMStatistics* stats) const {
+ base::DictionaryValue results;
+ base::DictionaryValue* device_info = new base::DictionaryValue();
+ results.Set("deviceInfo", device_info);
+
+ device_info->SetBoolean("userProfileExists", profile != NULL);
+ device_info->SetBoolean("profileServiceCreated", profile_service != NULL);
+ if (profile) {
+ device_info->SetBoolean("gcmEnabled",
+ gcm::GCMProfileService::IsGCMEnabled(profile));
+ }
+ if (profile_service) {
+ device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn());
+ device_info->SetBoolean("gcmClientReady",
+ profile_service->IsGCMClientReady());
+ }
+ if (stats) {
+ device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created);
+ device_info->SetString("gcmClientState", stats->gcm_client_state);
+ device_info->SetBoolean("connectionClientCreated",
+ stats->connection_client_created);
+ if (stats->connection_client_created)
+ device_info->SetString("connectionState", stats->connection_state);
+ }
+ web_ui()->CallJavascriptFunction("gcm_internals.setGcmInternalsInfo",
+ results);
+}
+
+void GcmInternalsUIMessageHandler::RequestAllInfo(
+ const base::ListValue* args) const {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ gcm::GCMProfileService* profile_service = NULL;
+ if (profile)
+ profile_service = gcm::GCMProfileServiceFactory::GetForProfile(profile);
+
+ if (profile_service) {
+ profile_service->RequestGCMStatistics(base::Bind(
+ &GcmInternalsUIMessageHandler::RequestAllInfoFinished,
+ base::Unretained(this)));
+ } else {
+ ReturnResults(profile, profile_service, NULL);
fgorski 2014/02/28 19:52:47 (profile, NULL, NULL)
juyik 2014/03/01 00:21:57 Done.
+ }
+}
+
+void GcmInternalsUIMessageHandler::RequestAllInfoFinished(
fgorski 2014/02/28 19:52:47 RequestGCMStatisticsFinished -> it will be easier
juyik 2014/03/01 00:21:57 Done.
+ const gcm::GCMClient::GCMStatistics& stats) const {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ gcm::GCMProfileService* profile_service = NULL;
+ if (profile)
+ profile_service = gcm::GCMProfileServiceFactory::GetForProfile(profile);
+ ReturnResults(profile, profile_service, &stats);
+}
+
+void GcmInternalsUIMessageHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("getGcmInternalsInfo",
+ base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo,
+ base::Unretained(this)));
+}
+
+} // namespace
+
GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
// Set up the chrome://gcm-internals source.
@@ -25,6 +129,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