Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / chromeos / dbus / session_manager_client.h
blob254e762d8e988bbe03de793a0268a2fa70424f33
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "chromeos/dbus/dbus_client_implementation_type.h"
18 namespace chromeos {
20 // SessionManagerClient is used to communicate with the session manager.
21 class CHROMEOS_EXPORT SessionManagerClient : public DBusClient {
22 public:
23 // Interface for observing changes from the session manager.
24 class Observer {
25 public:
26 virtual ~Observer() {}
28 // Called when the owner key is set.
29 virtual void OwnerKeySet(bool success) {}
31 // Called when the property change is complete.
32 virtual void PropertyChangeComplete(bool success) {}
34 // Called when the session manager announces that the screen has been locked
35 // successfully (i.e. after NotifyLockScreenShown() has been called).
36 virtual void ScreenIsLocked() {}
38 // Called when the session manager announces that the screen has been
39 // unlocked successfully (i.e. after NotifyLockScreenDismissed() has
40 // been called).
41 virtual void ScreenIsUnlocked() {}
43 // Called after EmitLoginPromptVisible is called.
44 virtual void EmitLoginPromptVisibleCalled() {}
47 // Interface for performing actions on behalf of the stub implementation.
48 class StubDelegate {
49 public:
50 virtual ~StubDelegate() {}
52 // Locks the screen. Invoked by the stub when RequestLockScreen() is called.
53 // In the real implementation of SessionManagerClient::RequestLockScreen(),
54 // a lock request is forwarded to the session manager; in the stub, this is
55 // short-circuited and the screen is locked immediately.
56 virtual void LockScreenForStub() = 0;
59 // Sets the delegate used by the stub implementation. Ownership of |delegate|
60 // remains with the caller.
61 virtual void SetStubDelegate(StubDelegate* delegate) = 0;
63 // Adds and removes the observer.
64 virtual void AddObserver(Observer* observer) = 0;
65 virtual void RemoveObserver(Observer* observer) = 0;
66 virtual bool HasObserver(const Observer* observer) const = 0;
68 // Returns the most recent screen-lock state received from session_manager.
69 // This mirrors the last Observer::ScreenIsLocked() or ScreenIsUnlocked()
70 // call.
71 virtual bool IsScreenLocked() const = 0;
73 // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
74 virtual void EmitLoginPromptVisible() = 0;
76 // Restarts a job referenced by |pid| with the provided command line.
77 virtual void RestartJob(int pid, const std::string& command_line) = 0;
79 // Starts the session for the user.
80 virtual void StartSession(const std::string& user_email) = 0;
82 // Stops the current session.
83 virtual void StopSession() = 0;
85 // Starts the factory reset.
86 virtual void StartDeviceWipe() = 0;
88 // Locks the screen.
89 virtual void RequestLockScreen() = 0;
91 // Notifies that the lock screen is shown.
92 virtual void NotifyLockScreenShown() = 0;
94 // Notifies that the lock screen is dismissed.
95 virtual void NotifyLockScreenDismissed() = 0;
97 // Notifies that supervised user creation have started.
98 virtual void NotifySupervisedUserCreationStarted() = 0;
100 // Notifies that supervised user creation have finished.
101 virtual void NotifySupervisedUserCreationFinished() = 0;
103 // Map that is used to describe the set of active user sessions where |key|
104 // is user_id and |value| is user_id_hash.
105 typedef std::map<std::string, std::string> ActiveSessionsMap;
107 // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
108 // method. It receives |sessions| argument where the keys are user_ids for
109 // all users that are currently active and |success| argument which indicates
110 // whether or not the request succeded.
111 typedef base::Callback<void(const ActiveSessionsMap& sessions,
112 bool success)> ActiveSessionsCallback;
114 // Enumerates active user sessions. Usually Chrome naturally keeps track of
115 // active users when they are added into current session. When Chrome is
116 // restarted after crash by session_manager it only receives user_id and
117 // user_id_hash for one user. This method is used to retrieve list of all
118 // active users.
119 virtual void RetrieveActiveSessions(
120 const ActiveSessionsCallback& callback) = 0;
122 // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
123 // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
124 // string. Upon success, we will pass a protobuf to the callback. On
125 // failure, we will pass "".
126 typedef base::Callback<void(const std::string&)> RetrievePolicyCallback;
128 // Fetches the device policy blob stored by the session manager. Upon
129 // completion of the retrieve attempt, we will call the provided callback.
130 virtual void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) = 0;
132 // Fetches the user policy blob stored by the session manager for the given
133 // |username|. Upon completion of the retrieve attempt, we will call the
134 // provided callback.
135 virtual void RetrievePolicyForUser(
136 const std::string& username,
137 const RetrievePolicyCallback& callback) = 0;
139 // Same as RetrievePolicyForUser() but blocks until a reply is received, and
140 // returns the policy synchronously. Returns an empty string if the method
141 // call fails.
142 // This may only be called in situations where blocking the UI thread is
143 // considered acceptable (e.g. restarting the browser after a crash or after
144 // a flag change).
145 virtual std::string BlockingRetrievePolicyForUser(
146 const std::string& username) = 0;
148 // Fetches the policy blob associated with the specified device-local account
149 // from session manager. |callback| is invoked up on completion.
150 virtual void RetrieveDeviceLocalAccountPolicy(
151 const std::string& account_id,
152 const RetrievePolicyCallback& callback) = 0;
154 // Used for StoreDevicePolicy, StorePolicyForUser and
155 // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
156 // operation was successful or not.
157 typedef base::Callback<void(bool)> StorePolicyCallback;
159 // Attempts to asynchronously store |policy_blob| as device policy. Upon
160 // completion of the store attempt, we will call callback.
161 virtual void StoreDevicePolicy(const std::string& policy_blob,
162 const StorePolicyCallback& callback) = 0;
164 // Attempts to asynchronously store |policy_blob| as user policy for the given
165 // |username|. Upon completion of the store attempt, we will call callback.
166 virtual void StorePolicyForUser(const std::string& username,
167 const std::string& policy_blob,
168 const StorePolicyCallback& callback) = 0;
170 // Sends a request to store a policy blob for the specified device-local
171 // account. The result of the operation is reported through |callback|.
172 virtual void StoreDeviceLocalAccountPolicy(
173 const std::string& account_id,
174 const std::string& policy_blob,
175 const StorePolicyCallback& callback) = 0;
177 // Sets the flags to be applied next time by the session manager when Chrome
178 // is restarted inside an already started session for a particular user.
179 virtual void SetFlagsForUser(const std::string& username,
180 const std::vector<std::string>& flags) = 0;
182 typedef base::Callback<void(const std::vector<std::string>& state_keys)>
183 StateKeysCallback;
185 // Get the currently valid server-backed state keys for the device.
186 // Server-backed state keys are opaque, device-unique, time-dependent,
187 // client-determined identifiers that are used for keying state in the cloud
188 // for the device to retrieve after a device factory reset.
190 // The state keys are returned asynchronously via |callback|. The callback
191 // will be invoked with an empty state key vector in case of errors.
192 virtual void GetServerBackedStateKeys(const StateKeysCallback& callback) = 0;
194 // Creates the instance.
195 static SessionManagerClient* Create(DBusClientImplementationType type);
197 ~SessionManagerClient() override;
199 protected:
200 // Create() should be used instead.
201 SessionManagerClient();
203 private:
204 DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
207 } // namespace chromeos
209 #endif // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_