OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 18 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "components/gcm_driver/gcm_client.h" | 21 #include "components/gcm_driver/gcm_client.h" |
22 #include "components/gcm_driver/gcm_driver.h" | 22 #include "components/gcm_driver/gcm_driver.h" |
| 23 #include "components/gcm_driver/gcm_internals_constants.h" |
23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
24 #include "content/public/browser/web_ui_controller.h" | 25 #include "content/public/browser/web_ui_controller.h" |
25 #include "content/public/browser/web_ui_data_source.h" | 26 #include "content/public/browser/web_ui_data_source.h" |
26 #include "content/public/browser/web_ui_message_handler.h" | 27 #include "content/public/browser/web_ui_message_handler.h" |
27 #include "grit/browser_resources.h" | 28 #include "grit/components_resources.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 void SetCheckinInfo( | 32 void SetCheckinInfo( |
32 const std::vector<gcm::CheckinActivity>& checkins, | 33 const std::vector<gcm::CheckinActivity>& checkins, |
33 base::ListValue* checkin_info) { | 34 base::ListValue* checkin_info) { |
34 std::vector<gcm::CheckinActivity>::const_iterator it = checkins.begin(); | 35 std::vector<gcm::CheckinActivity>::const_iterator it = checkins.begin(); |
35 for (; it < checkins.end(); ++it) { | 36 for (; it < checkins.end(); ++it) { |
36 base::ListValue* row = new base::ListValue(); | 37 base::ListValue* row = new base::ListValue(); |
37 checkin_info->Append(row); | 38 checkin_info->Append(row); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 : weak_ptr_factory_(this) {} | 144 : weak_ptr_factory_(this) {} |
144 | 145 |
145 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {} | 146 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {} |
146 | 147 |
147 void GcmInternalsUIMessageHandler::ReturnResults( | 148 void GcmInternalsUIMessageHandler::ReturnResults( |
148 Profile* profile, | 149 Profile* profile, |
149 gcm::GCMProfileService* profile_service, | 150 gcm::GCMProfileService* profile_service, |
150 const gcm::GCMClient::GCMStatistics* stats) const { | 151 const gcm::GCMClient::GCMStatistics* stats) const { |
151 base::DictionaryValue results; | 152 base::DictionaryValue results; |
152 base::DictionaryValue* device_info = new base::DictionaryValue(); | 153 base::DictionaryValue* device_info = new base::DictionaryValue(); |
153 results.Set("deviceInfo", device_info); | 154 results.Set(gcm_driver::kDeviceInfo, device_info); |
154 | 155 |
155 device_info->SetBoolean("profileServiceCreated", profile_service != NULL); | 156 device_info->SetBoolean(gcm_driver::kProfileServiceCreated, |
156 device_info->SetBoolean("gcmEnabled", | 157 profile_service != NULL); |
| 158 device_info->SetBoolean(gcm_driver::kGcmEnabled, |
157 gcm::GCMProfileService::IsGCMEnabled(profile)); | 159 gcm::GCMProfileService::IsGCMEnabled(profile)); |
158 if (stats) { | 160 if (stats) { |
159 results.SetBoolean("isRecording", stats->is_recording); | 161 results.SetBoolean(gcm_driver::kIsRecording, stats->is_recording); |
160 device_info->SetBoolean("gcmClientCreated", stats->gcm_client_created); | 162 device_info->SetBoolean(gcm_driver::kGcmClientCreated, |
161 device_info->SetString("gcmClientState", stats->gcm_client_state); | 163 stats->gcm_client_created); |
162 device_info->SetBoolean("connectionClientCreated", | 164 device_info->SetString(gcm_driver::kGcmClientState, |
| 165 stats->gcm_client_state); |
| 166 device_info->SetBoolean(gcm_driver::kConnectionClientCreated, |
163 stats->connection_client_created); | 167 stats->connection_client_created); |
164 device_info->SetString("registeredAppIds", | 168 device_info->SetString(gcm_driver::kRegisteredAppIds, |
165 base::JoinString(stats->registered_app_ids, ",")); | 169 base::JoinString(stats->registered_app_ids, ",")); |
166 if (stats->connection_client_created) | 170 if (stats->connection_client_created) |
167 device_info->SetString("connectionState", stats->connection_state); | 171 device_info->SetString(gcm_driver::kConnectionState, |
| 172 stats->connection_state); |
168 if (stats->android_id > 0) { | 173 if (stats->android_id > 0) { |
169 device_info->SetString("androidId", | 174 device_info->SetString( |
| 175 gcm_driver::kAndroidId, |
170 base::StringPrintf("0x%" PRIx64, stats->android_id)); | 176 base::StringPrintf("0x%" PRIx64, stats->android_id)); |
171 } | 177 } |
172 device_info->SetInteger("sendQueueSize", stats->send_queue_size); | 178 device_info->SetInteger(gcm_driver::kSendQueueSize, stats->send_queue_size); |
173 device_info->SetInteger("resendQueueSize", stats->resend_queue_size); | 179 device_info->SetInteger(gcm_driver::kResendQueueSize, |
| 180 stats->resend_queue_size); |
174 | 181 |
175 if (stats->recorded_activities.checkin_activities.size() > 0) { | 182 if (stats->recorded_activities.checkin_activities.size() > 0) { |
176 base::ListValue* checkin_info = new base::ListValue(); | 183 base::ListValue* checkin_info = new base::ListValue(); |
177 results.Set("checkinInfo", checkin_info); | 184 results.Set(gcm_driver::kCheckinInfo, checkin_info); |
178 SetCheckinInfo(stats->recorded_activities.checkin_activities, | 185 SetCheckinInfo(stats->recorded_activities.checkin_activities, |
179 checkin_info); | 186 checkin_info); |
180 } | 187 } |
181 if (stats->recorded_activities.connection_activities.size() > 0) { | 188 if (stats->recorded_activities.connection_activities.size() > 0) { |
182 base::ListValue* connection_info = new base::ListValue(); | 189 base::ListValue* connection_info = new base::ListValue(); |
183 results.Set("connectionInfo", connection_info); | 190 results.Set(gcm_driver::kConnectionInfo, connection_info); |
184 SetConnectionInfo(stats->recorded_activities.connection_activities, | 191 SetConnectionInfo(stats->recorded_activities.connection_activities, |
185 connection_info); | 192 connection_info); |
186 } | 193 } |
187 if (stats->recorded_activities.registration_activities.size() > 0) { | 194 if (stats->recorded_activities.registration_activities.size() > 0) { |
188 base::ListValue* registration_info = new base::ListValue(); | 195 base::ListValue* registration_info = new base::ListValue(); |
189 results.Set("registrationInfo", registration_info); | 196 results.Set(gcm_driver::kRegistrationInfo, registration_info); |
190 SetRegistrationInfo(stats->recorded_activities.registration_activities, | 197 SetRegistrationInfo(stats->recorded_activities.registration_activities, |
191 registration_info); | 198 registration_info); |
192 } | 199 } |
193 if (stats->recorded_activities.receiving_activities.size() > 0) { | 200 if (stats->recorded_activities.receiving_activities.size() > 0) { |
194 base::ListValue* receive_info = new base::ListValue(); | 201 base::ListValue* receive_info = new base::ListValue(); |
195 results.Set("receiveInfo", receive_info); | 202 results.Set(gcm_driver::kReceiveInfo, receive_info); |
196 SetReceivingInfo(stats->recorded_activities.receiving_activities, | 203 SetReceivingInfo(stats->recorded_activities.receiving_activities, |
197 receive_info); | 204 receive_info); |
198 } | 205 } |
199 if (stats->recorded_activities.sending_activities.size() > 0) { | 206 if (stats->recorded_activities.sending_activities.size() > 0) { |
200 base::ListValue* send_info = new base::ListValue(); | 207 base::ListValue* send_info = new base::ListValue(); |
201 results.Set("sendInfo", send_info); | 208 results.Set(gcm_driver::kSendInfo, send_info); |
202 SetSendingInfo(stats->recorded_activities.sending_activities, send_info); | 209 SetSendingInfo(stats->recorded_activities.sending_activities, send_info); |
203 } | 210 } |
204 } | 211 } |
205 web_ui()->CallJavascriptFunction("gcmInternals.setGcmInternalsInfo", | 212 web_ui()->CallJavascriptFunction(gcm_driver::kSetGcmInternalsInfo, results); |
206 results); | |
207 } | 213 } |
208 | 214 |
209 void GcmInternalsUIMessageHandler::RequestAllInfo( | 215 void GcmInternalsUIMessageHandler::RequestAllInfo( |
210 const base::ListValue* args) { | 216 const base::ListValue* args) { |
211 if (args->GetSize() != 1) { | 217 if (args->GetSize() != 1) { |
212 NOTREACHED(); | 218 NOTREACHED(); |
213 return; | 219 return; |
214 } | 220 } |
215 bool clear_logs = false; | 221 bool clear_logs = false; |
216 if (!args->GetBoolean(0, &clear_logs)) { | 222 if (!args->GetBoolean(0, &clear_logs)) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 Profile* profile = Profile::FromWebUI(web_ui()); | 270 Profile* profile = Profile::FromWebUI(web_ui()); |
265 DCHECK(profile); | 271 DCHECK(profile); |
266 gcm::GCMProfileService* profile_service = | 272 gcm::GCMProfileService* profile_service = |
267 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 273 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
268 DCHECK(profile_service); | 274 DCHECK(profile_service); |
269 ReturnResults(profile, profile_service, &stats); | 275 ReturnResults(profile, profile_service, &stats); |
270 } | 276 } |
271 | 277 |
272 void GcmInternalsUIMessageHandler::RegisterMessages() { | 278 void GcmInternalsUIMessageHandler::RegisterMessages() { |
273 web_ui()->RegisterMessageCallback( | 279 web_ui()->RegisterMessageCallback( |
274 "getGcmInternalsInfo", | 280 gcm_driver::kGetGcmInternalsInfo, |
275 base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo, | 281 base::Bind(&GcmInternalsUIMessageHandler::RequestAllInfo, |
276 weak_ptr_factory_.GetWeakPtr())); | 282 weak_ptr_factory_.GetWeakPtr())); |
277 web_ui()->RegisterMessageCallback( | 283 web_ui()->RegisterMessageCallback( |
278 "setGcmInternalsRecording", | 284 gcm_driver::kSetGcmInternalsRecording, |
279 base::Bind(&GcmInternalsUIMessageHandler::SetRecording, | 285 base::Bind(&GcmInternalsUIMessageHandler::SetRecording, |
280 weak_ptr_factory_.GetWeakPtr())); | 286 weak_ptr_factory_.GetWeakPtr())); |
281 } | 287 } |
282 | 288 |
283 } // namespace | 289 } // namespace |
284 | 290 |
285 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) | 291 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) |
286 : content::WebUIController(web_ui) { | 292 : content::WebUIController(web_ui) { |
287 // Set up the chrome://gcm-internals source. | 293 // Set up the chrome://gcm-internals source. |
288 content::WebUIDataSource* html_source = | 294 content::WebUIDataSource* html_source = |
289 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); | 295 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); |
290 | 296 |
291 html_source->SetJsonPath("strings.js"); | 297 html_source->SetJsonPath("strings.js"); |
292 | 298 |
293 // Add required resources. | 299 // Add required resources. |
294 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS); | 300 html_source->AddResourcePath(gcm_driver::kGcmInternalsCSS, |
295 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); | 301 IDR_GCM_DRIVER_GCM_INTERNALS_CSS); |
296 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); | 302 html_source->AddResourcePath(gcm_driver::kGcmInternalsJS, |
| 303 IDR_GCM_DRIVER_GCM_INTERNALS_JS); |
| 304 html_source->SetDefaultResource(IDR_GCM_DRIVER_GCM_INTERNALS_HTML); |
297 | 305 |
298 Profile* profile = Profile::FromWebUI(web_ui); | 306 Profile* profile = Profile::FromWebUI(web_ui); |
299 content::WebUIDataSource::Add(profile, html_source); | 307 content::WebUIDataSource::Add(profile, html_source); |
300 | 308 |
301 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); | 309 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); |
302 } | 310 } |
303 | 311 |
304 GCMInternalsUI::~GCMInternalsUI() {} | 312 GCMInternalsUI::~GCMInternalsUI() {} |
OLD | NEW |