Upstream version 5.34.104.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
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"
16
17 namespace chromeos {
18
19 // SessionManagerClient is used to communicate with the session manager.
20 class CHROMEOS_EXPORT SessionManagerClient : public DBusClient {
21  public:
22   // Interface for observing changes from the session manager.
23   class Observer {
24    public:
25     // Called when the owner key is set.
26     virtual void OwnerKeySet(bool success) {}
27
28     // Called when the property change is complete.
29     virtual void PropertyChangeComplete(bool success) {}
30
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
34     // session manager).
35     // TODO(derat): Delete this once the session manager is calling the
36     // "LockScreen" method instead.
37     virtual void LockScreen() {}
38
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() {}
42
43     // Called when the session manager announces that the screen has been
44     // unlocked successfully (i.e. after NotifyLockScreenDismissed() has
45     // been called).
46     virtual void ScreenIsUnlocked() {}
47
48     // Called after EmitLoginPromptVisible is called.
49     virtual void EmitLoginPromptVisibleCalled() {}
50   };
51
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;
56
57   // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
58   virtual void EmitLoginPromptVisible() = 0;
59
60   // Restarts a job referenced by |pid| with the provided command line.
61   virtual void RestartJob(int pid, const std::string& command_line) = 0;
62
63   // Starts the session for the user.
64   virtual void StartSession(const std::string& user_email) = 0;
65
66   // Stops the current session.
67   virtual void StopSession() = 0;
68
69   // Starts the factory reset.
70   virtual void StartDeviceWipe() = 0;
71
72   // Locks the screen.
73   virtual void RequestLockScreen() = 0;
74
75   // Notifies that the lock screen is shown.
76   virtual void NotifyLockScreenShown() = 0;
77
78   // Notifies that the lock screen is dismissed.
79   virtual void NotifyLockScreenDismissed() = 0;
80
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;
84
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;
91
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
96   // active users.
97   virtual void RetrieveActiveSessions(
98       const ActiveSessionsCallback& callback) = 0;
99
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;
105
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;
109
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;
116
117   // Same as RetrievePolicyForUser() but blocks until a reply is received, and
118   // returns the policy synchronously. Returns an empty string if the method
119   // call fails.
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
122   // a flag change).
123   virtual std::string BlockingRetrievePolicyForUser(
124       const std::string& username) = 0;
125
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;
131
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;
136
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;
141
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;
150
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;
157
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;
162
163   // Creates the instance.
164   static SessionManagerClient* Create(DBusClientImplementationType type);
165
166   virtual ~SessionManagerClient();
167
168  protected:
169   // Create() should be used instead.
170   SessionManagerClient();
171
172  private:
173   DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
174 };
175
176 }  // namespace chromeos
177
178 #endif  // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_