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::SetStubDelegate(StubDelegate
* delegate
) {
30 void FakeSessionManagerClient::AddObserver(Observer
* observer
) {
31 observers_
.AddObserver(observer
);
34 void FakeSessionManagerClient::RemoveObserver(Observer
* observer
) {
35 observers_
.RemoveObserver(observer
);
38 bool FakeSessionManagerClient::HasObserver(const Observer
* observer
) const {
39 return observers_
.HasObserver(observer
);
42 bool FakeSessionManagerClient::IsScreenLocked() const {
46 void FakeSessionManagerClient::EmitLoginPromptVisible() {
49 void FakeSessionManagerClient::RestartJob(int pid
,
50 const std::string
& command_line
) {
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::MessageLoop::current()->PostTask(
87 FROM_HERE
, base::Bind(callback
, user_sessions_
, true));
90 void FakeSessionManagerClient::RetrieveDevicePolicy(
91 const RetrievePolicyCallback
& callback
) {
92 base::MessageLoop::current()->PostTask(FROM_HERE
,
93 base::Bind(callback
, device_policy_
));
96 void FakeSessionManagerClient::RetrievePolicyForUser(
97 const std::string
& username
,
98 const RetrievePolicyCallback
& callback
) {
99 base::MessageLoop::current()->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::MessageLoop::current()->PostTask(
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::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
121 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(true));
124 void FakeSessionManagerClient::StorePolicyForUser(
125 const std::string
& username
,
126 const std::string
& policy_blob
,
127 const StorePolicyCallback
& callback
) {
128 user_policies_
[username
] = policy_blob
;
129 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
132 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
133 const std::string
& account_id
,
134 const std::string
& policy_blob
,
135 const StorePolicyCallback
& callback
) {
136 device_local_account_policy_
[account_id
] = policy_blob
;
137 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
140 void FakeSessionManagerClient::SetFlagsForUser(
141 const std::string
& username
,
142 const std::vector
<std::string
>& flags
) {
145 void FakeSessionManagerClient::GetServerBackedStateKeys(
146 const StateKeysCallback
& callback
) {
147 base::MessageLoop::current()->PostTask(
148 FROM_HERE
, base::Bind(callback
, server_backed_state_keys_
));
151 const std::string
& FakeSessionManagerClient::device_policy() const {
152 return device_policy_
;
155 void FakeSessionManagerClient::set_device_policy(
156 const std::string
& policy_blob
) {
157 device_policy_
= policy_blob
;
160 const std::string
& FakeSessionManagerClient::user_policy(
161 const std::string
& username
) const {
162 std::map
<std::string
, std::string
>::const_iterator it
=
163 user_policies_
.find(username
);
164 return it
== user_policies_
.end() ? base::EmptyString() : it
->second
;
167 void FakeSessionManagerClient::set_user_policy(const std::string
& username
,
168 const std::string
& policy_blob
) {
169 user_policies_
[username
] = policy_blob
;
172 const std::string
& FakeSessionManagerClient::device_local_account_policy(
173 const std::string
& account_id
) const {
174 std::map
<std::string
, std::string
>::const_iterator entry
=
175 device_local_account_policy_
.find(account_id
);
176 return entry
!= device_local_account_policy_
.end() ? entry
->second
177 : base::EmptyString();
180 void FakeSessionManagerClient::set_device_local_account_policy(
181 const std::string
& account_id
,
182 const std::string
& policy_blob
) {
183 device_local_account_policy_
[account_id
] = policy_blob
;
186 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success
) {
187 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(success
));
190 } // namespace chromeos