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.h"
10 #include "base/string_util.h"
11 #include "chromeos/dbus/cryptohome_client.h"
15 FakeSessionManagerClient::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){
21 FakeSessionManagerClient::~FakeSessionManagerClient() {
24 void FakeSessionManagerClient::AddObserver(Observer
* observer
) {
25 observers_
.AddObserver(observer
);
28 void FakeSessionManagerClient::RemoveObserver(Observer
* observer
) {
29 observers_
.RemoveObserver(observer
);
32 bool FakeSessionManagerClient::HasObserver(Observer
* observer
) {
33 return observers_
.HasObserver(observer
);
36 void FakeSessionManagerClient::EmitLoginPromptReady() {
37 emit_login_prompt_ready_call_count_
++;
40 void FakeSessionManagerClient::EmitLoginPromptVisible() {
43 void FakeSessionManagerClient::RestartJob(int pid
,
44 const std::string
& command_line
) {
47 void FakeSessionManagerClient::RestartEntd() {
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() {
63 void FakeSessionManagerClient::RequestLockScreen() {
66 void FakeSessionManagerClient::NotifyLockScreenShown() {
67 notify_lock_screen_shown_call_count_
++;
70 void FakeSessionManagerClient::RequestUnlockScreen() {
73 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
74 notify_lock_screen_dismissed_call_count_
++;
77 void FakeSessionManagerClient::RetrieveActiveSessions(
78 const ActiveSessionsCallback
& callback
) {
79 base::MessageLoop::current()->PostTask(
80 FROM_HERE
, base::Bind(callback
, user_sessions_
, true));
83 void FakeSessionManagerClient::RetrieveDevicePolicy(
84 const RetrievePolicyCallback
& callback
) {
85 base::MessageLoop::current()->PostTask(FROM_HERE
,
86 base::Bind(callback
, device_policy_
));
89 void FakeSessionManagerClient::RetrievePolicyForUser(
90 const std::string
& username
,
91 const RetrievePolicyCallback
& callback
) {
92 base::MessageLoop::current()->PostTask(
93 FROM_HERE
, base::Bind(callback
, user_policies_
[username
]));
96 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
97 const std::string
& account_id
,
98 const RetrievePolicyCallback
& callback
) {
99 base::MessageLoop::current()->PostTask(
101 base::Bind(callback
, device_local_account_policy_
[account_id
]));
104 void FakeSessionManagerClient::StoreDevicePolicy(
105 const std::string
& policy_blob
,
106 const StorePolicyCallback
& callback
) {
107 device_policy_
= policy_blob
;
108 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
109 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(true));
112 void FakeSessionManagerClient::StorePolicyForUser(
113 const std::string
& username
,
114 const std::string
& policy_blob
,
115 const std::string
& policy_key
,
116 const StorePolicyCallback
& callback
) {
117 user_policies_
[username
] = policy_blob
;
118 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
121 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
122 const std::string
& account_id
,
123 const std::string
& policy_blob
,
124 const StorePolicyCallback
& callback
) {
125 device_local_account_policy_
[account_id
] = policy_blob
;
126 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
129 const std::string
& FakeSessionManagerClient::device_policy() const {
130 return device_policy_
;
133 void FakeSessionManagerClient::set_device_policy(
134 const std::string
& policy_blob
) {
135 device_policy_
= policy_blob
;
138 const std::string
& FakeSessionManagerClient::user_policy(
139 const std::string
& username
) const {
140 std::map
<std::string
, std::string
>::const_iterator it
=
141 user_policies_
.find(username
);
142 return it
== user_policies_
.end() ? EmptyString() : it
->second
;
145 void FakeSessionManagerClient::set_user_policy(const std::string
& username
,
146 const std::string
& policy_blob
) {
147 user_policies_
[username
] = policy_blob
;
150 const std::string
& FakeSessionManagerClient::device_local_account_policy(
151 const std::string
& account_id
) const {
152 std::map
<std::string
, std::string
>::const_iterator entry
=
153 device_local_account_policy_
.find(account_id
);
154 return entry
!= device_local_account_policy_
.end() ? entry
->second
158 void FakeSessionManagerClient::set_device_local_account_policy(
159 const std::string
& account_id
,
160 const std::string
& policy_blob
) {
161 device_local_account_policy_
[account_id
] = policy_blob
;
164 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success
) {
165 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(success
));
168 } // namespace chromeos