Chromium Code Reviews| 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 "base/bind.h" | |
| 8 #include "base/values.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/services/gcm/gcm_profile_service.h" | |
| 11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | |
| 8 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "content/public/browser/web_ui.h" | |
| 14 #include "content/public/browser/web_ui_controller.h" | |
| 9 #include "content/public/browser/web_ui_data_source.h" | 15 #include "content/public/browser/web_ui_data_source.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" | |
| 17 #include "google_apis/gcm/gcm_client.h" | |
| 10 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
| 11 | 19 |
| 20 namespace { | |
| 21 | |
| 22 // Class acting as a controller of the chrome://gcm-internals WebUI. | |
| 23 class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler { | |
| 24 public: | |
| 25 GcmInternalsUIMessageHandler(); | |
| 26 virtual ~GcmInternalsUIMessageHandler(); | |
| 27 | |
| 28 // WebUIMessageHandler implementation. | |
| 29 virtual void RegisterMessages() OVERRIDE; | |
| 30 | |
| 31 private: | |
|
jianli
2014/02/27 00:49:34
nit: add DISALLOW_COPY_AND_ASSIGN
juyik
2014/03/01 00:21:57
Done.
| |
| 32 // Gets all of the GCM related infos and returns them to the caller using | |
| 33 // Javascript callback function | |
| 34 // |gcm-internals.returnInfo()|. | |
| 35 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.
| |
| 36 }; | |
| 37 | |
| 38 GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() {} | |
| 39 | |
| 40 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {} | |
| 41 | |
| 42 void GcmInternalsUIMessageHandler::GetAllInfo(const base::ListValue* args) { | |
| 43 base::DictionaryValue results; | |
| 44 base::DictionaryValue* device_info = new base::DictionaryValue(); | |
| 45 | |
| 46 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 47 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.
| |
| 48 gcm::GCMProfileServiceFactory::GetForProfile(profile); | |
| 49 gcm::GCMClient* gcm_client = profile_service->GetGCMClient(); | |
| 50 | |
| 51 device_info->SetBoolean("gcmEnabled", | |
| 52 gcm::GCMProfileService::IsGCMEnabled(profile)); | |
| 53 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.
| |
| 54 device_info->SetBoolean("userSignedIn", profile_service->IsSignedIn()); | |
| 55 device_info->SetBoolean("gcmClientCreated", gcm_client != NULL); | |
| 56 if (gcm_client) | |
| 57 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.
| |
| 58 | |
| 59 results.Set("deviceInfo", device_info); | |
| 60 web_ui()->CallJavascriptFunction("gcm_internals.returnInfos", results); | |
| 61 } | |
| 62 | |
| 63 void GcmInternalsUIMessageHandler::RegisterMessages() { | |
| 64 web_ui()->RegisterMessageCallback("gcmInternalsGetInfo", | |
|
fgorski
2014/02/26 23:38:19
call it getGcmInternalsInfo
juyik
2014/03/01 00:21:57
Done.
| |
| 65 base::Bind(&GcmInternalsUIMessageHandler::GetAllInfo, | |
| 66 base::Unretained(this))); | |
| 67 } | |
| 68 | |
| 69 } // namespace | |
| 70 | |
| 12 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) | 71 GCMInternalsUI::GCMInternalsUI(content::WebUI* web_ui) |
| 13 : content::WebUIController(web_ui) { | 72 : content::WebUIController(web_ui) { |
| 14 // Set up the chrome://gcm-internals source. | 73 // Set up the chrome://gcm-internals source. |
| 15 content::WebUIDataSource* html_source = | 74 content::WebUIDataSource* html_source = |
| 16 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); | 75 content::WebUIDataSource::Create(chrome::kChromeUIGCMInternalsHost); |
| 17 html_source->SetUseJsonJSFormatV2(); | 76 html_source->SetUseJsonJSFormatV2(); |
| 18 | 77 |
| 19 html_source->SetJsonPath("strings.js"); | 78 html_source->SetJsonPath("strings.js"); |
| 20 | 79 |
| 21 // Add required resources. | 80 // Add required resources. |
| 22 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS); | 81 html_source->AddResourcePath("gcm_internals.css", IDR_GCM_INTERNALS_CSS); |
| 23 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); | 82 html_source->AddResourcePath("gcm_internals.js", IDR_GCM_INTERNALS_JS); |
| 24 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); | 83 html_source->SetDefaultResource(IDR_GCM_INTERNALS_HTML); |
| 25 | 84 |
| 26 Profile* profile = Profile::FromWebUI(web_ui); | 85 Profile* profile = Profile::FromWebUI(web_ui); |
| 27 content::WebUIDataSource::Add(profile, html_source); | 86 content::WebUIDataSource::Add(profile, html_source); |
| 87 | |
| 88 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); | |
| 28 } | 89 } |
| 29 | 90 |
| 30 GCMInternalsUI::~GCMInternalsUI() {} | 91 GCMInternalsUI::~GCMInternalsUI() {} |
| OLD | NEW |