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_
11 #include "base/callback.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_client.h"
15 #include "chromeos/dbus/dbus_client_implementation_type.h"
19 // SessionManagerClient is used to communicate with the session manager.
20 class CHROMEOS_EXPORT SessionManagerClient : public DBusClient {
22 // Interface for observing changes from the session manager.
25 virtual ~Observer() {}
27 // Called when the owner key is set.
28 virtual void OwnerKeySet(bool success) {}
30 // Called when the property change is complete.
31 virtual void PropertyChangeComplete(bool success) {}
33 // Called when the session manager announces that the screen has been locked
34 // successfully (i.e. after NotifyLockScreenShown() has been called).
35 virtual void ScreenIsLocked() {}
37 // Called when the session manager announces that the screen has been
38 // unlocked successfully (i.e. after NotifyLockScreenDismissed() has
40 virtual void ScreenIsUnlocked() {}
42 // Called after EmitLoginPromptVisible is called.
43 virtual void EmitLoginPromptVisibleCalled() {}
46 // Interface for performing actions on behalf of the stub implementation.
49 virtual ~StubDelegate() {}
51 // Locks the screen. Invoked by the stub when RequestLockScreen() is called.
52 // In the real implementation of SessionManagerClient::RequestLockScreen(),
53 // a lock request is forwarded to the session manager; in the stub, this is
54 // short-circuited and the screen is locked immediately.
55 virtual void LockScreenForStub() = 0;
58 // Sets the delegate used by the stub implementation. Ownership of |delegate|
59 // remains with the caller.
60 virtual void SetStubDelegate(StubDelegate* delegate) = 0;
62 // Adds and removes the observer.
63 virtual void AddObserver(Observer* observer) = 0;
64 virtual void RemoveObserver(Observer* observer) = 0;
65 virtual bool HasObserver(Observer* observer) = 0;
67 // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
68 virtual void EmitLoginPromptVisible() = 0;
70 // Restarts a job referenced by |pid| with the provided command line.
71 virtual void RestartJob(int pid, const std::string& command_line) = 0;
73 // Starts the session for the user.
74 virtual void StartSession(const std::string& user_email) = 0;
76 // Stops the current session.
77 virtual void StopSession() = 0;
79 // Starts the factory reset.
80 virtual void StartDeviceWipe() = 0;
83 virtual void RequestLockScreen() = 0;
85 // Notifies that the lock screen is shown.
86 virtual void NotifyLockScreenShown() = 0;
88 // Notifies that the lock screen is dismissed.
89 virtual void NotifyLockScreenDismissed() = 0;
91 // Map that is used to describe the set of active user sessions where |key|
92 // is user_id and |value| is user_id_hash.
93 typedef std::map<std::string, std::string> ActiveSessionsMap;
95 // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
96 // method. It receives |sessions| argument where the keys are user_ids for
97 // all users that are currently active and |success| argument which indicates
98 // whether or not the request succeded.
99 typedef base::Callback<void(const ActiveSessionsMap& sessions,
100 bool success)> ActiveSessionsCallback;
102 // Enumerates active user sessions. Usually Chrome naturally keeps track of
103 // active users when they are added into current session. When Chrome is
104 // restarted after crash by session_manager it only receives user_id and
105 // user_id_hash for one user. This method is used to retrieve list of all
107 virtual void RetrieveActiveSessions(
108 const ActiveSessionsCallback& callback) = 0;
110 // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
111 // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
112 // string. Upon success, we will pass a protobuf to the callback. On
113 // failure, we will pass "".
114 typedef base::Callback<void(const std::string&)> RetrievePolicyCallback;
116 // Fetches the device policy blob stored by the session manager. Upon
117 // completion of the retrieve attempt, we will call the provided callback.
118 virtual void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) = 0;
120 // Fetches the user policy blob stored by the session manager for the given
121 // |username|. Upon completion of the retrieve attempt, we will call the
122 // provided callback.
123 virtual void RetrievePolicyForUser(
124 const std::string& username,
125 const RetrievePolicyCallback& callback) = 0;
127 // Same as RetrievePolicyForUser() but blocks until a reply is received, and
128 // returns the policy synchronously. Returns an empty string if the method
130 // This may only be called in situations where blocking the UI thread is
131 // considered acceptable (e.g. restarting the browser after a crash or after
133 virtual std::string BlockingRetrievePolicyForUser(
134 const std::string& username) = 0;
136 // Fetches the policy blob associated with the specified device-local account
137 // from session manager. |callback| is invoked up on completion.
138 virtual void RetrieveDeviceLocalAccountPolicy(
139 const std::string& account_id,
140 const RetrievePolicyCallback& callback) = 0;
142 // Used for StoreDevicePolicy, StorePolicyForUser and
143 // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
144 // operation was successful or not.
145 typedef base::Callback<void(bool)> StorePolicyCallback;
147 // Attempts to asynchronously store |policy_blob| as device policy. Upon
148 // completion of the store attempt, we will call callback.
149 virtual void StoreDevicePolicy(const std::string& policy_blob,
150 const StorePolicyCallback& callback) = 0;
152 // Attempts to asynchronously store |policy_blob| as user policy for the given
153 // |username|. Upon completion of the store attempt, we will call callback.
154 // The |policy_key| argument is not sent to the session manager, but is used
155 // by the stub implementation to enable policy validation on desktop builds.
156 virtual void StorePolicyForUser(const std::string& username,
157 const std::string& policy_blob,
158 const std::string& policy_key,
159 const StorePolicyCallback& callback) = 0;
161 // Sends a request to store a policy blob for the specified device-local
162 // account. The result of the operation is reported through |callback|.
163 virtual void StoreDeviceLocalAccountPolicy(
164 const std::string& account_id,
165 const std::string& policy_blob,
166 const StorePolicyCallback& callback) = 0;
168 // Sets the flags to be applied next time by the session manager when Chrome
169 // is restarted inside an already started session for a particular user.
170 virtual void SetFlagsForUser(const std::string& username,
171 const std::vector<std::string>& flags) = 0;
173 // Creates the instance.
174 static SessionManagerClient* Create(DBusClientImplementationType type);
176 virtual ~SessionManagerClient();
179 // Create() should be used instead.
180 SessionManagerClient();
183 DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
186 } // namespace chromeos
188 #endif // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_