session_manager_client.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <map>
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/chromeos_export.h"
14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chromeos/dbus/dbus_client.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/dbus_client_implementation_type.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SessionManagerClient is used to communicate with the session manager.
20424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class CHROMEOS_EXPORT SessionManagerClient : public DBusClient {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Interface for observing changes from the session manager.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Observer {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    virtual ~Observer() {}
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when the owner key is set.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OwnerKeySet(bool success) {}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when the property change is complete.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void PropertyChangeComplete(bool success) {}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Called when the session manager announces that the screen has been locked
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // successfully (i.e. after NotifyLockScreenShown() has been called).
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    virtual void ScreenIsLocked() {}
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Called when the session manager announces that the screen has been
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // unlocked successfully (i.e. after NotifyLockScreenDismissed() has
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // been called).
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    virtual void ScreenIsUnlocked() {}
41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Called after EmitLoginPromptVisible is called.
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    virtual void EmitLoginPromptVisibleCalled() {}
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Interface for performing actions on behalf of the stub implementation.
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  class StubDelegate {
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)   public:
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    virtual ~StubDelegate() {}
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // Locks the screen. Invoked by the stub when RequestLockScreen() is called.
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // In the real implementation of SessionManagerClient::RequestLockScreen(),
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // a lock request is forwarded to the session manager; in the stub, this is
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // short-circuited and the screen is locked immediately.
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    virtual void LockScreenForStub() = 0;
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  };
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Sets the delegate used by the stub implementation. Ownership of |delegate|
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // remains with the caller.
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void SetStubDelegate(StubDelegate* delegate) = 0;
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds and removes the observer.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AddObserver(Observer* observer) = 0;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RemoveObserver(Observer* observer) = 0;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HasObserver(Observer* observer) = 0;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Kicks off an attempt to emit the "login-prompt-visible" upstart signal.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitLoginPromptVisible() = 0;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restarts a job referenced by |pid| with the provided command line.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RestartJob(int pid, const std::string& command_line) = 0;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Starts the session for the user.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StartSession(const std::string& user_email) = 0;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stops the current session.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StopSession() = 0;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Starts the factory reset.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StartDeviceWipe() = 0;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Locks the screen.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RequestLockScreen() = 0;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies that the lock screen is shown.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void NotifyLockScreenShown() = 0;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies that the lock screen is dismissed.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void NotifyLockScreenDismissed() = 0;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Map that is used to describe the set of active user sessions where |key|
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // is user_id and |value| is user_id_hash.
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef std::map<std::string, std::string> ActiveSessionsMap;
9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // method. It receives |sessions| argument where the keys are user_ids for
9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // all users that are currently active and |success| argument which indicates
9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // whether or not the request succeded.
9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef base::Callback<void(const ActiveSessionsMap& sessions,
10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                              bool success)> ActiveSessionsCallback;
10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Enumerates active user sessions. Usually Chrome naturally keeps track of
10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // active users when they are added into current session. When Chrome is
10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // restarted after crash by session_manager it only receives user_id and
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // user_id_hash for one user. This method is used to retrieve list of all
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // active users.
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void RetrieveActiveSessions(
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const ActiveSessionsCallback& callback) = 0;
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Used for RetrieveDevicePolicy, RetrievePolicyForUser and
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // string.  Upon success, we will pass a protobuf to the callback.  On
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // failure, we will pass "".
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(const std::string&)> RetrievePolicyCallback;
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Fetches the device policy blob stored by the session manager.  Upon
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completion of the retrieve attempt, we will call the provided callback.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) = 0;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
120a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Fetches the user policy blob stored by the session manager for the given
121a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // |username|. Upon completion of the retrieve attempt, we will call the
122a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // provided callback.
123a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void RetrievePolicyForUser(
124a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const std::string& username,
125a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const RetrievePolicyCallback& callback) = 0;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
127bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Same as RetrievePolicyForUser() but blocks until a reply is received, and
128bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // returns the policy synchronously. Returns an empty string if the method
129bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // call fails.
130bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // This may only be called in situations where blocking the UI thread is
131bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // considered acceptable (e.g. restarting the browser after a crash or after
132bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // a flag change).
133bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  virtual std::string BlockingRetrievePolicyForUser(
134bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      const std::string& username) = 0;
135bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fetches the policy blob associated with the specified device-local account
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // from session manager.  |callback| is invoked up on completion.
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RetrieveDeviceLocalAccountPolicy(
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& account_id,
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const RetrievePolicyCallback& callback) = 0;
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
142a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Used for StoreDevicePolicy, StorePolicyForUser and
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // StoreDeviceLocalAccountPolicy. Takes a boolean indicating whether the
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // operation was successful or not.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(bool)> StorePolicyCallback;
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Attempts to asynchronously store |policy_blob| as device policy.  Upon
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completion of the store attempt, we will call callback.
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StoreDevicePolicy(const std::string& policy_blob,
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const StorePolicyCallback& callback) = 0;
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
152a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Attempts to asynchronously store |policy_blob| as user policy for the given
153a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // |username|. Upon completion of the store attempt, we will call callback.
154a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // The |policy_key| argument is not sent to the session manager, but is used
155a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // by the stub implementation to enable policy validation on desktop builds.
156a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void StorePolicyForUser(const std::string& username,
157a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                  const std::string& policy_blob,
158a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                  const std::string& policy_key,
159a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                  const StorePolicyCallback& callback) = 0;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sends a request to store a policy blob for the specified device-local
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // account. The result of the operation is reported through |callback|.
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void StoreDeviceLocalAccountPolicy(
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& account_id,
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& policy_blob,
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const StorePolicyCallback& callback) = 0;
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Sets the flags to be applied next time by the session manager when Chrome
1697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // is restarted inside an already started session for a particular user.
1707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetFlagsForUser(const std::string& username,
1717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                               const std::vector<std::string>& flags) = 0;
1727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates the instance.
174424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  static SessionManagerClient* Create(DBusClientImplementationType type);
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~SessionManagerClient();
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create() should be used instead.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionManagerClient();
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SessionManagerClient);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chromeos
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
189