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