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