File: system_proxy_client.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; 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 (122 lines) | stat: -rw-r--r-- 5,265 bytes parent folder | download | duplicates (7)
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
121
122
// 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 CHROMEOS_ASH_COMPONENTS_DBUS_SYSTEM_PROXY_SYSTEM_PROXY_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_SYSTEM_PROXY_SYSTEM_PROXY_CLIENT_H_

#include "base/component_export.h"
#include "base/functional/callback.h"
#include "chromeos/ash/components/dbus/system_proxy/system_proxy_service.pb.h"
#include "dbus/object_proxy.h"

namespace dbus {
class Bus;
}

namespace ash {

// SystemProxyClient is used to communicate with the org.chromium.SystemProxy
// service. All method should be called from the origin thread (UI thread) which
// initializes the DBusThreadManager instance.
class COMPONENT_EXPORT(SYSTEM_PROXY) SystemProxyClient {
 public:
  using SetAuthenticationDetailsCallback = base::OnceCallback<void(
      const system_proxy::SetAuthenticationDetailsResponse& response)>;
  using WorkerActiveCallback = base::RepeatingCallback<void(
      const system_proxy::WorkerActiveSignalDetails& details)>;
  using AuthenticationRequiredCallback = base::RepeatingCallback<void(
      const system_proxy::AuthenticationRequiredDetails& details)>;
  using ClearUserCredentialsCallback = base::OnceCallback<void(
      const system_proxy::ClearUserCredentialsResponse& response)>;
  using ShutDownProcessCallback =
      base::OnceCallback<void(const system_proxy::ShutDownResponse& response)>;

  // Interface with testing functionality. Accessed through GetTestInterface(),
  // only implemented in the fake implementation.
  class TestInterface {
   public:
    // Returns how many times |SetAuthenticationDetails| was called.
    virtual int GetSetAuthenticationDetailsCallCount() const = 0;
    // Returns how many times |ShutDownProcess| was called.
    virtual int GetShutDownCallCount() const = 0;
    // Returns how many times |ClearUserCredentials| was called.
    virtual int GetClearUserCredentialsCount() const = 0;
    // Returns the content of the last request sent to the System-proxy service
    // to set authentication details.
    virtual system_proxy::SetAuthenticationDetailsRequest
    GetLastAuthenticationDetailsRequest() const = 0;
    // Simulates the |AuthenticationRequired| signal by calling the callback set
    // by |SetAuthenticationRequiredSignalCallback|. The callback is called only
    // if |FakeSystemProxyClient| was set up to listen for signals by calling
    // |ConnectToWorkerSignals|.
    virtual void SendAuthenticationRequiredSignal(
        const system_proxy::AuthenticationRequiredDetails& details) = 0;
    // Simulates the |WorkerActiveSignal| signal by calling the callback set
    // by |SetWorkerActiveSignalCallback|.
    virtual void SendWorkerActiveSignal(
        const system_proxy::WorkerActiveSignalDetails& details) = 0;

   protected:
    virtual ~TestInterface() {}
  };

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

  // Creates and initializes the global instance. |bus| must not be null.
  static void Initialize(dbus::Bus* bus);

  // Creates and initializes a fake global instance if not already created.
  static void InitializeFake();

  // Destroys the global instance.
  static void Shutdown();

  // Returns the global instance which may be null if not initialized.
  static SystemProxyClient* Get();

  // SystemProxy daemon D-Bus method calls. See org.chromium.SystemProxy.xml and
  // system_proxy_service.proto in Chromium OS code for the documentation of the
  // methods and request/response messages.
  virtual void SetAuthenticationDetails(
      const system_proxy::SetAuthenticationDetailsRequest& request,
      SetAuthenticationDetailsCallback callback) = 0;

  virtual void ClearUserCredentials(
      const system_proxy::ClearUserCredentialsRequest& request,
      ClearUserCredentialsCallback callback) = 0;

  // When receiving a shut down call, System-proxy will schedule a shut down
  // task and reply. |callback| is called when the daemon or one of the
  // processes starts to shut down.
  virtual void ShutDownProcess(const system_proxy::ShutDownRequest& request,
                               ShutDownProcessCallback callback) = 0;

  // Returns an interface for testing (fake only), or returns nullptr.
  virtual TestInterface* GetTestInterface() = 0;

  // Sets the callback to be called when System-proxy emits the
  // |WorkerActiveSignal| signal.
  virtual void SetWorkerActiveSignalCallback(WorkerActiveCallback callback) = 0;

  // Sets the callback to be called when System-proxy emits the
  // |AuthenticationRequired| signal.
  virtual void SetAuthenticationRequiredSignalCallback(
      AuthenticationRequiredCallback callback) = 0;

  // Waits for the System-proxy d-bus service to be available and then connects
  // to the signals for which a callback has been set with
  // |SetWorkerActiveSignalCallback| and
  // |SetAuthenticationRequiredSignalCallback|.
  virtual void ConnectToWorkerSignals() = 0;

 protected:
  // Initialize/Shutdown should be used instead.
  SystemProxyClient();
  virtual ~SystemProxyClient();
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_DBUS_SYSTEM_PROXY_SYSTEM_PROXY_CLIENT_H_