Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/ui/webui/help/version_updater.h" | 15 #include "chrome/browser/ui/webui/help/version_updater.h" |
| 16 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | |
| 16 #include "components/policy/core/common/policy_service.h" | 17 #include "components/policy/core/common/policy_service.h" |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
| 20 | 21 |
| 21 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 22 #include "base/task/cancelable_task_tracker.h" | 23 #include "base/task/cancelable_task_tracker.h" |
| 23 #include "chromeos/system/version_loader.h" | 24 #include "chromeos/system/version_loader.h" |
| 24 #endif // defined(OS_CHROMEOS) | 25 #endif // defined(OS_CHROMEOS) |
| 25 | 26 |
| 26 namespace base { | 27 namespace base { |
| 27 class DictionaryValue; | 28 class DictionaryValue; |
| 28 class FilePath; | 29 class FilePath; |
| 29 class ListValue; | 30 class ListValue; |
| 30 } | 31 } |
| 31 | 32 |
| 33 namespace content { | |
| 34 class WebUIDataSource; | |
| 35 } | |
| 36 | |
| 37 class Profile; | |
| 38 | |
| 39 namespace settings { | |
| 40 | |
| 32 // WebUI message handler for the help page. | 41 // WebUI message handler for the help page. |
| 33 class HelpHandler : public content::WebUIMessageHandler, | 42 class AboutHandler : public settings::SettingsPageUIHandler, |
|
tommycli
2016/05/10 20:45:40
This could use a unit test. I see that the origina
dpapad
2016/05/10 22:03:02
Acknowledged. I prefer to first make progress on t
tommycli
2016/05/10 22:14:52
SGTM
| |
| 34 public content::NotificationObserver { | 43 public content::NotificationObserver { |
| 35 public: | 44 public: |
| 36 HelpHandler(); | 45 AboutHandler(); |
| 37 ~HelpHandler() override; | 46 ~AboutHandler() override; |
| 47 | |
| 48 static AboutHandler* Create(content::WebUIDataSource* html_source, | |
| 49 Profile* profile); | |
| 38 | 50 |
| 39 // WebUIMessageHandler implementation. | 51 // WebUIMessageHandler implementation. |
| 40 void RegisterMessages() override; | 52 void RegisterMessages() override; |
| 41 | 53 |
| 42 // Adds string values for the UI to |localized_strings|. | |
| 43 static void GetLocalizedValues(base::DictionaryValue* localized_strings); | |
| 44 | |
| 45 // NotificationObserver implementation. | 54 // NotificationObserver implementation. |
| 46 void Observe(int type, | 55 void Observe(int type, |
| 47 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
| 48 const content::NotificationDetails& details) override; | 57 const content::NotificationDetails& details) override; |
| 49 | 58 |
| 50 // Returns the browser version as a string. | 59 // Returns the browser version as a string. |
| 51 static base::string16 BuildBrowserVersionString(); | 60 static base::string16 BuildBrowserVersionString(); |
| 52 | 61 |
| 53 private: | 62 private: |
| 54 void OnDeviceAutoUpdatePolicyChanged(const base::Value* previous_policy, | 63 void OnDeviceAutoUpdatePolicyChanged(const base::Value* previous_policy, |
| 55 const base::Value* current_policy); | 64 const base::Value* current_policy); |
| 56 | 65 |
| 57 // On ChromeOS, this gets the current update status. On other platforms, it | 66 // On ChromeOS, this gets the current update status. On other platforms, it |
| 58 // will request and perform an update (if one is available). | 67 // will request and perform an update (if one is available). |
| 59 void RefreshUpdateStatus(); | 68 void HandleRefreshUpdateStatus(const base::ListValue* args); |
| 60 | |
| 61 // Initializes querying values for the page. | |
| 62 void OnPageLoaded(const base::ListValue* args); | |
| 63 | 69 |
| 64 #if defined(OS_MACOSX) | 70 #if defined(OS_MACOSX) |
| 65 // Promotes the updater for all users. | 71 // Promotes the updater for all users. |
| 66 void PromoteUpdater(const base::ListValue* args); | 72 void PromoteUpdater(const base::ListValue* args); |
| 67 #endif | 73 #endif |
| 68 | 74 |
| 69 // Relaunches the browser. |args| must be empty. | 75 // Relaunches the browser. |args| must be empty. |
| 70 void RelaunchNow(const base::ListValue* args); | 76 void HandleRelaunchNow(const base::ListValue* args); |
| 71 | 77 |
| 72 // Opens the feedback dialog. |args| must be empty. | 78 // Opens the feedback dialog. |args| must be empty. |
| 73 void OpenFeedbackDialog(const base::ListValue* args); | 79 void HandleOpenFeedbackDialog(const base::ListValue* args); |
| 74 | 80 |
| 75 // Opens the help page. |args| must be empty. | 81 // Opens the help page. |args| must be empty. |
| 76 void OpenHelpPage(const base::ListValue* args); | 82 void HandleOpenHelpPage(const base::ListValue* args); |
| 77 | 83 |
| 78 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
| 79 // Sets the release track version. | 85 // Sets the release track version. |
| 80 void SetChannel(const base::ListValue* args); | 86 void SetChannel(const base::ListValue* args); |
|
tommycli
2016/05/10 20:45:40
Can we rename this to HandleSetChannel?
dpapad
2016/05/10 22:03:02
Done.
| |
| 81 | 87 |
| 82 // Performs relaunch and powerwash. | 88 // Checks for and applies update, triggered by JS. |
| 83 void RelaunchAndPowerwash(const base::ListValue* args); | 89 void HandleRequestUpdate(const base::ListValue* args); |
| 90 | |
| 91 void HandleGetOsVersion(const base::ListValue* args); | |
| 92 void HandleGetArcVersion(const base::ListValue* args); | |
| 93 void HandleGetOsFirmware(const base::ListValue* args); | |
| 94 // C++ callback for either of |HandleGetOsVersion|, |HandleGetArcVersion|, | |
| 95 // |HandleGetOsFirmware|. | |
| 96 void OnVersionReady(std::string callback_id, std::string version); | |
| 97 | |
| 98 void HandleGetCurrentChannel(const base::ListValue* args); | |
| 99 void HandleGetTargetChannel(const base::ListValue* args); | |
| 100 // C++ callback for either of |HandleGetCurrentChannel| or | |
| 101 // |HandleGetTargetChannel|, | |
| 102 void OnGetChannelReady(std::string callback_id, const std::string& channel); | |
| 84 #endif | 103 #endif |
| 85 | 104 |
| 86 // Checks for and applies update. | 105 // Checks for and applies update. |
| 87 void RequestUpdate(const base::ListValue* args); | 106 void RequestUpdate(); |
| 88 | 107 |
| 89 // Callback method which forwards status updates to the page. | 108 // Callback method which forwards status updates to the page. |
| 90 void SetUpdateStatus(VersionUpdater::Status status, | 109 void SetUpdateStatus(VersionUpdater::Status status, |
| 91 int progress, | 110 int progress, |
| 92 const base::string16& fail_message); | 111 const base::string16& fail_message); |
| 93 | 112 |
| 94 #if defined(OS_MACOSX) | 113 #if defined(OS_MACOSX) |
| 95 // Callback method which forwards promotion state to the page. | 114 // Callback method which forwards promotion state to the page. |
| 96 void SetPromotionState(VersionUpdater::PromotionState state); | 115 void SetPromotionState(VersionUpdater::PromotionState state); |
| 97 #endif | 116 #endif |
| 98 | 117 |
| 99 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
| 100 // Callbacks from VersionLoader. | 119 void HandleGetRegulatoryInfo(const base::ListValue* args); |
| 101 void OnOSVersion(const std::string& version); | |
| 102 void OnARCVersion(const std::string& firmware); | |
| 103 void OnOSFirmware(const std::string& firmware); | |
| 104 void OnCurrentChannel(const std::string& channel); | |
| 105 void OnTargetChannel(const std::string& channel); | |
| 106 | 120 |
| 107 // Callback for when the directory with the regulatory label image and alt | 121 // Callback for when the directory with the regulatory label image and alt |
| 108 // text has been found. | 122 // text has been found. |
| 109 void OnRegulatoryLabelDirFound(const base::FilePath& path); | 123 void OnRegulatoryLabelDirFound(std::string callback_id, |
| 124 const base::FilePath& path); | |
| 110 | 125 |
| 111 // Callback for setting the regulatory label source. | 126 // Callback for when the regulatory text has been read. |
| 112 void OnRegulatoryLabelImageFound(const base::FilePath& path); | 127 void OnRegulatoryLabelTextRead(std::string callback_id, |
| 113 | 128 const base::FilePath& path, |
| 114 // Callback for setting the regulatory label alt text. | 129 const std::string& text); |
| 115 void OnRegulatoryLabelTextRead(const std::string& text); | |
| 116 #endif | 130 #endif |
| 117 | 131 |
| 118 // Specialized instance of the VersionUpdater used to update the browser. | 132 // Specialized instance of the VersionUpdater used to update the browser. |
| 119 std::unique_ptr<VersionUpdater> version_updater_; | 133 std::unique_ptr<VersionUpdater> version_updater_; |
| 120 | 134 |
| 121 // Used to observe notifications. | 135 // Used to observe notifications. |
| 122 content::NotificationRegistrar registrar_; | 136 content::NotificationRegistrar registrar_; |
| 123 | 137 |
| 124 // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy. | 138 // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy. |
| 125 policy::PolicyChangeRegistrar policy_registrar_; | 139 policy::PolicyChangeRegistrar policy_registrar_; |
| 126 | 140 |
| 127 // Used for callbacks. | 141 // Used for callbacks. |
| 128 base::WeakPtrFactory<HelpHandler> weak_factory_; | 142 base::WeakPtrFactory<AboutHandler> weak_factory_; |
| 129 | 143 |
| 130 DISALLOW_COPY_AND_ASSIGN(HelpHandler); | 144 DISALLOW_COPY_AND_ASSIGN(AboutHandler); |
| 131 }; | 145 }; |
| 132 | 146 |
| 133 #endif // CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ | 147 } // namespace settings |
| 148 | |
| 149 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ | |
| OLD | NEW |