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 11 #include "base/basictypes.h" 12 #include "base/compiler_specific.h" 13 #include "base/observer_list.h" 14 #include "chromeos/dbus/session_manager_client.h" 15 16 namespace chromeos { 17 18 // A fake implementation of session_manager. Accepts policy blobs to be set and 19 // returns them unmodified. 20 class FakeSessionManagerClient : public chromeos::SessionManagerClient { 21 public: 22 FakeSessionManagerClient(); 23 virtual ~FakeSessionManagerClient(); 24 25 // SessionManagerClient: 26 virtual void AddObserver(Observer* observer) OVERRIDE; 27 virtual void RemoveObserver(Observer* observer) OVERRIDE; 28 virtual bool HasObserver(Observer* observer) OVERRIDE; 29 virtual void EmitLoginPromptReady() OVERRIDE; 30 virtual void EmitLoginPromptVisible() OVERRIDE; 31 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE; 32 virtual void RestartEntd() OVERRIDE; 33 virtual void StartSession(const std::string& user_email) OVERRIDE; 34 virtual void StopSession() OVERRIDE; 35 virtual void StartDeviceWipe() OVERRIDE; 36 virtual void RequestLockScreen() OVERRIDE; 37 virtual void NotifyLockScreenShown() OVERRIDE; 38 virtual void RequestUnlockScreen() 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 std::string& policy_key, 57 const StorePolicyCallback& callback) OVERRIDE; 58 virtual void StoreDeviceLocalAccountPolicy( 59 const std::string& account_id, 60 const std::string& policy_blob, 61 const StorePolicyCallback& callback) OVERRIDE; 62 virtual void SetFlagsForUser(const std::string& username, 63 const std::vector<std::string>& flags) OVERRIDE; 64 65 const std::string& device_policy() const; 66 void set_device_policy(const std::string& policy_blob); 67 68 const std::string& user_policy(const std::string& username) const; 69 void set_user_policy(const std::string& username, 70 const std::string& policy_blob); 71 72 const std::string& device_local_account_policy( 73 const std::string& account_id) const; 74 void set_device_local_account_policy(const std::string& account_id, 75 const std::string& policy_blob); 76 77 // Notify observers about a property change completion. 78 void OnPropertyChangeComplete(bool success); 79 80 // Returns how many times EmitLoginPromptReady() is called. 81 int emit_login_prompt_ready_call_count() { 82 return emit_login_prompt_ready_call_count_; 83 } 84 85 // Returns how many times LockScreenShown() was called. 86 int notify_lock_screen_shown_call_count() { 87 return notify_lock_screen_shown_call_count_; 88 } 89 90 // Returns how many times LockScreenDismissed() was called. 91 int notify_lock_screen_dismissed_call_count() { 92 return notify_lock_screen_dismissed_call_count_; 93 } 94 95 private: 96 std::string device_policy_; 97 std::map<std::string, std::string> user_policies_; 98 std::map<std::string, std::string> device_local_account_policy_; 99 ObserverList<Observer> observers_; 100 SessionManagerClient::ActiveSessionsMap user_sessions_; 101 102 int emit_login_prompt_ready_call_count_; 103 int notify_lock_screen_shown_call_count_; 104 int notify_lock_screen_dismissed_call_count_; 105 106 DISALLOW_COPY_AND_ASSIGN(FakeSessionManagerClient); 107 }; 108 109 } // namespace chromeos 110 111 #endif // CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 112