Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / fake_session_manager_client.cc
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
13 namespace chromeos {
14
15 FakeSessionManagerClient::FakeSessionManagerClient()
16     : first_boot_(false),
17       start_device_wipe_call_count_(0),
18       notify_lock_screen_shown_call_count_(0),
19       notify_lock_screen_dismissed_call_count_(0) {
20 }
21
22 FakeSessionManagerClient::~FakeSessionManagerClient() {
23 }
24
25 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
26 }
27
28 void FakeSessionManagerClient::SetStubDelegate(StubDelegate* delegate) {
29 }
30
31 void FakeSessionManagerClient::AddObserver(Observer* observer) {
32   observers_.AddObserver(observer);
33 }
34
35 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
36   observers_.RemoveObserver(observer);
37 }
38
39 bool FakeSessionManagerClient::HasObserver(Observer* observer) {
40   return observers_.HasObserver(observer);
41 }
42
43 void FakeSessionManagerClient::EmitLoginPromptVisible() {
44 }
45
46 void FakeSessionManagerClient::RestartJob(int pid,
47                                           const std::string& command_line) {
48 }
49
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;
55 }
56
57 void FakeSessionManagerClient::StopSession() {
58 }
59
60 void FakeSessionManagerClient::StartDeviceWipe() {
61   start_device_wipe_call_count_++;
62 }
63
64 void FakeSessionManagerClient::RequestLockScreen() {
65 }
66
67 void FakeSessionManagerClient::NotifyLockScreenShown() {
68   notify_lock_screen_shown_call_count_++;
69 }
70
71 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
72   notify_lock_screen_dismissed_call_count_++;
73 }
74
75 void FakeSessionManagerClient::RetrieveActiveSessions(
76       const ActiveSessionsCallback& callback) {
77   base::MessageLoop::current()->PostTask(
78       FROM_HERE, base::Bind(callback, user_sessions_, true));
79 }
80
81 void FakeSessionManagerClient::RetrieveDevicePolicy(
82     const RetrievePolicyCallback& callback) {
83   base::MessageLoop::current()->PostTask(FROM_HERE,
84                                          base::Bind(callback, device_policy_));
85 }
86
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]));
92 }
93
94 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
95     const std::string& username) {
96   return user_policies_[username];
97 }
98
99 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
100     const std::string& account_id,
101     const RetrievePolicyCallback& callback) {
102   base::MessageLoop::current()->PostTask(
103       FROM_HERE,
104       base::Bind(callback, device_local_account_policy_[account_id]));
105 }
106
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));
113 }
114
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));
121 }
122
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));
129 }
130
131 void FakeSessionManagerClient::SetFlagsForUser(
132     const std::string& username,
133     const std::vector<std::string>& flags) {
134 }
135
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_));
140 }
141
142 const std::string& FakeSessionManagerClient::device_policy() const {
143   return device_policy_;
144 }
145
146 void FakeSessionManagerClient::set_device_policy(
147     const std::string& policy_blob) {
148   device_policy_ = policy_blob;
149 }
150
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;
156 }
157
158 void FakeSessionManagerClient::set_user_policy(const std::string& username,
159                                                const std::string& policy_blob) {
160   user_policies_[username] = policy_blob;
161 }
162
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();
169 }
170
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;
175 }
176
177 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
178   FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
179 }
180
181 }  // namespace chromeos