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 { |
40 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 38 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
41 BrowserThread::PostTask( | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
42 BrowserThread::UI, FROM_HERE, | 40 session_connection_ = chromeos::MonitorSession(&Handler, this); |
43 NewRunnableMethod(this, &LoginLibraryImpl::EmitLoginPromptReady)); | 41 } |
44 return; | 42 |
45 } | 43 virtual void EmitLoginPromptReady() OVERRIDE { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
46 chromeos::EmitLoginPromptReady(); | 45 chromeos::EmitLoginPromptReady(); |
47 } | 46 } |
48 | 47 |
49 void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { | 48 virtual void RequestRetrievePolicy( |
| 49 RetrievePolicyCallback callback, void* delegate) OVERRIDE { |
50 DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()"; | 50 DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()"; |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
52 chromeos::RetrievePolicy(callback, delegate); | 52 chromeos::RetrievePolicy(callback, delegate); |
53 } | 53 } |
54 | 54 |
55 void RequestStorePolicy(const std::string& policy, | 55 virtual void RequestStorePolicy(const std::string& policy, |
56 StorePolicyCallback callback, | 56 StorePolicyCallback callback, |
57 void* delegate) { | 57 void* delegate) OVERRIDE { |
58 DCHECK(callback) << "must provide a callback to StorePolicy()"; | 58 DCHECK(callback) << "must provide a callback to StorePolicy()"; |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate); | 60 chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate); |
61 } | 61 } |
62 | 62 |
63 bool StartSession(const std::string& user_email, | 63 virtual bool StartSession( |
64 const std::string& unique_id /* unused */) { | 64 const std::string& user_email, |
| 65 const std::string& unique_id /* unused */) OVERRIDE { |
65 // only pass unique_id through once we use it for something. | 66 // only pass unique_id through once we use it for something. |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
67 return chromeos::StartSession(user_email.c_str(), ""); | 68 return chromeos::StartSession(user_email.c_str(), ""); |
68 } | 69 } |
69 | 70 |
70 bool StopSession(const std::string& unique_id /* unused */) { | 71 virtual bool StopSession(const std::string& unique_id /* unused */) OVERRIDE { |
71 // only pass unique_id through once we use it for something. | 72 // only pass unique_id through once we use it for something. |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
73 return chromeos::StopSession(""); | 74 return chromeos::StopSession(""); |
74 } | 75 } |
75 | 76 |
76 bool RestartEntd() { | 77 virtual bool RestartEntd() OVERRIDE { |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
78 return chromeos::RestartEntd(); | 79 return chromeos::RestartEntd(); |
79 } | 80 } |
80 | 81 |
81 bool RestartJob(int pid, const std::string& command_line) { | 82 virtual bool RestartJob(int pid, const std::string& command_line) OVERRIDE { |
82 if (job_restart_request_) { | 83 if (job_restart_request_) { |
83 NOTREACHED(); | 84 NOTREACHED(); |
84 return false; | 85 return false; |
85 } | 86 } |
86 job_restart_request_ = new JobRestartRequest(pid, command_line); | 87 job_restart_request_ = new JobRestartRequest(pid, command_line); |
87 return true; | 88 return true; |
88 } | 89 } |
89 | 90 |
90 private: | 91 private: |
91 class JobRestartRequest | 92 class JobRestartRequest |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 break; | 171 break; |
171 case PropertyOpFailure: | 172 case PropertyOpFailure: |
172 self->CompletePropertyOp(false); | 173 self->CompletePropertyOp(false); |
173 break; | 174 break; |
174 default: | 175 default: |
175 NOTREACHED(); | 176 NOTREACHED(); |
176 break; | 177 break; |
177 } | 178 } |
178 } | 179 } |
179 | 180 |
180 void Init() { | |
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
182 session_connection_ = chromeos::MonitorSession(&Handler, this); | |
183 } | |
184 | |
185 void CompleteSetOwnerKey(bool value) { | 181 void CompleteSetOwnerKey(bool value) { |
186 VLOG(1) << "Owner key generation: " << (value ? "success" : "fail"); | 182 VLOG(1) << "Owner key generation: " << (value ? "success" : "fail"); |
187 int result = | 183 int result = |
188 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 184 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
189 if (!value) | 185 if (!value) |
190 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED; | 186 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED; |
191 | 187 |
192 // 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 |
193 // that we're done with this attempt. | 189 // that we're done with this attempt. |
194 NotificationService::current()->Notify(result, | 190 NotificationService::current()->Notify(result, |
(...skipping 24 matching lines...) Expand all Loading... |
219 JobRestartRequest* job_restart_request_; | 215 JobRestartRequest* job_restart_request_; |
220 | 216 |
221 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); | 217 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); |
222 }; | 218 }; |
223 | 219 |
224 class LoginLibraryStubImpl : public LoginLibrary { | 220 class LoginLibraryStubImpl : public LoginLibrary { |
225 public: | 221 public: |
226 LoginLibraryStubImpl() {} | 222 LoginLibraryStubImpl() {} |
227 virtual ~LoginLibraryStubImpl() {} | 223 virtual ~LoginLibraryStubImpl() {} |
228 | 224 |
229 void EmitLoginPromptReady() { } | 225 virtual void Init() OVERRIDE {} |
230 void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { | 226 |
| 227 virtual void EmitLoginPromptReady() OVERRIDE {} |
| 228 virtual void RequestRetrievePolicy( |
| 229 RetrievePolicyCallback callback, void* delegate) OVERRIDE { |
231 callback(delegate, "", 0); | 230 callback(delegate, "", 0); |
232 } | 231 } |
233 void RequestStorePolicy(const std::string& policy, | 232 virtual void RequestStorePolicy(const std::string& policy, |
234 StorePolicyCallback callback, | 233 StorePolicyCallback callback, |
235 void* delegate) { | 234 void* delegate) OVERRIDE { |
236 callback(delegate, true); | 235 callback(delegate, true); |
237 } | 236 } |
238 bool StartSession(const std::string& user_email, | 237 virtual bool StartSession( |
239 const std::string& unique_id /* unused */) { return true; } | 238 const std::string& user_email, |
240 bool StopSession(const std::string& unique_id /* unused */) { return true; } | 239 const std::string& unique_id /* unused */) OVERRIDE { |
241 bool RestartJob(int pid, const std::string& command_line) { return true; } | 240 return true; |
242 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; } |
243 | 249 |
244 private: | 250 private: |
245 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); | 251 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); |
246 }; | 252 }; |
247 | 253 |
248 // static | 254 // static |
249 LoginLibrary* LoginLibrary::GetImpl(bool stub) { | 255 LoginLibrary* LoginLibrary::GetImpl(bool stub) { |
| 256 LoginLibrary* impl; |
250 if (stub) | 257 if (stub) |
251 return new LoginLibraryStubImpl(); | 258 impl = new LoginLibraryStubImpl(); |
252 else | 259 else |
253 return new LoginLibraryImpl(); | 260 impl = new LoginLibraryImpl(); |
| 261 impl->Init(); |
| 262 return impl; |
254 } | 263 } |
255 | 264 |
256 } // namespace chromeos | 265 } // namespace chromeos |
257 | |
258 // Needed for NewRunnableMethod() call above. | |
259 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::LoginLibraryImpl); | |
OLD | NEW |