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(Observer
* observer
) {
39 return observers_
.HasObserver(observer
);
42 void FakeSessionManagerClient::EmitLoginPromptVisible() {
45 void FakeSessionManagerClient::RestartJob(int pid
,
46 const std::string
& command_line
) {
49 void FakeSessionManagerClient::StartSession(const std::string
& user_email
) {
50 DCHECK_EQ(0UL, user_sessions_
.count(user_email
));
51 std::string user_id_hash
=
52 CryptohomeClient::GetStubSanitizedUsername(user_email
);
53 user_sessions_
[user_email
] = user_id_hash
;
56 void FakeSessionManagerClient::StopSession() {
59 void FakeSessionManagerClient::StartDeviceWipe() {
60 start_device_wipe_call_count_
++;
63 void FakeSessionManagerClient::RequestLockScreen() {
66 void FakeSessionManagerClient::NotifyLockScreenShown() {
67 notify_lock_screen_shown_call_count_
++;
70 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
71 notify_lock_screen_dismissed_call_count_
++;
74 void FakeSessionManagerClient::RetrieveActiveSessions(
75 const ActiveSessionsCallback
& callback
) {
76 base::MessageLoop::current()->PostTask(
77 FROM_HERE
, base::Bind(callback
, user_sessions_
, true));
80 void FakeSessionManagerClient::RetrieveDevicePolicy(
81 const RetrievePolicyCallback
& callback
) {
82 base::MessageLoop::current()->PostTask(FROM_HERE
,
83 base::Bind(callback
, device_policy_
));
86 void FakeSessionManagerClient::RetrievePolicyForUser(
87 const std::string
& username
,
88 const RetrievePolicyCallback
& callback
) {
89 base::MessageLoop::current()->PostTask(
90 FROM_HERE
, base::Bind(callback
, user_policies_
[username
]));
93 std::string
FakeSessionManagerClient::BlockingRetrievePolicyForUser(
94 const std::string
& username
) {
95 return user_policies_
[username
];
98 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
99 const std::string
& account_id
,
100 const RetrievePolicyCallback
& callback
) {
101 base::MessageLoop::current()->PostTask(
103 base::Bind(callback
, device_local_account_policy_
[account_id
]));
106 void FakeSessionManagerClient::StoreDevicePolicy(
107 const std::string
& policy_blob
,
108 const StorePolicyCallback
& callback
) {
109 device_policy_
= policy_blob
;
110 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
111 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(true));
114 void FakeSessionManagerClient::StorePolicyForUser(
115 const std::string
& username
,
116 const std::string
& policy_blob
,
117 const StorePolicyCallback
& callback
) {
118 user_policies_
[username
] = policy_blob
;
119 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
122 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
123 const std::string
& account_id
,
124 const std::string
& policy_blob
,
125 const StorePolicyCallback
& callback
) {
126 device_local_account_policy_
[account_id
] = policy_blob
;
127 base::MessageLoop::current()->PostTask(FROM_HERE
, base::Bind(callback
, true));
130 void FakeSessionManagerClient::SetFlagsForUser(
131 const std::string
& username
,
132 const std::vector
<std::string
>& flags
) {
135 void FakeSessionManagerClient::GetServerBackedStateKeys(
136 const StateKeysCallback
& callback
) {
137 base::MessageLoop::current()->PostTask(
138 FROM_HERE
, base::Bind(callback
, server_backed_state_keys_
));
141 const std::string
& FakeSessionManagerClient::device_policy() const {
142 return device_policy_
;
145 void FakeSessionManagerClient::set_device_policy(
146 const std::string
& policy_blob
) {
147 device_policy_
= policy_blob
;
150 const std::string
& FakeSessionManagerClient::user_policy(
151 const std::string
& username
) const {
152 std::map
<std::string
, std::string
>::const_iterator it
=
153 user_policies_
.find(username
);
154 return it
== user_policies_
.end() ? base::EmptyString() : it
->second
;
157 void FakeSessionManagerClient::set_user_policy(const std::string
& username
,
158 const std::string
& policy_blob
) {
159 user_policies_
[username
] = policy_blob
;
162 const std::string
& FakeSessionManagerClient::device_local_account_policy(
163 const std::string
& account_id
) const {
164 std::map
<std::string
, std::string
>::const_iterator entry
=
165 device_local_account_policy_
.find(account_id
);
166 return entry
!= device_local_account_policy_
.end() ? entry
->second
167 : base::EmptyString();
170 void FakeSessionManagerClient::set_device_local_account_policy(
171 const std::string
& account_id
,
172 const std::string
& policy_blob
) {
173 device_local_account_policy_
[account_id
] = policy_blob
;
176 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success
) {
177 FOR_EACH_OBSERVER(Observer
, observers_
, PropertyChangeComplete(success
));
180 } // namespace chromeos