File: browser_updater_client.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 5,066 bytes parent folder | download | duplicates (4)
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
// 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_UPDATER_BROWSER_UPDATER_CLIENT_H_
#define CHROME_BROWSER_UPDATER_BROWSER_UPDATER_CLIENT_H_

#include <optional>
#include <string>

#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/updater/registration_data.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/updater_scope.h"

namespace base {
class Version;
class FilePath;
}

// Cross-platform client to communicate between the browser and the Chromium
// updater. It helps the browser register to the Chromium updater and invokes
// on-demand updates.
class BrowserUpdaterClient
    : public base::RefCountedThreadSafe<BrowserUpdaterClient> {
 public:
  // Must be called on the program's main sequence.
  static scoped_refptr<BrowserUpdaterClient> Create(
      updater::UpdaterScope scope);
  static scoped_refptr<BrowserUpdaterClient> Create(
      base::RepeatingCallback<scoped_refptr<updater::UpdateService>()>
          proxy_provider,
      updater::UpdaterScope scope);
  static std::optional<updater::UpdateService::UpdateState>
  GetLastOnDemandUpdateState();
  static std::optional<updater::UpdateService::AppState>
  GetLastKnownBrowserRegistration();
  static std::optional<updater::UpdateService::AppState>
  GetLastKnownUpdaterRegistration();

  explicit BrowserUpdaterClient(
      scoped_refptr<updater::UpdateService> update_service);

  // Registers the browser to the Chromium updater via IPC registration API.
  // When registration is completed, it will call RegistrationCompleted().
  // A ref to this object is held until the registration completes. Must be
  // called on the sequence on which the BrowserUpdateClient was created.
  // `complete` will be called after registration on the same sequence.
  void Register(base::OnceClosure complete);

  // Triggers an on-demand update from the Chromium updater, reporting status
  // updates to the callback. A ref to this object is held until the update
  // completes. Must be called on the sequence on which the BrowserUpdateClient
  // was created. `version_updater_callback` will be run on the same sequence.
  void CheckForUpdate(
      base::RepeatingCallback<void(const updater::UpdateService::UpdateState&)>
          version_updater_callback);

  // Launches the updater to run its periodic background tasks. This is a
  // mechanism to act as a backup periodic scheduler for the updater.
  void RunPeriodicTasks(base::OnceClosure callback);

  // Gets the current updater version. Can also be used to check for the
  // existence of the updater. A ref to the BrowserUpdaterClient is held until
  // the callback is invoked. Must be called on the sequence on which the
  // BrowserUpdateClient was created. `callback` will be run on the same
  // sequence.
  void GetUpdaterVersion(
      base::OnceCallback<void(const base::Version&)> callback);

  // Returns whether the browser is registered with the updater. A ref to the
  // BrowserUpdaterClient is held until the callback is invoked. Must be called
  // on the sequence on which the BrowserUpdaterClient was created. `callback`
  // will be run on the same sequence.
  void IsBrowserRegistered(base::OnceCallback<void(bool)> callback);

  // Returns the browser's app ID. App IDs are case-insensitive and it may not
  // be in the same case used elsewhere in the browser.
  static std::string GetAppId();

  // Returns the expected existence checker path for this browser instance.
  static base::FilePath GetExpectedEcp();

 protected:
  friend class base::RefCountedThreadSafe<BrowserUpdaterClient>;
  virtual ~BrowserUpdaterClient();

 private:
  SEQUENCE_CHECKER(sequence_checker_);
  static bool AppMatches(const updater::UpdateService::AppState& app);
  updater::RegistrationRequest GetRegistrationRequest();

  void RegistrationCompleted(base::OnceClosure complete, int result);
  void GetUpdaterVersionCompleted(
      base::OnceCallback<void(const base::Version&)> callback,
      const base::Version& version);
  void UpdateCompleted(
      base::RepeatingCallback<void(const updater::UpdateService::UpdateState&)>
          callback,
      updater::UpdateService::Result result);
  void RunPeriodicTasksCompleted(base::OnceClosure callback);
  void IsBrowserRegisteredCompleted(
      base::OnceCallback<void(bool)> callback,
      const std::vector<updater::UpdateService::AppState>& apps);

  template <updater::UpdaterScope scope>
  static scoped_refptr<BrowserUpdaterClient> GetClient(
      base::RepeatingCallback<scoped_refptr<updater::UpdateService>()>
          proxy_provider);

  scoped_refptr<updater::UpdateService> update_service_;
  base::WeakPtrFactory<BrowserUpdaterClient> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_UPDATER_BROWSER_UPDATER_CLIENT_H_