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