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 // Called when the owner key is set.
26 virtual void OwnerKeySet(bool success) {}
28 // Called when the property change is complete.
29 virtual void PropertyChangeComplete(bool success) {}
31 // Called when the session manager requests that the lock screen be
32 // displayed. NotifyLockScreenShown() is called after the lock screen
33 // is shown (the canonical "is the screen locked?" state lives in the
35 // TODO(derat): Delete this once the session manager is calling the
36 // "LockScreen" method instead.
37 virtual void LockScreen() {}
39 // Called when the session manager announces that the screen has been locked
40 // successfully (i.e. after NotifyLockScreenShown() has been called).
41 virtual void ScreenIsLocked() {}
43 // Called when the session manager announces that the screen has been
44 // unlocked successfully (i.e. after NotifyLockScreenDismissed() has
46 virtual void ScreenIsUnlocked() {}
48 // Called after EmitLoginPromptVisible is called.
49 virtual void EmitLoginPromptVisibleCalled() {}
52 // Adds and removes the observer.
53 virtual void AddObserver(Observer* observer) = 0;
54 virtual void RemoveObserver(Observer* observer) = 0;
55 virtual bool HasObserver(Observer* observer) = 0;
57 // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
58 virtual void EmitLoginPromptVisible() = 0;
60 // Restarts a job referenced by |pid| with the provided command line.
61 virtual void RestartJob(int pid, const std::string& command_line) = 0;
63 // Starts the session for the user.
64 virtual void StartSession(const std::string& user_email) = 0;
66 // Stops the current session.
67 virtual void StopSession() = 0;
69 // Starts the factory reset.
70 virtual void StartDeviceWipe() = 0;
73 virtual void RequestLockScreen() = 0;
75 // Notifies that the lock screen is shown.
76 virtual void NotifyLockScreenShown() = 0;
78 // Notifies that the lock screen is dismissed.
79 virtual void NotifyLockScreenDismissed() = 0;
81 // Map that is used to describe the set of active user sessions where |key|
82 // is user_id and |value| is user_id_hash.
83 typedef std::map<std::string, std::string> ActiveSessionsMap;
85 // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
86 // method. It receives |sessions| argument where the keys are user_ids for
87 // all users that are currently active and |success| argument which indicates
88 // whether or not the request succeded.
89 typedef base::Callback<void(const ActiveSessionsMap& sessions,
90 bool success)> ActiveSessionsCallback;
92 // Enumerates active user sessions. Usually Chrome naturally keeps track of
93 // active users when they are added into current session. When Chrome is
94 // restarted after crash by session_manager it only receives user_id and
95 // user_id_hash for one user. This method is used to retrieve list of all
97 virtual void RetrieveActiveSessions(
98 const ActiveSessionsCallback& callback) = 0;
100 // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
101 // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
102 // string. Upon success, we will pass a protobuf to the callback. On
103 // failure, we will pass "".
104 typedef base::Callback<void(const std::string&)> RetrievePolicyCallback;
106 // Fetches the device policy blob stored by the session manager. Upon
107 // completion of the retrieve attempt, we will call the provided callback.
108 virtual void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) = 0;
110 // Fetches the user policy blob stored by the session manager for the given
111 // |username|. Upon completion of the retrieve attempt, we will call the
112 // provided callback.
113 virtual void RetrievePolicyForUser(
114 const std::string& username,
115 const RetrievePolicyCallback& callback) = 0;
117 // Same as RetrievePolicyForUser() but blocks until a reply is received, and
118 // returns the policy synchronously. Returns an empty string if the method
120 // This may only be called in situations where blocking the UI thread is
121 // considered acceptable (e.g. restarting the browser after a crash or after
123 virtual std::string BlockingRetrievePolicyForUser(
124 const std::string& username) = 0;
126 // Fetches the policy blob associated with the specified device-local account
127 // from session manager. |callback| is invoked up on completion.
128 virtual void RetrieveDeviceLocalAccountPolicy(
129 const std::string& account_id,
130 const RetrievePolicyCallback& callback) = 0;
132 // Used for StoreDevicePolicy, StorePolicyForUser and
133 // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
134 // operation was successful or not.
135 typedef base::Callback<void(bool)> StorePolicyCallback;
137 // Attempts to asynchronously store |policy_blob| as device policy. Upon
138 // completion of the store attempt, we will call callback.
139 virtual void StoreDevicePolicy(const std::string& policy_blob,
140 const StorePolicyCallback& callback) = 0;
142 // Attempts to asynchronously store |policy_blob| as user policy for the given
143 // |username|. Upon completion of the store attempt, we will call callback.
144 // The |policy_key| argument is not sent to the session manager, but is used
145 // by the stub implementation to enable policy validation on desktop builds.
146 virtual void StorePolicyForUser(const std::string& username,
147 const std::string& policy_blob,
148 const std::string& policy_key,
149 const StorePolicyCallback& callback) = 0;
151 // Sends a request to store a policy blob for the specified device-local
152 // account. The result of the operation is reported through |callback|.
153 virtual void StoreDeviceLocalAccountPolicy(
154 const std::string& account_id,
155 const std::string& policy_blob,
156 const StorePolicyCallback& callback) = 0;
158 // Sets the flags to be applied next time by the session manager when Chrome
159 // is restarted inside an already started session for a particular user.
160 virtual void SetFlagsForUser(const std::string& username,
161 const std::vector<std::string>& flags) = 0;
163 // Creates the instance.
164 static SessionManagerClient* Create(DBusClientImplementationType type);
166 virtual ~SessionManagerClient();
169 // Create() should be used instead.
170 SessionManagerClient();
173 DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
176 } // namespace chromeos
178 #endif // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_