Update To 11.40.268.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     : start_device_wipe_call_count_(0),
17       notify_lock_screen_shown_call_count_(0),
18       notify_lock_screen_dismissed_call_count_(0) {
19 }
20
21 FakeSessionManagerClient::~FakeSessionManagerClient() {
22 }
23
24 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
25 }
26
27 void FakeSessionManagerClient::SetStubDelegate(StubDelegate* delegate) {
28 }
29
30 void FakeSessionManagerClient::AddObserver(Observer* observer) {
31   observers_.AddObserver(observer);
32 }
33
34 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
35   observers_.RemoveObserver(observer);
36 }
37
38 bool FakeSessionManagerClient::HasObserver(Observer* observer) {
39   return observers_.HasObserver(observer);
40 }
41
42 void FakeSessionManagerClient::EmitLoginPromptVisible() {
43 }
44
45 void FakeSessionManagerClient::RestartJob(int pid,
46                                           const std::string& command_line) {
47 }
48
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;
54 }
55
56 void FakeSessionManagerClient::StopSession() {
57 }
58
59 void FakeSessionManagerClient::NotifySupervisedUserCreationStarted() {
60 }
61
62 void FakeSessionManagerClient::NotifySupervisedUserCreationFinished() {
63 }
64
65 void FakeSessionManagerClient::StartDeviceWipe() {
66   start_device_wipe_call_count_++;
67 }
68
69 void FakeSessionManagerClient::RequestLockScreen() {
70 }
71
72 void FakeSessionManagerClient::NotifyLockScreenShown() {
73   notify_lock_screen_shown_call_count_++;
74 }
75
76 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
77   notify_lock_screen_dismissed_call_count_++;
78 }
79
80 void FakeSessionManagerClient::RetrieveActiveSessions(
81       const ActiveSessionsCallback& callback) {
82   base::MessageLoop::current()->PostTask(
83       FROM_HERE, base::Bind(callback, user_sessions_, true));
84 }
85
86 void FakeSessionManagerClient::RetrieveDevicePolicy(
87     const RetrievePolicyCallback& callback) {
88   base::MessageLoop::current()->PostTask(FROM_HERE,
89                                          base::Bind(callback, device_policy_));
90 }
91
92 void FakeSessionManagerClient::RetrievePolicyForUser(
93     const std::string& username,
94     const RetrievePolicyCallback& callback) {
95   base::MessageLoop::current()->PostTask(
96       FROM_HERE, base::Bind(callback, user_policies_[username]));
97 }
98
99 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
100     const std::string& username) {
101   return user_policies_[username];
102 }
103
104 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
105     const std::string& account_id,
106     const RetrievePolicyCallback& callback) {
107   base::MessageLoop::current()->PostTask(
108       FROM_HERE,
109       base::Bind(callback, device_local_account_policy_[account_id]));
110 }
111
112 void FakeSessionManagerClient::StoreDevicePolicy(
113     const std::string& policy_blob,
114     const StorePolicyCallback& callback) {
115   device_policy_ = policy_blob;
116   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
117   FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(true));
118 }
119
120 void FakeSessionManagerClient::StorePolicyForUser(
121     const std::string& username,
122     const std::string& policy_blob,
123     const StorePolicyCallback& callback) {
124   user_policies_[username] = policy_blob;
125   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
126 }
127
128 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
129     const std::string& account_id,
130     const std::string& policy_blob,
131     const StorePolicyCallback& callback) {
132   device_local_account_policy_[account_id] = policy_blob;
133   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
134 }
135
136 void FakeSessionManagerClient::SetFlagsForUser(
137     const std::string& username,
138     const std::vector<std::string>& flags) {
139 }
140
141 void FakeSessionManagerClient::GetServerBackedStateKeys(
142     const StateKeysCallback& callback) {
143   base::MessageLoop::current()->PostTask(
144       FROM_HERE, base::Bind(callback, server_backed_state_keys_));
145 }
146
147 const std::string& FakeSessionManagerClient::device_policy() const {
148   return device_policy_;
149 }
150
151 void FakeSessionManagerClient::set_device_policy(
152     const std::string& policy_blob) {
153   device_policy_ = policy_blob;
154 }
155
156 const std::string& FakeSessionManagerClient::user_policy(
157     const std::string& username) const {
158   std::map<std::string, std::string>::const_iterator it =
159       user_policies_.find(username);
160   return it == user_policies_.end() ? base::EmptyString() : it->second;
161 }
162
163 void FakeSessionManagerClient::set_user_policy(const std::string& username,
164                                                const std::string& policy_blob) {
165   user_policies_[username] = policy_blob;
166 }
167
168 const std::string& FakeSessionManagerClient::device_local_account_policy(
169     const std::string& account_id) const {
170   std::map<std::string, std::string>::const_iterator entry =
171       device_local_account_policy_.find(account_id);
172   return entry != device_local_account_policy_.end() ? entry->second
173                                                      : base::EmptyString();
174 }
175
176 void FakeSessionManagerClient::set_device_local_account_policy(
177     const std::string& account_id,
178     const std::string& policy_blob) {
179   device_local_account_policy_[account_id] = policy_blob;
180 }
181
182 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
183   FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
184 }
185
186 }  // namespace chromeos