File: about_handler.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (253 lines) | stat: -rw-r--r-- 9,707 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/ui/webui/help/version_updater.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "chrome/browser/upgrade_detector/upgrade_observer.h"
#include "components/policy/core/common/policy_service.h"
#include "content/public/browser/web_ui_message_handler.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "base/callback_list.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/ash/tpm/tpm_firmware_update.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace base {
class Clock;
class FilePath;
}  // namespace base

class Profile;

namespace settings {

// WebUI message handler for the help page.
class AboutHandler : public settings::SettingsPageUIHandler,
                     public UpgradeObserver {
 public:
  explicit AboutHandler(Profile* profile);

  AboutHandler(const AboutHandler&) = delete;
  AboutHandler& operator=(const AboutHandler&) = delete;

  ~AboutHandler() override;

  // WebUIMessageHandler implementation.
  void RegisterMessages() override;
  void OnJavascriptAllowed() override;
  void OnJavascriptDisallowed() override;

  // UpgradeObserver implementation.
  void OnUpgradeRecommended() override;

 protected:
  // Used to test the EOL string displayed in the About details page.
  void set_clock(base::Clock* clock) { clock_ = clock; }

 private:
  void OnDeviceAutoUpdatePolicyChanged(const base::Value* previous_policy,
                                       const base::Value* current_policy);

  // Called once the JS page is ready to be called, serves as a signal to the
  // handler to register C++ observers.
  void HandlePageReady(const base::Value::List& args);

  // Called once when the page has loaded. On ChromeOS, this gets the current
  // update status. On other platforms, it will request and perform an update
  // (if one is available).
  void HandleRefreshUpdateStatus(const base::Value::List& args);
  void RefreshUpdateStatus();

#if BUILDFLAG(IS_MAC)
  // Promotes the updater for all users.
  void PromoteUpdater(const base::Value::List& args);
#endif

  // Opens the feedback dialog.
  // |args| must be empty.
  void HandleOpenFeedbackDialog(const base::Value::List& args);

  // Opens the help page. |args| must be empty.
  void HandleOpenHelpPage(const base::Value::List& args);

#if BUILDFLAG(IS_CHROMEOS)
  // Checks if ReleaseNotes is enabled.
  void HandleGetEnabledReleaseNotes(const base::Value::List& args);

  // Checks if system is connected to internet.
  void HandleCheckInternetConnection(const base::Value::List& args);

  // Opens the release notes app. |args| must be empty.
  void HandleLaunchReleaseNotes(const base::Value::List& args);

  // Opens the help page. |args| must be empty.
  void HandleOpenOsHelpPage(const base::Value::List& args);

  // Sets the release track version.
  void HandleSetChannel(const base::Value::List& args);

  // Retrieves OS, ARC and firmware versions.
  void HandleGetVersionInfo(const base::Value::List& args);
  void OnGetVersionInfoReady(std::string callback_id,
                             base::Value::Dict version_info);

  // Retrieves the number of firmware updates available.
  void HandleGetFirmwareUpdateCount(const base::Value::List& args);

  // Retrieves channel info.
  void HandleGetChannelInfo(const base::Value::List& args);

  // Checks whether we can update the firmware.
  void HandleCanChangeFirmware(const base::Value::List& args);

  // Checks whether we can change the current channel.
  void HandleCanChangeChannel(const base::Value::List& args);

  // Callbacks for version_updater_->GetChannel calls.
  void OnGetCurrentChannel(std::string callback_id,
                           const std::string& current_channel);
  void OnGetTargetChannel(std::string callback_id,
                          const std::string& current_channel,
                          const std::string& target_channel);

  // Applies deferred update, triggered by JS.
  void HandleApplyDeferredUpdateAdvanced(const base::Value::List& args);

  // Checks for and applies update, triggered by JS.
  void HandleRequestUpdate(const base::Value::List& args);

  // Checks for and applies update over cellular connection, triggered by JS.
  // Update version and size should be included in the list of arguments.
  void HandleRequestUpdateOverCellular(const base::Value::List& args);

  // Checks for and applies update over cellular connection.
  void RequestUpdateOverCellular(const std::string& update_version,
                                 int64_t update_size);

  // Called once when the page has loaded to retrieve the TPM firmware update
  // status.
  void HandleRefreshTPMFirmwareUpdateStatus(const base::Value::List& args);
  void RefreshTPMFirmwareUpdateStatus(
      const std::set<ash::tpm_firmware_update::Mode>& modes);
#endif

  // Checks for and applies update.
  void RequestUpdate();

  // Callback method which forwards status updates to the page.
  void SetUpdateStatus(VersionUpdater::Status status,
                       int progress,
                       bool rollback,
                       bool powerwash,
                       const std::string& version,
                       int64_t size,
                       const std::u16string& fail_message);

#if BUILDFLAG(IS_MAC)
  // Callback method which forwards promotion state to the page.
  void SetPromotionState(VersionUpdater::PromotionState state);
#endif

#if BUILDFLAG(IS_CHROMEOS)
  void HandleOpenDiagnostics(const base::Value::List& args);

  void HandleOpenFirmwareUpdates(const base::Value::List& args);

  void HandleGetRegulatoryInfo(const base::Value::List& args);

  // Callback for when the directory with the regulatory label image and alt
  // text has been found.
  void OnRegulatoryLabelDirFound(std::string callback_id,
                                 const base::FilePath& label_dir_path);

  // Callback for when the regulatory text has been read.
  void OnRegulatoryLabelTextRead(std::string callback_id,
                                 const base::FilePath& label_dir_path,
                                 const std::string& text);

  // Retrieves device End of Life information which contains the End of Life
  // date. Will asynchronously resolve the provided callback with an object
  // containing a boolean indicating whether the device has reached/passed End
  // of Life, and an End Of Life description formatted with the month and year.
  void HandleGetEndOfLifeInfo(const base::Value::List& args);

  // Callbacks for version_updater_->GetEolInfo calls.
  void OnGetEndOfLifeInfo(std::string callback_id,
                          ash::UpdateEngineClient::EolInfo eol_info);

  std::u16string GetEndOfLifeMessage(base::Time eol_date) const;

  // Opens the end of life incentive URL.
  void HandleOpenEndOfLifeIncentive(const base::Value::List& args);

  // Get the managed auto update cros setting.
  void HandleIsManagedAutoUpdateEnabled(const base::Value::List& args);

  // Get the consumer auto update pref from update_engine.
  void HandleIsConsumerAutoUpdateEnabled(const base::Value::List& args);

  // Callbacks for version_updater_->IsConsumerAutoUpdateEnabled calls.
  void OnIsConsumerAutoUpdateEnabled(std::string callback_id,
                                     std::string feature,
                                     std::optional<bool> enabled);

  void HandleSetConsumerAutoUpdate(const base::Value::List& args);
  void HandleOpenProductLicenseOther(const base::Value::List& args);

  // Handles the check for extended updates eligibility.
  // |args| should have 4 values:
  //   - [string] Name of the callback function
  //   - [bool] Whether eol has passed
  //   - [bool] Whether extended updates date has passed
  //   - [bool] Whether opt-in is required for extended updates
  void HandleIsExtendedUpdatesOptInEligible(const base::Value::List& args);

  // Opens the Extended Updates dialog. |args| must be empty.
  void HandleOpenExtendedUpdatesDialog(const base::Value::List& args);

  // Records metric indicating that the Extended Updates option was shown.
  void HandleRecordExtendedUpdatesShown(const base::Value::List& args);

  // Called when the |kDeviceExtendedAutoUpdateEnabled| setting is changed.
  void OnExtendedUpdatesSettingChanged();

  // Whether the end of life incentive includes an offer.
  bool eol_incentive_shows_offer_ = false;

  // Subscription for changes to the |kDeviceExtendedAutoUpdateEnabled| setting.
  base::CallbackListSubscription extended_updates_setting_change_subscription_;
#endif  // BUILDFLAG(IS_CHROMEOS)

  const raw_ptr<Profile> profile_;

  // Specialized instance of the VersionUpdater used to update the browser.
  std::unique_ptr<VersionUpdater> version_updater_;

  // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy.
  std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_;

  // If true changes to UpgradeObserver are applied, if false they are ignored.
  bool apply_changes_from_upgrade_observer_ = false;

  // Override to test the EOL string displayed in the About details page.
  raw_ptr<base::Clock> clock_;

  // Used for callbacks.
  base::WeakPtrFactory<AboutHandler> weak_factory_{this};
};

}  // namespace settings

#endif  // CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_