Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / session_manager_client.h
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.
4
5 #ifndef CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
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"
17
18 namespace chromeos {
19
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() {}
27
28     // Called when the owner key is set.
29     virtual void OwnerKeySet(bool success) {}
30
31     // Called when the property change is complete.
32     virtual void PropertyChangeComplete(bool success) {}
33
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() {}
37
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() {}
42
43     // Called after EmitLoginPromptVisible is called.
44     virtual void EmitLoginPromptVisibleCalled() {}
45   };
46
47   // Interface for performing actions on behalf of the stub implementation.
48   class StubDelegate {
49    public:
50     virtual ~StubDelegate() {}
51
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;
57   };
58
59   // Sets the delegate used by the stub implementation. Ownership of |delegate|
60   // remains with the caller.
61   virtual void SetStubDelegate(StubDelegate* delegate) = 0;
62
63   // Adds and removes the observer.
64   virtual void AddObserver(Observer* observer) = 0;
65   virtual void RemoveObserver(Observer* observer) = 0;
66   virtual bool HasObserver(Observer* observer) = 0;
67
68   // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
69   virtual void EmitLoginPromptVisible() = 0;
70
71   // Restarts a job referenced by |pid| with the provided command line.
72   virtual void RestartJob(int pid, const std::string& command_line) = 0;
73
74   // Starts the session for the user.
75   virtual void StartSession(const std::string& user_email) = 0;
76
77   // Stops the current session.
78   virtual void StopSession() = 0;
79
80   // Starts the factory reset.
81   virtual void StartDeviceWipe() = 0;
82
83   // Locks the screen.
84   virtual void RequestLockScreen() = 0;
85
86   // Notifies that the lock screen is shown.
87   virtual void NotifyLockScreenShown() = 0;
88
89   // Notifies that the lock screen is dismissed.
90   virtual void NotifyLockScreenDismissed() = 0;
91
92   // Map that is used to describe the set of active user sessions where |key|
93   // is user_id and |value| is user_id_hash.
94   typedef std::map<std::string, std::string> ActiveSessionsMap;
95
96   // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
97   // method. It receives |sessions| argument where the keys are user_ids for
98   // all users that are currently active and |success| argument which indicates
99   // whether or not the request succeded.
100   typedef base::Callback<void(const ActiveSessionsMap& sessions,
101                               bool success)> ActiveSessionsCallback;
102
103   // Enumerates active user sessions. Usually Chrome naturally keeps track of
104   // active users when they are added into current session. When Chrome is
105   // restarted after crash by session_manager it only receives user_id and
106   // user_id_hash for one user. This method is used to retrieve list of all
107   // active users.
108   virtual void RetrieveActiveSessions(
109       const ActiveSessionsCallback& callback) = 0;
110
111   // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
112   // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
113   // string.  Upon success, we will pass a protobuf to the callback.  On
114   // failure, we will pass "".
115   typedef base::Callback<void(const std::string&)> RetrievePolicyCallback;
116
117   // Fetches the device policy blob stored by the session manager.  Upon
118   // completion of the retrieve attempt, we will call the provided callback.
119   virtual void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) = 0;
120
121   // Fetches the user policy blob stored by the session manager for the given
122   // |username|. Upon completion of the retrieve attempt, we will call the
123   // provided callback.
124   virtual void RetrievePolicyForUser(
125       const std::string& username,
126       const RetrievePolicyCallback& callback) = 0;
127
128   // Same as RetrievePolicyForUser() but blocks until a reply is received, and
129   // returns the policy synchronously. Returns an empty string if the method
130   // call fails.
131   // This may only be called in situations where blocking the UI thread is
132   // considered acceptable (e.g. restarting the browser after a crash or after
133   // a flag change).
134   virtual std::string BlockingRetrievePolicyForUser(
135       const std::string& username) = 0;
136
137   // Fetches the policy blob associated with the specified device-local account
138   // from session manager.  |callback| is invoked up on completion.
139   virtual void RetrieveDeviceLocalAccountPolicy(
140       const std::string& account_id,
141       const RetrievePolicyCallback& callback) = 0;
142
143   // Used for StoreDevicePolicy, StorePolicyForUser and
144   // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
145   // operation was successful or not.
146   typedef base::Callback<void(bool)> StorePolicyCallback;
147
148   // Attempts to asynchronously store |policy_blob| as device policy.  Upon
149   // completion of the store attempt, we will call callback.
150   virtual void StoreDevicePolicy(const std::string& policy_blob,
151                                  const StorePolicyCallback& callback) = 0;
152
153   // Attempts to asynchronously store |policy_blob| as user policy for the given
154   // |username|. Upon completion of the store attempt, we will call callback.
155   virtual void StorePolicyForUser(const std::string& username,
156                                   const std::string& policy_blob,
157                                   const StorePolicyCallback& callback) = 0;
158
159   // Sends a request to store a policy blob for the specified device-local
160   // account. The result of the operation is reported through |callback|.
161   virtual void StoreDeviceLocalAccountPolicy(
162       const std::string& account_id,
163       const std::string& policy_blob,
164       const StorePolicyCallback& callback) = 0;
165
166   // Sets the flags to be applied next time by the session manager when Chrome
167   // is restarted inside an already started session for a particular user.
168   virtual void SetFlagsForUser(const std::string& username,
169                                const std::vector<std::string>& flags) = 0;
170
171   typedef base::Callback<void(const std::vector<std::string>& state_keys)>
172       StateKeysCallback;
173
174   // Get the currently valid server-backed state keys for the device.
175   // Server-backed state keys are opaque, device-unique, time-dependent,
176   // client-determined identifiers that are used for keying state in the cloud
177   // for the device to retrieve after a device factory reset.
178   //
179   // The state keys are returned asynchronously via |callback|. The callback
180   // will be invoked with an empty state key vector in case of errors.
181   virtual void GetServerBackedStateKeys(const StateKeysCallback& callback) = 0;
182
183   // Creates the instance.
184   static SessionManagerClient* Create(DBusClientImplementationType type);
185
186   virtual ~SessionManagerClient();
187
188  protected:
189   // Create() should be used instead.
190   SessionManagerClient();
191
192  private:
193   DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
194 };
195
196 }  // namespace chromeos
197
198 #endif  // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_