1 // Copyright 2013 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_FAKE_SESSION_MANAGER_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/compiler_specific.h" 14 #include "base/observer_list.h" 15 #include "chromeos/dbus/session_manager_client.h" 16 17 namespace chromeos { 18 19 // A fake implementation of session_manager. Accepts policy blobs to be set and 20 // returns them unmodified. 21 class FakeSessionManagerClient : public SessionManagerClient { 22 public: 23 FakeSessionManagerClient(); 24 virtual ~FakeSessionManagerClient(); 25 26 // SessionManagerClient overrides 27 virtual void Init(dbus::Bus* bus) OVERRIDE; 28 virtual void SetStubDelegate(StubDelegate* delegate) OVERRIDE; 29 virtual void AddObserver(Observer* observer) OVERRIDE; 30 virtual void RemoveObserver(Observer* observer) OVERRIDE; 31 virtual bool HasObserver(Observer* observer) OVERRIDE; 32 virtual void EmitLoginPromptVisible() OVERRIDE; 33 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE; 34 virtual void StartSession(const std::string& user_email) OVERRIDE; 35 virtual void StopSession() OVERRIDE; 36 virtual void StartDeviceWipe() OVERRIDE; 37 virtual void RequestLockScreen() OVERRIDE; 38 virtual void NotifyLockScreenShown() OVERRIDE; 39 virtual void NotifyLockScreenDismissed() OVERRIDE; 40 virtual void RetrieveActiveSessions( 41 const ActiveSessionsCallback& callback) OVERRIDE; 42 virtual void RetrieveDevicePolicy( 43 const RetrievePolicyCallback& callback) OVERRIDE; 44 virtual void RetrievePolicyForUser( 45 const std::string& username, 46 const RetrievePolicyCallback& callback) OVERRIDE; 47 virtual std::string BlockingRetrievePolicyForUser( 48 const std::string& username) OVERRIDE; 49 virtual void RetrieveDeviceLocalAccountPolicy( 50 const std::string& account_id, 51 const RetrievePolicyCallback& callback) OVERRIDE; 52 virtual void StoreDevicePolicy(const std::string& policy_blob, 53 const StorePolicyCallback& callback) OVERRIDE; 54 virtual void StorePolicyForUser(const std::string& username, 55 const std::string& policy_blob, 56 const StorePolicyCallback& callback) OVERRIDE; 57 virtual void StoreDeviceLocalAccountPolicy( 58 const std::string& account_id, 59 const std::string& policy_blob, 60 const StorePolicyCallback& callback) OVERRIDE; 61 virtual void SetFlagsForUser(const std::string& username, 62 const std::vector<std::string>& flags) OVERRIDE; 63 virtual void GetServerBackedStateKeys(const StateKeysCallback& callback) 64 OVERRIDE; 65 66 const std::string& device_policy() const; 67 void set_device_policy(const std::string& policy_blob); 68 69 const std::string& user_policy(const std::string& username) const; 70 void set_user_policy(const std::string& username, 71 const std::string& policy_blob); 72 73 const std::string& device_local_account_policy( 74 const std::string& account_id) const; 75 void set_device_local_account_policy(const std::string& account_id, 76 const std::string& policy_blob); 77 78 // Notify observers about a property change completion. 79 void OnPropertyChangeComplete(bool success); 80 81 // Configures the list of state keys used to satisfy 82 // GetServerBackedStateKeys() requests. 83 void set_server_backed_state_keys( 84 const std::vector<std::string>& state_keys) { 85 server_backed_state_keys_ = state_keys; 86 } 87 88 void set_first_boot(bool first_boot) { first_boot_ = first_boot; } 89 90 int start_device_wipe_call_count() const { 91 return start_device_wipe_call_count_; 92 } 93 94 // Returns how many times LockScreenShown() was called. 95 int notify_lock_screen_shown_call_count() const { 96 return notify_lock_screen_shown_call_count_; 97 } 98 99 // Returns how many times LockScreenDismissed() was called. 100 int notify_lock_screen_dismissed_call_count() const { 101 return notify_lock_screen_dismissed_call_count_; 102 } 103 104 private: 105 std::string device_policy_; 106 std::map<std::string, std::string> user_policies_; 107 std::map<std::string, std::string> device_local_account_policy_; 108 ObserverList<Observer> observers_; 109 SessionManagerClient::ActiveSessionsMap user_sessions_; 110 std::vector<std::string> server_backed_state_keys_; 111 bool first_boot_; 112 113 int start_device_wipe_call_count_; 114 int notify_lock_screen_shown_call_count_; 115 int notify_lock_screen_dismissed_call_count_; 116 117 DISALLOW_COPY_AND_ASSIGN(FakeSessionManagerClient); 118 }; 119 120 } // namespace chromeos 121 122 #endif // CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 123