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 #include "chromeos/dbus/fake_session_manager_client.h" 6 7 #include "base/bind.h" 8 #include "base/location.h" 9 #include "base/message_loop/message_loop.h" 10 #include "base/strings/string_util.h" 11 #include "chromeos/dbus/cryptohome_client.h" 12 13 namespace chromeos { 14 15 FakeSessionManagerClient::FakeSessionManagerClient() 16 : emit_login_prompt_ready_call_count_(0) , 17 notify_lock_screen_shown_call_count_(0), 18 notify_lock_screen_dismissed_call_count_(0){ 19 } 20 21 FakeSessionManagerClient::~FakeSessionManagerClient() { 22 } 23 24 void FakeSessionManagerClient::AddObserver(Observer* observer) { 25 observers_.AddObserver(observer); 26 } 27 28 void FakeSessionManagerClient::RemoveObserver(Observer* observer) { 29 observers_.RemoveObserver(observer); 30 } 31 32 bool FakeSessionManagerClient::HasObserver(Observer* observer) { 33 return observers_.HasObserver(observer); 34 } 35 36 void FakeSessionManagerClient::EmitLoginPromptReady() { 37 emit_login_prompt_ready_call_count_++; 38 } 39 40 void FakeSessionManagerClient::EmitLoginPromptVisible() { 41 } 42 43 void FakeSessionManagerClient::RestartJob(int pid, 44 const std::string& command_line) { 45 } 46 47 void FakeSessionManagerClient::RestartEntd() { 48 } 49 50 void FakeSessionManagerClient::StartSession(const std::string& user_email) { 51 DCHECK_EQ(0UL, user_sessions_.count(user_email)); 52 std::string user_id_hash = 53 CryptohomeClient::GetStubSanitizedUsername(user_email); 54 user_sessions_[user_email] = user_id_hash; 55 } 56 57 void FakeSessionManagerClient::StopSession() { 58 } 59 60 void FakeSessionManagerClient::StartDeviceWipe() { 61 } 62 63 void FakeSessionManagerClient::RequestLockScreen() { 64 } 65 66 void FakeSessionManagerClient::NotifyLockScreenShown() { 67 notify_lock_screen_shown_call_count_++; 68 } 69 70 void FakeSessionManagerClient::RequestUnlockScreen() { 71 } 72 73 void FakeSessionManagerClient::NotifyLockScreenDismissed() { 74 notify_lock_screen_dismissed_call_count_++; 75 } 76 77 void FakeSessionManagerClient::RetrieveActiveSessions( 78 const ActiveSessionsCallback& callback) { 79 base::MessageLoop::current()->PostTask( 80 FROM_HERE, base::Bind(callback, user_sessions_, true)); 81 } 82 83 void FakeSessionManagerClient::RetrieveDevicePolicy( 84 const RetrievePolicyCallback& callback) { 85 base::MessageLoop::current()->PostTask(FROM_HERE, 86 base::Bind(callback, device_policy_)); 87 } 88 89 void FakeSessionManagerClient::RetrievePolicyForUser( 90 const std::string& username, 91 const RetrievePolicyCallback& callback) { 92 base::MessageLoop::current()->PostTask( 93 FROM_HERE, base::Bind(callback, user_policies_[username])); 94 } 95 96 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser( 97 const std::string& username) { 98 return user_policies_[username]; 99 } 100 101 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy( 102 const std::string& account_id, 103 const RetrievePolicyCallback& callback) { 104 base::MessageLoop::current()->PostTask( 105 FROM_HERE, 106 base::Bind(callback, device_local_account_policy_[account_id])); 107 } 108 109 void FakeSessionManagerClient::StoreDevicePolicy( 110 const std::string& policy_blob, 111 const StorePolicyCallback& callback) { 112 device_policy_ = policy_blob; 113 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true)); 114 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(true)); 115 } 116 117 void FakeSessionManagerClient::StorePolicyForUser( 118 const std::string& username, 119 const std::string& policy_blob, 120 const std::string& policy_key, 121 const StorePolicyCallback& callback) { 122 user_policies_[username] = policy_blob; 123 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true)); 124 } 125 126 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy( 127 const std::string& account_id, 128 const std::string& policy_blob, 129 const StorePolicyCallback& callback) { 130 device_local_account_policy_[account_id] = policy_blob; 131 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true)); 132 } 133 134 void FakeSessionManagerClient::SetFlagsForUser( 135 const std::string& username, 136 const std::vector<std::string>& flags) { 137 } 138 139 const std::string& FakeSessionManagerClient::device_policy() const { 140 return device_policy_; 141 } 142 143 void FakeSessionManagerClient::set_device_policy( 144 const std::string& policy_blob) { 145 device_policy_ = policy_blob; 146 } 147 148 const std::string& FakeSessionManagerClient::user_policy( 149 const std::string& username) const { 150 std::map<std::string, std::string>::const_iterator it = 151 user_policies_.find(username); 152 return it == user_policies_.end() ? EmptyString() : it->second; 153 } 154 155 void FakeSessionManagerClient::set_user_policy(const std::string& username, 156 const std::string& policy_blob) { 157 user_policies_[username] = policy_blob; 158 } 159 160 const std::string& FakeSessionManagerClient::device_local_account_policy( 161 const std::string& account_id) const { 162 std::map<std::string, std::string>::const_iterator entry = 163 device_local_account_policy_.find(account_id); 164 return entry != device_local_account_policy_.end() ? entry->second 165 : EmptyString(); 166 } 167 168 void FakeSessionManagerClient::set_device_local_account_policy( 169 const std::string& account_id, 170 const std::string& policy_blob) { 171 device_local_account_policy_[account_id] = policy_blob; 172 } 173 174 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { 175 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); 176 } 177 178 } // namespace chromeos 179