File: upgrade_detector_chromeos.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 (112 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download | duplicates (5)
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
// Copyright 2012 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_UPGRADE_DETECTOR_UPGRADE_DETECTOR_CHROMEOS_H_
#define CHROME_BROWSER_UPGRADE_DETECTOR_UPGRADE_DETECTOR_CHROMEOS_H_

#include "base/no_destructor.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/upgrade_detector/build_state_observer.h"
#include "chrome/browser/upgrade_detector/installed_version_updater_chromeos.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "chromeos/ash/components/dbus/update_engine/update_engine_client.h"

class PrefRegistrySimple;
namespace base {
class Clock;
class TickClock;
}  // namespace base

class UpgradeDetectorChromeos : public UpgradeDetector,
                                public BuildStateObserver,
                                public ash::UpdateEngineClient::Observer {
 public:
  UpgradeDetectorChromeos(const UpgradeDetectorChromeos&) = delete;
  UpgradeDetectorChromeos& operator=(const UpgradeDetectorChromeos&) = delete;

  ~UpgradeDetectorChromeos() override;

  // Register ChromeOS specific Prefs.
  static void RegisterPrefs(PrefRegistrySimple* registry);

  static UpgradeDetectorChromeos* GetInstance();

  // UpgradeDetector:
  void Init() override;
  void Shutdown() override;
  base::Time GetAnnoyanceLevelDeadline(
      UpgradeNotificationAnnoyanceLevel level) override;
  void OverrideHighAnnoyanceDeadline(base::Time deadline) override;
  void ResetOverriddenDeadline() override;

  // BuildStateObserver:
  void OnUpdate(const BuildState* build_state) override;

 protected:
  UpgradeDetectorChromeos(const base::Clock* clock,
                          const base::TickClock* tick_clock);

 private:
  friend class base::NoDestructor<UpgradeDetectorChromeos>;

  // Returns the period between first notification and Recommended / Required
  // deadline specified via the RelaunchHeadsUpPeriod policy setting, or a
  // zero delta if unset or out of range.
  static base::TimeDelta GetRelaunchHeadsUpPeriod();

  // Calculates |elevated_deadline_| and |high_deadline_| using either
  // |high_deadline_override_| if it is not null or the threshold values
  // computed based on the RelaunchNotificationPeriod, RelaunchHeadsUpPeriod and
  // RelaunchWindow policy settings.
  void CalculateDeadlines();

  // UpgradeDetector:
  void RecomputeSchedule() override;

  // ash::UpdateEngineClient::Observer implementation.
  void UpdateStatusChanged(const update_engine::StatusResult& status) override;
  void OnUpdateOverCellularOneTimePermissionGranted() override;

  // The function that sends out a notification (after a certain time has
  // elapsed) that lets the rest of the UI know we should start notifying the
  // user that a new version is available.
  void NotifyOnUpgrade();

  // The function that sends out a notification (after a certain time has
  // elapsed) that lets the rest of the UI know we should start notifying the
  // user that an update is available but deferred.
  void NotifyOnDeferredUpgrade();

  std::optional<InstalledVersionUpdater> installed_version_updater_;

  // The time when elevated annoyance deadline is reached.
  base::Time elevated_deadline_;

  // The time when high annoyance deadline is reached.
  base::Time high_deadline_;

  // The time when grace annoyance deadline is reached.
  base::Time grace_deadline_;

  // The overridden high annoyance deadline which takes priority over
  // |high_deadline_| for showing relaunch notifications.
  base::Time high_deadline_override_;

  // Observes changes to the browser.relaunch_heads_up_period Local State
  // preference.
  PrefChangeRegistrar pref_change_registrar_;

  // A timer used to move through the various upgrade notification stages and
  // call UpgradeDetector::NotifyUpgrade.
  base::OneShotTimer upgrade_notification_timer_;
  bool initialized_;

  // Indicates whether there is an update in progress.
  bool update_in_progress_;

  base::WeakPtrFactory<UpgradeDetectorChromeos> weak_factory_{this};
};

#endif  // CHROME_BROWSER_UPGRADE_DETECTOR_UPGRADE_DETECTOR_CHROMEOS_H_