OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/login_library.h" | 5 #include "chrome/browser/chromeos/cros/login_library.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "chrome/browser/chromeos/login/signed_settings.h" | 12 #include "chrome/browser/chromeos/login/signed_settings.h" |
13 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | 13 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
18 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
19 | 19 |
20 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 LoginLibrary::~LoginLibrary() {} | 23 LoginLibrary::~LoginLibrary() {} |
24 | 24 |
25 class LoginLibraryImpl : public LoginLibrary { | 25 class LoginLibraryImpl : public LoginLibrary { |
26 public: | 26 public: |
27 LoginLibraryImpl() : job_restart_request_(NULL) { | 27 LoginLibraryImpl() : job_restart_request_(NULL) { |
28 CHECK(CrosLibrary::Get() && CrosLibrary::Get()->libcros_loaded()); | |
29 Init(); | |
30 } | 28 } |
31 | 29 |
32 virtual ~LoginLibraryImpl() { | 30 virtual ~LoginLibraryImpl() { |
33 if (session_connection_) { | 31 if (session_connection_) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 chromeos::DisconnectSession(session_connection_); | 33 chromeos::DisconnectSession(session_connection_); |
36 } | 34 } |
37 } | 35 } |
38 | 36 |
39 void EmitLoginPromptReady() { | 37 virtual void Init() OVERRIDE { |
| 38 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 40 session_connection_ = chromeos::MonitorSession(&Handler, this); |
| 41 } |
| 42 |
| 43 virtual void EmitLoginPromptReady() OVERRIDE { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
41 chromeos::EmitLoginPromptReady(); | 45 chromeos::EmitLoginPromptReady(); |
42 } | 46 } |
43 | 47 |
44 void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { | 48 virtual void RequestRetrievePolicy( |
| 49 RetrievePolicyCallback callback, void* delegate) OVERRIDE { |
45 DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()"; | 50 DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()"; |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 chromeos::RetrievePolicy(callback, delegate); | 52 chromeos::RetrievePolicy(callback, delegate); |
48 } | 53 } |
49 | 54 |
50 void RequestStorePolicy(const std::string& policy, | 55 virtual void RequestStorePolicy(const std::string& policy, |
51 StorePolicyCallback callback, | 56 StorePolicyCallback callback, |
52 void* delegate) { | 57 void* delegate) OVERRIDE { |
53 DCHECK(callback) << "must provide a callback to StorePolicy()"; | 58 DCHECK(callback) << "must provide a callback to StorePolicy()"; |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
55 chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate); | 60 chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate); |
56 } | 61 } |
57 | 62 |
58 bool StartSession(const std::string& user_email, | 63 virtual bool StartSession( |
59 const std::string& unique_id /* unused */) { | 64 const std::string& user_email, |
| 65 const std::string& unique_id /* unused */) OVERRIDE { |
60 // only pass unique_id through once we use it for something. | 66 // only pass unique_id through once we use it for something. |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
62 return chromeos::StartSession(user_email.c_str(), ""); | 68 return chromeos::StartSession(user_email.c_str(), ""); |
63 } | 69 } |
64 | 70 |
65 bool StopSession(const std::string& unique_id /* unused */) { | 71 virtual bool StopSession(const std::string& unique_id /* unused */) OVERRIDE { |
66 // only pass unique_id through once we use it for something. | 72 // only pass unique_id through once we use it for something. |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
68 return chromeos::StopSession(""); | 74 return chromeos::StopSession(""); |
69 } | 75 } |
70 | 76 |
71 bool RestartEntd() { | 77 virtual bool RestartEntd() OVERRIDE { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
73 return chromeos::RestartEntd(); | 79 return chromeos::RestartEntd(); |
74 } | 80 } |
75 | 81 |
76 bool RestartJob(int pid, const std::string& command_line) { | 82 virtual bool RestartJob(int pid, const std::string& command_line) OVERRIDE { |
77 if (job_restart_request_) { | 83 if (job_restart_request_) { |
78 NOTREACHED(); | 84 NOTREACHED(); |
79 return false; | 85 return false; |
80 } | 86 } |
81 job_restart_request_ = new JobRestartRequest(pid, command_line); | 87 job_restart_request_ = new JobRestartRequest(pid, command_line); |
82 return true; | 88 return true; |
83 } | 89 } |
84 | 90 |
85 private: | 91 private: |
86 class JobRestartRequest | 92 class JobRestartRequest |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 break; | 171 break; |
166 case PropertyOpFailure: | 172 case PropertyOpFailure: |
167 self->CompletePropertyOp(false); | 173 self->CompletePropertyOp(false); |
168 break; | 174 break; |
169 default: | 175 default: |
170 NOTREACHED(); | 176 NOTREACHED(); |
171 break; | 177 break; |
172 } | 178 } |
173 } | 179 } |
174 | 180 |
175 void Init() { | |
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
177 session_connection_ = chromeos::MonitorSession(&Handler, this); | |
178 } | |
179 | |
180 void CompleteSetOwnerKey(bool value) { | 181 void CompleteSetOwnerKey(bool value) { |
181 VLOG(1) << "Owner key generation: " << (value ? "success" : "fail"); | 182 VLOG(1) << "Owner key generation: " << (value ? "success" : "fail"); |
182 int result = | 183 int result = |
183 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 184 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
184 if (!value) | 185 if (!value) |
185 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED; | 186 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED; |
186 | 187 |
187 // Whether we exported the public key or not, send a notification indicating | 188 // Whether we exported the public key or not, send a notification indicating |
188 // that we're done with this attempt. | 189 // that we're done with this attempt. |
189 NotificationService::current()->Notify(result, | 190 NotificationService::current()->Notify(result, |
(...skipping 24 matching lines...) Expand all Loading... |
214 JobRestartRequest* job_restart_request_; | 215 JobRestartRequest* job_restart_request_; |
215 | 216 |
216 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); | 217 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); |
217 }; | 218 }; |
218 | 219 |
219 class LoginLibraryStubImpl : public LoginLibrary { | 220 class LoginLibraryStubImpl : public LoginLibrary { |
220 public: | 221 public: |
221 LoginLibraryStubImpl() {} | 222 LoginLibraryStubImpl() {} |
222 virtual ~LoginLibraryStubImpl() {} | 223 virtual ~LoginLibraryStubImpl() {} |
223 | 224 |
224 void EmitLoginPromptReady() { } | 225 virtual void Init() OVERRIDE {} |
225 void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { | 226 |
| 227 virtual void EmitLoginPromptReady() OVERRIDE {} |
| 228 virtual void RequestRetrievePolicy( |
| 229 RetrievePolicyCallback callback, void* delegate) OVERRIDE { |
226 callback(delegate, "", 0); | 230 callback(delegate, "", 0); |
227 } | 231 } |
228 void RequestStorePolicy(const std::string& policy, | 232 virtual void RequestStorePolicy(const std::string& policy, |
229 StorePolicyCallback callback, | 233 StorePolicyCallback callback, |
230 void* delegate) { | 234 void* delegate) OVERRIDE { |
231 callback(delegate, true); | 235 callback(delegate, true); |
232 } | 236 } |
233 bool StartSession(const std::string& user_email, | 237 virtual bool StartSession( |
234 const std::string& unique_id /* unused */) { return true; } | 238 const std::string& user_email, |
235 bool StopSession(const std::string& unique_id /* unused */) { return true; } | 239 const std::string& unique_id /* unused */) OVERRIDE { |
236 bool RestartJob(int pid, const std::string& command_line) { return true; } | 240 return true; |
237 bool RestartEntd() { return true; } | 241 } |
| 242 virtual bool StopSession(const std::string& unique_id /* unused */) OVERRIDE { |
| 243 return true; |
| 244 } |
| 245 virtual bool RestartJob(int pid, const std::string& command_line) OVERRIDE { |
| 246 return true; |
| 247 } |
| 248 virtual bool RestartEntd() OVERRIDE { return true; } |
238 | 249 |
239 private: | 250 private: |
240 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); | 251 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); |
241 }; | 252 }; |
242 | 253 |
243 // static | 254 // static |
244 LoginLibrary* LoginLibrary::GetImpl(bool stub) { | 255 LoginLibrary* LoginLibrary::GetImpl(bool stub) { |
| 256 LoginLibrary* impl; |
245 if (stub) | 257 if (stub) |
246 return new LoginLibraryStubImpl(); | 258 impl = new LoginLibraryStubImpl(); |
247 else | 259 else |
248 return new LoginLibraryImpl(); | 260 impl = new LoginLibraryImpl(); |
| 261 impl->Init(); |
| 262 return impl; |
249 } | 263 } |
250 | 264 |
251 } // namespace chromeos | 265 } // namespace chromeos |
252 | |
253 // Needed for NewRunnableMethod() call above. | |
254 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::LoginLibraryImpl); | |
OLD | NEW |