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()
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(Observer
* observer
) {
40 return observers_
.HasObserver(observer
);
43 void FakeSessionManagerClient::EmitLoginPromptVisible() {
46 void FakeSessionManagerClient::RestartJob(int pid
,
47 const std::string
& command_line
) {
50 void FakeSessionManagerClient::StartSession(const std::string
& user_email
) {
51 DCHECK_EQ(0UL, user_sessions_
.count(user_email
));
52 std::string user_id_hash
=
53 CryptohomeClient::GetStubSanitizedUsername(user_email
);
54 user_sessions_
[user_email
] = user_id_hash
;
57 void FakeSessionManagerClient::StopSession() {
60 void FakeSessionManagerClient::StartDeviceWipe() {
61 start_device_wipe_call_count_
++;
64 void FakeSessionManagerClient::RequestLockScreen() {
67 void FakeSessionManagerClient::NotifyLockScreenShown() {
68 notify_lock_screen_shown_call_count_
++;
71 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
72 notify_lock_screen_dismissed_call_count_
++;
75 void FakeSessionManagerClient::RetrieveActiveSessions(
76 const ActiveSessionsCallback
& callback
) {
77 base::MessageLoop::current()->PostTask(
78 FROM_HERE
, base::Bind(callback
, user_sessions_
, true));
81 void FakeSessionManagerClient::RetrieveDevicePolicy(
82 const RetrievePolicyCallback
& callback
) {
83 base::MessageLoop::current()->PostTask(FROM_HERE
,
84 base::Bind(callback
, device_policy_
));
87 void FakeSessionManagerClient::RetrievePolicyForUser(
88 const std::string
& username
,
89 const RetrievePolicyCallback
& callback
) {
90 base::MessageLoop::current()->PostTask(
91 FROM_HERE
, base::Bind(callback
, user_policies_
[username
]));
94 std::string
FakeSessionManagerClient::BlockingRetrievePolicyForUser(
95 const std::string
& username
) {
96 return user_policies_
[username
];
99 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
100 const std::string
& account_id
,
101 const RetrievePolicyCallback
& callback
) {
102 base::MessageLoop::current()->PostTask(
104 base::Bind(callback
, device_local_account_policy_
[account_id
]));
107 void FakeSessionManagerClient::StoreDevicePolicy(
108 const std::string
& policy_blob
,
109 const StorePolicyCallback
& callback
) {
110 device_policy_
= policy_blob
;
111 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
112 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(true));
115 void FakeSessionManagerClient::StorePolicyForUser(
116 const std::string
& username
,
117 const std::string
& policy_blob
,
118 const StorePolicyCallback
& callback
) {
119 user_policies_
[username
] = policy_blob
;
120 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
123 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
124 const std::string
& account_id
,
125 const std::string
& policy_blob
,
126 const StorePolicyCallback
& callback
) {
127 device_local_account_policy_
[account_id
] = policy_blob
;
128 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
131 void FakeSessionManagerClient::SetFlagsForUser(
132 const std::string
& username
,
133 const std::vector
<std::string
>& flags
) {
136 void FakeSessionManagerClient::GetServerBackedStateKeys(
137 const StateKeysCallback
& callback
) {
138 base::MessageLoop::current()->PostTask(
139 FROM_HERE
, base::Bind(callback
, server_backed_state_keys_
, first_boot_
));
142 const std::string
& FakeSessionManagerClient::device_policy() const {
143 return device_policy_
;
146 void FakeSessionManagerClient::set_device_policy(
147 const std::string
& policy_blob
) {
148 device_policy_
= policy_blob
;
151 const 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() ? base::EmptyString() : it
->second
;
158 void FakeSessionManagerClient::set_user_policy(const std::string
& username
,
159 const std::string
& policy_blob
) {
160 user_policies_
[username
] = policy_blob
;
163 const 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 : base::EmptyString();
171 void 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
;
177 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success
) {
178 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(success
));
181 } // namespace chromeos