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

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
« no previous file with comments | « chrome/browser/services/gcm/gcm_profile_service.cc ('k') | google_apis/gcm/engine/mcs_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 RequestGCMStatisticsFinished(
44 const gcm::GCMClient::GCMStatistics& args) const;
45
46 DISALLOW_COPY_AND_ASSIGN(GcmInternalsUIMessageHandler);
47 };
48
49 GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() {}
50
51 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {}
52
53 void GcmInternalsUIMessageHandler::ReturnResults(
54 Profile* profile,
55 gcm::GCMProfileService* profile_service,
56 const gcm::GCMClient::GCMStatistics* stats) const {
57 base::DictionaryValue results;
58 base::DictionaryValue* device_info = new base::DictionaryValue();
59 results.Set("deviceInfo", device_info);
60
61 device_info->SetBoolean("userProfileExists", profile != NULL);
62 device_info->SetBoolean("profileServiceCreated", profile_service != NULL);
63 if (profile) {
64 device_info->SetString("gcmEnabledState",
65 gcm::GCMProfileService::GetGCMEnabledStateString(
66 gcm::GCMProfileService::GetGCMEnabledState(profile)));
67 }
68 if (profile_service) {
69 device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn());
70 device_info->SetBoolean("gcmClientReady",
71 profile_service->IsGCMClientReady());
72 }
73 if (stats) {
74 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created);
75 device_info->SetString("gcmClientState", stats->gcm_client_state);
76 device_info->SetBoolean("connectionClientCreated",
77 stats->connection_client_created);
78 if (stats->connection_client_created)
79 device_info->SetString("connectionState", stats->connection_state);
80 }
81 web_ui()->CallJavascriptFunction("gcm_internals.setGcmInternalsInfo",
82 results);
83 }
84
85 void GcmInternalsUIMessageHandler::RequestAllInfo(
86 const base::ListValue* args) const {
87 Profile* profile = Profile::FromWebUI(web_ui());
88 gcm::GCMProfileService* profile_service = NULL;
89 if (profile)
90 profile_service = gcm::GCMProfileServiceFactory::GetForProfile(profile);
91
92 if (!profile_service) {
93 ReturnResults(profile, NULL, NULL);
94 } else {
95 profile_service->RequestGCMStatistics(base::Bind(
96 &GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished,
97 base::Unretained(this)));
98 }
99 }
100
101 void GcmInternalsUIMessageHandler::RequestGCMStatisticsFinished(
102 const gcm::GCMClient::GCMStatistics& stats) const {
103 Profile* profile = Profile::FromWebUI(web_ui());
104 DCHECK(profile);
105 gcm::GCMProfileService* profile_service =
106 gcm::GCMProfileServiceFactory::GetForProfile(profile);
107 DCHECK(profile_service);
108 ReturnResults(profile, profile_service, &stats);
109 }
110
111 void GcmInternalsUIMessageHandler::RegisterMessages() {
112 web_ui()->RegisterMessageCallback("getGcmInternalsInfo",
fgorski 2014/03/01 22:40:09 nit: move the parameter to a line of its own
juyik 2014/03/04 19:37:25 Done.
113 base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo,
114 base::Unretained(this)));
115 }
116
117 } // namespace
118
12 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) 119 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui)
13 : content::WebUIController(web_ui) { 120 : content::WebUIController(web_ui) {
14 // Set up the chrome://gcm-internals source. 121 // Set up the chrome://gcm-internals source.
15 content::WebUIDataSource* html_source = 122 content::WebUIDataSource* html_source =
16 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); 123 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost);
17 html_source->SetUseJsonJSFormatV2(); 124 html_source->SetUseJsonJSFormatV2();
18 125
19 html_source->SetJsonPath("strings.js"); 126 html_source->SetJsonPath("strings.js");
20 127
21 // Add required resources. 128 // Add required resources.
22 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS); 129 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS);
23 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); 130 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS);
24 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); 131 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML);
25 132
26 Profile* profile = Profile::FromWebUI(web_ui); 133 Profile* profile = Profile::FromWebUI(web_ui);
27 content::WebUIDataSource::Add(profile, html_source); 134 content::WebUIDataSource::Add(profile, html_source);
135
136 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler());
28 } 137 }
29 138
30 GCMInternalsUI::~GCMInternalsUI() {} 139 GCMInternalsUI::~GCMInternalsUI() {}
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_profile_service.cc ('k') | google_apis/gcm/engine/mcs_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698