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