File: build_state.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 (90 lines) | stat: -rw-r--r-- 3,327 bytes parent folder | download | duplicates (6)
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
// Copyright 2020 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_BUILD_STATE_H_
#define CHROME_BROWSER_UPGRADE_DETECTOR_BUILD_STATE_H_

#include <optional>

#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "base/version.h"

class BuildStateObserver;

// The state of the browser or device build. This class is not thread safe --
// all access must take place on the UI thread.
class BuildState {
 public:
  // Logged as BuildStateUpdateType. Do not reorder or remove entries.
  enum class UpdateType {
    // No new version ready for use.
    kNone = 0,

    // A bump from the running version to a newer one (i.e., a typical update).
    kNormalUpdate = 1,

    // Rollback to an older version via administrative action.
    kEnterpriseRollback = 2,

    // Rollback to an older version via a switch to a more stable channel.
    // (Chrome OS only.)
    kChannelSwitchRollback = 3,

    // Needed for UMA - can be removed if BuildStateUpdateType is removed.
    kMaxValue = kChannelSwitchRollback,
  };

  BuildState();
  BuildState(const BuildState&) = delete;
  BuildState& operator=(const BuildState&) = delete;
  ~BuildState();

  // Returns the current update type if an update has been detected, or kNone if
  // one has not been detected. In the latter case, neither installed_version()
  // nor critical_version() is relevant.
  UpdateType update_type() const {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    return update_type_;
  }

  // If update_type() is not kNone, returns the discovered version or no value
  // if an error occurred while determining the installed version. A returned
  // value may be numerically higher or lower than the currently running build.
  // Note: On Chrome OS, this is the system version number rather than the
  // browser version number.
  const std::optional<base::Version>& installed_version() const {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    return installed_version_;
  }

  // If update_type() is not kNone, returns the optional critical version,
  // indicating a minimum version that must be running. A running version lower
  // than this must be updated as soon as possible. (Windows only.)
  const std::optional<base::Version>& critical_version() const {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    return critical_version_;
  }

  // Sets the update properties. Observers are notified if the given properties
  // differ from the instance's previous properties.
  void SetUpdate(UpdateType update_type,
                 const base::Version& installed_version,
                 const std::optional<base::Version>& critical_version);

  void AddObserver(BuildStateObserver* observer);
  void RemoveObserver(const BuildStateObserver* observer);
  bool HasObserver(const BuildStateObserver* observer) const;

 private:
  void NotifyObserversOnUpdate();

  SEQUENCE_CHECKER(sequence_checker_);
  base::ObserverList<BuildStateObserver, /*check_empty=*/true> observers_;
  UpdateType update_type_ = UpdateType::kNone;
  std::optional<base::Version> installed_version_;
  std::optional<base::Version> critical_version_;
};

#endif  // CHROME_BROWSER_UPGRADE_DETECTOR_BUILD_STATE_H_