File: event_based_status_reporting_service.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 (100 lines) | stat: -rw-r--r-- 3,421 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
91
92
93
94
95
96
97
98
99
100
// Copyright 2019 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_ASH_CHILD_ACCOUNTS_EVENT_BASED_STATUS_REPORTING_SERVICE_H_
#define CHROME_BROWSER_ASH_CHILD_ACCOUNTS_EVENT_BASED_STATUS_REPORTING_SERVICE_H_

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/ash/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ash/child_accounts/screen_time_controller.h"
#include "chromeos/dbus/power/power_manager_client.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "services/network/public/cpp/network_connection_tracker.h"

namespace content {
class BrowserContext;
}  // namespace content

namespace ash {

// Requests status report when events relevant to supervision features happen.
// The events that are triggers to status report are:
//     * App install
//     * App update
//     * Device lock
//     * Device unlock
//     * Device connected
//     * Device returns from suspend mode
//     * Device is about to lock by usage time limit
class EventBasedStatusReportingService
    : public KeyedService,
      public ArcAppListPrefs::Observer,
      public session_manager::SessionManagerObserver,
      public network::NetworkConnectionTracker::NetworkConnectionObserver,
      public chromeos::PowerManagerClient::Observer,
      public ScreenTimeController::Observer {
 public:
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum class StatusReportEvent {
    kAppInstalled = 0,
    kAppUpdated = 1,
    kSessionActive = 2,
    kSessionLocked = 3,
    kDeviceOnline = 4,
    kSuspendDone = 5,
    kUsageTimeLimitWarning = 6,
    kMaxValue = kUsageTimeLimitWarning,
  };

  // Histogram to log events that triggered status report.
  static constexpr char kUMAStatusReportEvent[] =
      "Supervision.StatusReport.Event";

  explicit EventBasedStatusReportingService(content::BrowserContext* context);

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

  ~EventBasedStatusReportingService() override;

  // ArcAppListPrefs::Observer:
  void OnPackageInstalled(
      const arc::mojom::ArcPackageInfo& package_info) override;
  void OnPackageModified(
      const arc::mojom::ArcPackageInfo& package_info) override;

  // session_manager::SessionManagerObserver:
  void OnSessionStateChanged() override;

  // network::NetworkConnectionTracker::NetworkConnectionObserver:
  void OnConnectionChanged(network::mojom::ConnectionType type) override;

  // PowerManagerClient::Observer:
  void SuspendDone(base::TimeDelta duration) override;

  // ScreenTimeController::Observer:
  void UsageTimeLimitWarning() override;

 private:
  friend class EventBasedStatusReportingServiceTest;

  void RequestStatusReport(StatusReportEvent event);

  void LogStatusReportEventUMA(StatusReportEvent event);

  // KeyedService:
  void Shutdown() override;

  const raw_ptr<content::BrowserContext, DanglingUntriaged> context_;
  bool session_just_started_ = true;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_CHILD_ACCOUNTS_EVENT_BASED_STATUS_REPORTING_SERVICE_H_