OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/automation/automation_event_observers.h" | 5 #include "chrome/browser/automation/automation_event_observers.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 7 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 8 #include "content/public/browser/notification_service.h" |
8 | 9 |
9 LoginEventObserver::LoginEventObserver( | 10 LoginEventObserver::LoginEventObserver( |
10 AutomationEventQueue* event_queue, | 11 AutomationEventQueue* event_queue, |
11 chromeos::ExistingUserController* controller, | 12 chromeos::ExistingUserController* controller, |
12 AutomationProvider* automation) | 13 AutomationProvider* automation) |
13 : AutomationEventObserver(event_queue, false), | 14 : AutomationEventObserver(event_queue, false), |
14 controller_(controller), | 15 controller_(controller), |
15 automation_(automation->AsWeakPtr()) { | 16 automation_(automation->AsWeakPtr()) { |
16 controller_->set_login_status_consumer(this); | 17 controller_->set_login_status_consumer(this); |
17 } | 18 } |
18 | 19 |
19 LoginEventObserver::~LoginEventObserver() {} | 20 LoginEventObserver::~LoginEventObserver() {} |
20 | 21 |
21 void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) { | 22 void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) { |
22 _NotifyLoginEvent(error.GetErrorString()); | 23 _NotifyLoginEvent(error.GetErrorString()); |
23 } | 24 } |
24 | 25 |
25 void LoginEventObserver::OnLoginSuccess(const std::string& username, | 26 void LoginEventObserver::OnLoginSuccess(const std::string& username, |
26 const std::string& password, | 27 const std::string& password, |
27 bool pending_requests, | 28 bool pending_requests, |
28 bool using_oauth) { | 29 bool using_oauth) { |
29 // Profile changes after login. Ensure AutomationProvider refers to | 30 // Profile changes after login. Ensure AutomationProvider refers to |
30 // the correct one. | 31 // the correct one. |
31 if (automation_) { | 32 if (automation_) { |
32 automation_->set_profile( | 33 automation_->set_profile( |
33 g_browser_process->profile_manager()->GetLastUsedProfile()); | 34 g_browser_process->profile_manager()->GetLastUsedProfile()); |
34 } | 35 } |
35 _NotifyLoginEvent(std::string()); | 36 VLOG(1) << "Successfully logged in. Waiting for a page to load"; |
| 37 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 38 content::NotificationService::AllBrowserContextsAndSources()); |
| 39 } |
| 40 |
| 41 void LoginEventObserver::Observe( |
| 42 int type, |
| 43 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) { |
| 45 if (type == content::NOTIFICATION_LOAD_STOP) { |
| 46 VLOG(1) << "Page load done."; |
| 47 _NotifyLoginEvent(std::string()); |
| 48 } |
36 } | 49 } |
37 | 50 |
38 void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) { | 51 void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) { |
39 DictionaryValue* dict = new DictionaryValue; | 52 DictionaryValue* dict = new DictionaryValue; |
40 dict->SetString("type", "login_event"); | 53 dict->SetString("type", "login_event"); |
41 if (error_string.length()) | 54 if (error_string.length()) |
42 dict->SetString("error_string", error_string); | 55 dict->SetString("error_string", error_string); |
43 NotifyEvent(dict); | 56 NotifyEvent(dict); |
44 controller_->set_login_status_consumer(NULL); | 57 controller_->set_login_status_consumer(NULL); |
45 RemoveIfDone(); | 58 RemoveIfDone(); |
46 } | 59 } |
OLD | NEW |