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_
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"
20 // SessionManagerClient is used to communicate with the session manager.
21 class CHROMEOS_EXPORT SessionManagerClient
: public DBusClient
{
23 // Interface for observing changes from the session manager.
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
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.
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 // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
69 virtual void EmitLoginPromptVisible() = 0;
71 // Restarts a job referenced by |pid| with the provided command line.
72 virtual void RestartJob(int pid
, const std::string
& command_line
) = 0;
74 // Starts the session for the user.
75 virtual void StartSession(const std::string
& user_email
) = 0;
77 // Stops the current session.
78 virtual void StopSession() = 0;
80 // Starts the factory reset.
81 virtual void StartDeviceWipe() = 0;
84 virtual void RequestLockScreen() = 0;
86 // Notifies that the lock screen is shown.
87 virtual void NotifyLockScreenShown() = 0;
89 // Notifies that the lock screen is dismissed.
90 virtual void NotifyLockScreenDismissed() = 0;
92 // Notifies that supervised user creation have started.
93 virtual void NotifySupervisedUserCreationStarted() = 0;
95 // Notifies that supervised user creation have finished.
96 virtual void NotifySupervisedUserCreationFinished() = 0;
98 // Map that is used to describe the set of active user sessions where |key|
99 // is user_id and |value| is user_id_hash.
100 typedef std::map
<std::string
, std::string
> ActiveSessionsMap
;
102 // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
103 // method. It receives |sessions| argument where the keys are user_ids for
104 // all users that are currently active and |success| argument which indicates
105 // whether or not the request succeded.
106 typedef base::Callback
<void(const ActiveSessionsMap
& sessions
,
107 bool success
)> ActiveSessionsCallback
;
109 // Enumerates active user sessions. Usually Chrome naturally keeps track of
110 // active users when they are added into current session. When Chrome is
111 // restarted after crash by session_manager it only receives user_id and
112 // user_id_hash for one user. This method is used to retrieve list of all
114 virtual void RetrieveActiveSessions(
115 const ActiveSessionsCallback
& callback
) = 0;
117 // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
118 // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
119 // string. Upon success, we will pass a protobuf to the callback. On
120 // failure, we will pass "".
121 typedef base::Callback
<void(const std::string
&)> RetrievePolicyCallback
;
123 // Fetches the device policy blob stored by the session manager. Upon
124 // completion of the retrieve attempt, we will call the provided callback.
125 virtual void RetrieveDevicePolicy(const RetrievePolicyCallback
& callback
) = 0;
127 // Fetches the user policy blob stored by the session manager for the given
128 // |username|. Upon completion of the retrieve attempt, we will call the
129 // provided callback.
130 virtual void RetrievePolicyForUser(
131 const std::string
& username
,
132 const RetrievePolicyCallback
& callback
) = 0;
134 // Same as RetrievePolicyForUser() but blocks until a reply is received, and
135 // returns the policy synchronously. Returns an empty string if the method
137 // This may only be called in situations where blocking the UI thread is
138 // considered acceptable (e.g. restarting the browser after a crash or after
140 virtual std::string
BlockingRetrievePolicyForUser(
141 const std::string
& username
) = 0;
143 // Fetches the policy blob associated with the specified device-local account
144 // from session manager. |callback| is invoked up on completion.
145 virtual void RetrieveDeviceLocalAccountPolicy(
146 const std::string
& account_id
,
147 const RetrievePolicyCallback
& callback
) = 0;
149 // Used for StoreDevicePolicy, StorePolicyForUser and
150 // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
151 // operation was successful or not.
152 typedef base::Callback
<void(bool)> StorePolicyCallback
;
154 // Attempts to asynchronously store |policy_blob| as device policy. Upon
155 // completion of the store attempt, we will call callback.
156 virtual void StoreDevicePolicy(const std::string
& policy_blob
,
157 const StorePolicyCallback
& callback
) = 0;
159 // Attempts to asynchronously store |policy_blob| as user policy for the given
160 // |username|. Upon completion of the store attempt, we will call callback.
161 virtual void StorePolicyForUser(const std::string
& username
,
162 const std::string
& policy_blob
,
163 const StorePolicyCallback
& callback
) = 0;
165 // Sends a request to store a policy blob for the specified device-local
166 // account. The result of the operation is reported through |callback|.
167 virtual void StoreDeviceLocalAccountPolicy(
168 const std::string
& account_id
,
169 const std::string
& policy_blob
,
170 const StorePolicyCallback
& callback
) = 0;
172 // Sets the flags to be applied next time by the session manager when Chrome
173 // is restarted inside an already started session for a particular user.
174 virtual void SetFlagsForUser(const std::string
& username
,
175 const std::vector
<std::string
>& flags
) = 0;
177 typedef base::Callback
<void(const std::vector
<std::string
>& state_keys
)>
180 // Get the currently valid server-backed state keys for the device.
181 // Server-backed state keys are opaque, device-unique, time-dependent,
182 // client-determined identifiers that are used for keying state in the cloud
183 // for the device to retrieve after a device factory reset.
185 // The state keys are returned asynchronously via |callback|. The callback
186 // will be invoked with an empty state key vector in case of errors.
187 virtual void GetServerBackedStateKeys(const StateKeysCallback
& callback
) = 0;
189 // Creates the instance.
190 static SessionManagerClient
* Create(DBusClientImplementationType type
);
192 virtual ~SessionManagerClient();
195 // Create() should be used instead.
196 SessionManagerClient();
199 DISALLOW_COPY_AND_ASSIGN(SessionManagerClient
);
202 } // namespace chromeos
204 #endif // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_