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