[Password Generation] Enable new UI
[chromium-blink-merge.git] / chromeos / dbus / fake_session_manager_client.cc
blob7445847d9db3b3f98f7b9fa3f804770b6ccf50be
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/message_loop/message_loop.h"
10 #include "base/strings/string_util.h"
11 #include "chromeos/dbus/cryptohome_client.h"
13 namespace chromeos {
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) {
22 FakeSessionManagerClient::~FakeSessionManagerClient() {
25 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
28 void FakeSessionManagerClient::AddObserver(Observer* observer) {
29 observers_.AddObserver(observer);
32 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
33 observers_.RemoveObserver(observer);
36 bool FakeSessionManagerClient::HasObserver(Observer* observer) {
37 return observers_.HasObserver(observer);
40 void FakeSessionManagerClient::EmitLoginPromptReady() {
41 emit_login_prompt_ready_call_count_++;
44 void FakeSessionManagerClient::EmitLoginPromptVisible() {
47 void FakeSessionManagerClient::RestartJob(int pid,
48 const std::string& command_line) {
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;
58 void FakeSessionManagerClient::StopSession() {
61 void FakeSessionManagerClient::StartDeviceWipe() {
62 start_device_wipe_call_count_++;
65 void FakeSessionManagerClient::RequestLockScreen() {
68 void FakeSessionManagerClient::NotifyLockScreenShown() {
69 notify_lock_screen_shown_call_count_++;
72 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
73 notify_lock_screen_dismissed_call_count_++;
76 void FakeSessionManagerClient::RetrieveActiveSessions(
77 const ActiveSessionsCallback& callback) {
78 base::MessageLoop::current()->PostTask(
79 FROM_HERE, base::Bind(callback, user_sessions_, true));
82 void FakeSessionManagerClient::RetrieveDevicePolicy(
83 const RetrievePolicyCallback& callback) {
84 base::MessageLoop::current()->PostTask(FROM_HERE,
85 base::Bind(callback, device_policy_));
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]));
95 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
96 const std::string& username) {
97 return user_policies_[username];
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]));
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));
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));
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));
133 void FakeSessionManagerClient::SetFlagsForUser(
134 const std::string& username,
135 const std::vector<std::string>& flags) {
138 const std::string& FakeSessionManagerClient::device_policy() const {
139 return device_policy_;
142 void FakeSessionManagerClient::set_device_policy(
143 const std::string& policy_blob) {
144 device_policy_ = policy_blob;
147 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;
154 void FakeSessionManagerClient::set_user_policy(const std::string& username,
155 const std::string& policy_blob) {
156 user_policies_[username] = policy_blob;
159 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();
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;
173 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
174 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
177 } // namespace chromeos