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"
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"
15 FakeSessionManagerClient::FakeSessionManagerClient()
16 : start_device_wipe_call_count_(0),
17 notify_lock_screen_shown_call_count_(0),
18 notify_lock_screen_dismissed_call_count_(0) {
21 FakeSessionManagerClient::~FakeSessionManagerClient() {
24 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
27 void FakeSessionManagerClient::AddObserver(Observer* observer) {
28 observers_.AddObserver(observer);
31 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
32 observers_.RemoveObserver(observer);
35 bool FakeSessionManagerClient::HasObserver(Observer* observer) {
36 return observers_.HasObserver(observer);
39 void FakeSessionManagerClient::EmitLoginPromptVisible() {
42 void FakeSessionManagerClient::RestartJob(int pid,
43 const std::string& command_line) {
46 void FakeSessionManagerClient::StartSession(const std::string& user_email) {
47 DCHECK_EQ(0UL, user_sessions_.count(user_email));
48 std::string user_id_hash =
49 CryptohomeClient::GetStubSanitizedUsername(user_email);
50 user_sessions_[user_email] = user_id_hash;
53 void FakeSessionManagerClient::StopSession() {
56 void FakeSessionManagerClient::StartDeviceWipe() {
57 start_device_wipe_call_count_++;
60 void FakeSessionManagerClient::RequestLockScreen() {
63 void FakeSessionManagerClient::NotifyLockScreenShown() {
64 notify_lock_screen_shown_call_count_++;
67 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
68 notify_lock_screen_dismissed_call_count_++;
71 void FakeSessionManagerClient::RetrieveActiveSessions(
72 const ActiveSessionsCallback& callback) {
73 base::MessageLoop::current()->PostTask(
74 FROM_HERE, base::Bind(callback, user_sessions_, true));
77 void FakeSessionManagerClient::RetrieveDevicePolicy(
78 const RetrievePolicyCallback& callback) {
79 base::MessageLoop::current()->PostTask(FROM_HERE,
80 base::Bind(callback, device_policy_));
83 void FakeSessionManagerClient::RetrievePolicyForUser(
84 const std::string& username,
85 const RetrievePolicyCallback& callback) {
86 base::MessageLoop::current()->PostTask(
87 FROM_HERE, base::Bind(callback, user_policies_[username]));
90 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
91 const std::string& username) {
92 return user_policies_[username];
95 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
96 const std::string& account_id,
97 const RetrievePolicyCallback& callback) {
98 base::MessageLoop::current()->PostTask(
100 base::Bind(callback, device_local_account_policy_[account_id]));
103 void FakeSessionManagerClient::StoreDevicePolicy(
104 const std::string& policy_blob,
105 const StorePolicyCallback& callback) {
106 device_policy_ = policy_blob;
107 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
108 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(true));
111 void FakeSessionManagerClient::StorePolicyForUser(
112 const std::string& username,
113 const std::string& policy_blob,
114 const std::string& policy_key,
115 const StorePolicyCallback& callback) {
116 user_policies_[username] = policy_blob;
117 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
120 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
121 const std::string& account_id,
122 const std::string& policy_blob,
123 const StorePolicyCallback& callback) {
124 device_local_account_policy_[account_id] = policy_blob;
125 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
128 void FakeSessionManagerClient::SetFlagsForUser(
129 const std::string& username,
130 const std::vector<std::string>& flags) {
133 const std::string& FakeSessionManagerClient::device_policy() const {
134 return device_policy_;
137 void FakeSessionManagerClient::set_device_policy(
138 const std::string& policy_blob) {
139 device_policy_ = policy_blob;
142 const std::string& FakeSessionManagerClient::user_policy(
143 const std::string& username) const {
144 std::map<std::string, std::string>::const_iterator it =
145 user_policies_.find(username);
146 return it == user_policies_.end() ? base::EmptyString() : it->second;
149 void FakeSessionManagerClient::set_user_policy(const std::string& username,
150 const std::string& policy_blob) {
151 user_policies_[username] = policy_blob;
154 const std::string& FakeSessionManagerClient::device_local_account_policy(
155 const std::string& account_id) const {
156 std::map<std::string, std::string>::const_iterator entry =
157 device_local_account_policy_.find(account_id);
158 return entry != device_local_account_policy_.end() ? entry->second
159 : base::EmptyString();
162 void FakeSessionManagerClient::set_device_local_account_policy(
163 const std::string& account_id,
164 const std::string& policy_blob) {
165 device_local_account_policy_[account_id] = policy_blob;
168 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
169 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
172 } // namespace chromeos