Roll src/third_party/WebKit 10b2b4a:a6818f9 (svn 202548:202549)
[chromium-blink-merge.git] / chromeos / dbus / fake_session_manager_client.cc
blob89261ea52aa3b4a1e1e6bed9d8f3822012d38a58
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.
5 #include "chromeos/dbus/fake_session_manager_client.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_util.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "chromeos/dbus/cryptohome_client.h"
14 namespace chromeos {
16 FakeSessionManagerClient::FakeSessionManagerClient()
17 : start_device_wipe_call_count_(0),
18 notify_lock_screen_shown_call_count_(0),
19 notify_lock_screen_dismissed_call_count_(0) {
22 FakeSessionManagerClient::~FakeSessionManagerClient() {
25 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
28 void FakeSessionManagerClient::SetStubDelegate(StubDelegate* delegate) {
31 void FakeSessionManagerClient::AddObserver(Observer* observer) {
32 observers_.AddObserver(observer);
35 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
36 observers_.RemoveObserver(observer);
39 bool FakeSessionManagerClient::HasObserver(const Observer* observer) const {
40 return observers_.HasObserver(observer);
43 bool FakeSessionManagerClient::IsScreenLocked() const {
44 return false;
47 void FakeSessionManagerClient::EmitLoginPromptVisible() {
50 void FakeSessionManagerClient::RestartJob(
51 const std::vector<std::string>& argv) {}
53 void FakeSessionManagerClient::StartSession(const std::string& user_email) {
54 DCHECK_EQ(0UL, user_sessions_.count(user_email));
55 std::string user_id_hash =
56 CryptohomeClient::GetStubSanitizedUsername(user_email);
57 user_sessions_[user_email] = user_id_hash;
60 void FakeSessionManagerClient::StopSession() {
63 void FakeSessionManagerClient::NotifySupervisedUserCreationStarted() {
66 void FakeSessionManagerClient::NotifySupervisedUserCreationFinished() {
69 void FakeSessionManagerClient::StartDeviceWipe() {
70 start_device_wipe_call_count_++;
73 void FakeSessionManagerClient::RequestLockScreen() {
76 void FakeSessionManagerClient::NotifyLockScreenShown() {
77 notify_lock_screen_shown_call_count_++;
80 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
81 notify_lock_screen_dismissed_call_count_++;
84 void FakeSessionManagerClient::RetrieveActiveSessions(
85 const ActiveSessionsCallback& callback) {
86 base::ThreadTaskRunnerHandle::Get()->PostTask(
87 FROM_HERE, base::Bind(callback, user_sessions_, true));
90 void FakeSessionManagerClient::RetrieveDevicePolicy(
91 const RetrievePolicyCallback& callback) {
92 base::ThreadTaskRunnerHandle::Get()->PostTask(
93 FROM_HERE, base::Bind(callback, device_policy_));
96 void FakeSessionManagerClient::RetrievePolicyForUser(
97 const std::string& username,
98 const RetrievePolicyCallback& callback) {
99 base::ThreadTaskRunnerHandle::Get()->PostTask(
100 FROM_HERE, base::Bind(callback, user_policies_[username]));
103 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
104 const std::string& username) {
105 return user_policies_[username];
108 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
109 const std::string& account_id,
110 const RetrievePolicyCallback& callback) {
111 base::ThreadTaskRunnerHandle::Get()->PostTask(
112 FROM_HERE,
113 base::Bind(callback, device_local_account_policy_[account_id]));
116 void FakeSessionManagerClient::StoreDevicePolicy(
117 const std::string& policy_blob,
118 const StorePolicyCallback& callback) {
119 device_policy_ = policy_blob;
120 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
121 base::Bind(callback, true));
122 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(true));
125 void FakeSessionManagerClient::StorePolicyForUser(
126 const std::string& username,
127 const std::string& policy_blob,
128 const StorePolicyCallback& callback) {
129 user_policies_[username] = policy_blob;
130 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
131 base::Bind(callback, true));
134 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
135 const std::string& account_id,
136 const std::string& policy_blob,
137 const StorePolicyCallback& callback) {
138 device_local_account_policy_[account_id] = policy_blob;
139 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
140 base::Bind(callback, true));
143 void FakeSessionManagerClient::SetFlagsForUser(
144 const std::string& username,
145 const std::vector<std::string>& flags) {
148 void FakeSessionManagerClient::GetServerBackedStateKeys(
149 const StateKeysCallback& callback) {
150 base::ThreadTaskRunnerHandle::Get()->PostTask(
151 FROM_HERE, base::Bind(callback, server_backed_state_keys_));
154 const std::string& FakeSessionManagerClient::device_policy() const {
155 return device_policy_;
158 void FakeSessionManagerClient::set_device_policy(
159 const std::string& policy_blob) {
160 device_policy_ = policy_blob;
163 const std::string& FakeSessionManagerClient::user_policy(
164 const std::string& username) const {
165 std::map<std::string, std::string>::const_iterator it =
166 user_policies_.find(username);
167 return it == user_policies_.end() ? base::EmptyString() : it->second;
170 void FakeSessionManagerClient::set_user_policy(const std::string& username,
171 const std::string& policy_blob) {
172 user_policies_[username] = policy_blob;
175 const std::string& FakeSessionManagerClient::device_local_account_policy(
176 const std::string& account_id) const {
177 std::map<std::string, std::string>::const_iterator entry =
178 device_local_account_policy_.find(account_id);
179 return entry != device_local_account_policy_.end() ? entry->second
180 : base::EmptyString();
183 void FakeSessionManagerClient::set_device_local_account_policy(
184 const std::string& account_id,
185 const std::string& policy_blob) {
186 device_local_account_policy_[account_id] = policy_blob;
189 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
190 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
193 } // namespace chromeos