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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/gcm_internals_ui.h" 5 #include "chrome/browser/ui/webui/gcm_internals_ui.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/values.h"
7 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
8 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/web_ui.h"
15 #include "content/public/browser/web_ui_controller.h"
9 #include "content/public/browser/web_ui_data_source.h" 16 #include "content/public/browser/web_ui_data_source.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "google_apis/gcm/gcm_client.h"
10 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
11 20
21 namespace {
22
23 // Class acting as a controller of the chrome://gcm-internals WebUI.
24 class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler {
25 public:
26 GcmInternalsUIMessageHandler();
27 virtual ~GcmInternalsUIMessageHandler();
28
29 // WebUIMessageHandler implementation.
30 virtual void RegisterMessages() OVERRIDE;
31
32 private:
33 // Return all of the GCM related infos to the gcm-internals page by calling
34 // Javascript callback function
35 // |gcm-internals.returnInfo()|.
36 void ReturnResults(Profile* profile, gcm::GCMProfileService* profile_service,
37 const gcm::GCMClient::GCMStatistics* stats) const;
38
39 // Request all of the GCM related infos through gcm profile service.
40 void RequestAllInfo(const base::ListValue* args) const;
41
42 // Callback function of the request for all gcm related infos.
43 void RequestAllInfoFinished(const gcm::GCMClient::GCMStatistics& args) const;
44
45 DISALLOW_COPY_AND_ASSIGN(GcmInternalsUIMessageHandler);
46 };
47
48 GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() {}
49
50 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {}
51
52 void GcmInternalsUIMessageHandler::ReturnResults(
53 Profile* profile,
54 gcm::GCMProfileService* profile_service,
55 const gcm::GCMClient::GCMStatistics* stats) const {
56 base::DictionaryValue results;
57 base::DictionaryValue* device_info = new base::DictionaryValue();
58 results.Set("deviceInfo", device_info);
59
60 device_info->SetBoolean("userProfileExists", profile != NULL);
61 device_info->SetBoolean("profileServiceCreated", profile_service != NULL);
62 if (profile) {
63 device_info->SetBoolean("gcmEnabled",
64 gcm::GCMProfileService::IsGCMEnabled(profile));
65 }
66 if (profile_service) {
67 device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn());
68 device_info->SetBoolean("gcmClientReady",
69 profile_service->IsGCMClientReady());
70 }
71 if (stats) {
72 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created);
73 device_info->SetString("gcmClientState", stats->gcm_client_state);
74 device_info->SetBoolean("connectionClientCreated",
75 stats->connection_client_created);
76 if (stats->connection_client_created)
77 device_info->SetString("connectionState", stats->connection_state);
78 }
79 web_ui()->CallJavascriptFunction("gcm_internals.setGcmInternalsInfo",
80 results);
81 }
82
83 void GcmInternalsUIMessageHandler::RequestAllInfo(
84 const base::ListValue* args) const {
85 Profile* profile = Profile::FromWebUI(web_ui());
86 gcm::GCMProfileService* profile_service = NULL;
87 if (profile)
88 profile_service = gcm::GCMProfileServiceFactory::GetForProfile(profile);
89
90 if (profile_service) {
91 profile_service->RequestGCMStatistics(base::Bind(
92 &GcmInternalsUIMessageHandler::RequestAllInfoFinished,
93 base::Unretained(this)));
94 } else {
95 ReturnResults(profile, profile_service, NULL);
fgorski 2014/02/28 19:52:47 (profile, NULL, NULL)
juyik 2014/03/01 00:21:57 Done.
96 }
97 }
98
99 void GcmInternalsUIMessageHandler::RequestAllInfoFinished(
fgorski 2014/02/28 19:52:47 RequestGCMStatisticsFinished -> it will be easier
juyik 2014/03/01 00:21:57 Done.
100 const gcm::GCMClient::GCMStatistics& stats) const {
101 Profile* profile = Profile::FromWebUI(web_ui());
102 gcm::GCMProfileService* profile_service = NULL;
103 if (profile)
104 profile_service = gcm::GCMProfileServiceFactory::GetForProfile(profile);
105 ReturnResults(profile, profile_service, &stats);
106 }
107
108 void GcmInternalsUIMessageHandler::RegisterMessages() {
109 web_ui()->RegisterMessageCallback("getGcmInternalsInfo",
110 base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo,
111 base::Unretained(this)));
112 }
113
114 } // namespace
115
12 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) 116 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui)
13 : content::WebUIController(web_ui) { 117 : content::WebUIController(web_ui) {
14 // Set up the chrome://gcm-internals source. 118 // Set up the chrome://gcm-internals source.
15 content::WebUIDataSource* html_source = 119 content::WebUIDataSource* html_source =
16 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); 120 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost);
17 html_source->SetUseJsonJSFormatV2(); 121 html_source->SetUseJsonJSFormatV2();
18 122
19 html_source->SetJsonPath("strings.js"); 123 html_source->SetJsonPath("strings.js");
20 124
21 // Add required resources. 125 // Add required resources.
22 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS); 126 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS);
23 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); 127 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS);
24 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); 128 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML);
25 129
26 Profile* profile = Profile::FromWebUI(web_ui); 130 Profile* profile = Profile::FromWebUI(web_ui);
27 content::WebUIDataSource::Add(profile, html_source); 131 content::WebUIDataSource::Add(profile, html_source);
132
133 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler());
28 } 134 }
29 135
30 GCMInternalsUI::~GCMInternalsUI() {} 136 GCMInternalsUI::~GCMInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698