File: update_usage_stats_task.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, 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 (102 lines) | stat: -rw-r--r-- 3,735 bytes parent folder | download | duplicates (2)
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
// Copyright 2022 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_UPDATER_UPDATE_USAGE_STATS_TASK_H_
#define CHROME_UPDATER_UPDATE_USAGE_STATS_TASK_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "build/build_config.h"
#include "chrome/updater/updater_scope.h"

#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif

namespace base {
class FilePath;
}

namespace updater {

class PersistedData;

// A UsageStatsProvider evaluates the usage stat state of apps on the system to
// determine whether or not the updater is allowed to send usage stats.
class UsageStatsProvider {
 public:
  virtual ~UsageStatsProvider() = default;

  // Returns true if any app besides Omaha 4 or CECA is allowed to send usage
  // stats. The function looks at apps installed on the system to check if they
  // have usage stats enabled. This information is stored in the registry on
  // Windows, and in a crashpad database found in the `ApplicationSupport`
  // directory on MacOS.
  virtual bool AnyAppEnablesUsageStats() const = 0;

  // Returns true if the updater is allowed to send detailed event logs to an
  // external endpoint. Logging is allowed only if the following conditions are
  // all met:
  //    1) The updater manages an app (an `event_logging_permission_provider`)
  //       responsible for granting the updater permission to send remote
  //       logging events.
  //    2) The `event_logging_permission_provider` app has usage stats enabled.
  //    3) The updater manages no other apps. That is, the apps managed by the
  //    updater are a subset of {Updater, Enterprise Companion App,
  //    event_logging_permission_provider}.
  virtual bool RemoteEventLoggingAllowed() const = 0;

  static std::unique_ptr<UsageStatsProvider> Create(UpdaterScope scope);

 private:
  friend class UpdateUsageStatsTaskTest;

  // Creates a UsageStatsProvider that checks apps in the specified locations
  // (install directories on MacOS and registry paths on Windows), as well as
  // uses the specified app as an event logging permission provider. The app is
  // identified via an appid on Windows and as the name of the application
  // directory on MacOS.
#if BUILDFLAG(IS_WIN)
  static std::unique_ptr<UsageStatsProvider> Create(
      HKEY hive,
      std::optional<std::wstring> event_logging_permission_provider,
      std::vector<std::wstring> registry_paths);
#elif BUILDFLAG(IS_MAC)
  static std::unique_ptr<UsageStatsProvider> Create(
      std::optional<std::string> event_logging_permission_provider,
      std::vector<base::FilePath> app_directories);
#endif
};

class UpdateUsageStatsTask
    : public base::RefCountedThreadSafe<UpdateUsageStatsTask> {
 public:
  UpdateUsageStatsTask(UpdaterScope scope,
                       scoped_refptr<PersistedData> persisted_data);
  void Run(base::OnceClosure callback);

 private:
  friend class base::RefCountedThreadSafe<UpdateUsageStatsTask>;
  FRIEND_TEST_ALL_PREFIXES(UpdateUsageStatsTaskTest, NoApps);
  FRIEND_TEST_ALL_PREFIXES(UpdateUsageStatsTaskTest, OneAppEnabled);
  FRIEND_TEST_ALL_PREFIXES(UpdateUsageStatsTaskTest, ZeroAppsEnabled);
  virtual ~UpdateUsageStatsTask();
  void SetUsageStatsEnabled(scoped_refptr<PersistedData> persisted_data,
                            bool enabled);

  SEQUENCE_CHECKER(sequence_checker_);
  const UpdaterScope scope_;
  scoped_refptr<PersistedData> persisted_data_;
};

}  // namespace updater

#endif  // CHROME_UPDATER_UPDATE_USAGE_STATS_TASK_H_