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 "content/public/browser/notification_service.h" | |
5 #include "chrome/browser/automation/automation_event_observers.h" | 6 #include "chrome/browser/automation/automation_event_observers.h" |
6 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 8 #include "chrome/browser/chromeos/login/existing_user_controller.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); |
18 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | |
19 content::NotificationService::AllBrowserContextsAndSources()); | |
17 } | 20 } |
18 | 21 |
19 LoginEventObserver::~LoginEventObserver() {} | 22 LoginEventObserver::~LoginEventObserver() {} |
20 | 23 |
21 void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) { | 24 void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) { |
22 _NotifyLoginEvent(error.GetErrorString()); | 25 _NotifyLoginEvent(error.GetErrorString()); |
23 } | 26 } |
24 | 27 |
25 void LoginEventObserver::OnLoginSuccess(const std::string& username, | 28 void LoginEventObserver::OnLoginSuccess(const std::string& username, |
26 const std::string& password, | 29 const std::string& password, |
27 bool pending_requests, | 30 bool pending_requests, |
28 bool using_oauth) { | 31 bool using_oauth) { |
29 // Profile changes after login. Ensure AutomationProvider refers to | 32 // Profile changes after login. Ensure AutomationProvider refers to |
30 // the correct one. | 33 // the correct one. |
31 if (automation_) { | 34 if (automation_) { |
32 automation_->set_profile( | 35 automation_->set_profile( |
33 g_browser_process->profile_manager()->GetLastUsedProfile()); | 36 g_browser_process->profile_manager()->GetLastUsedProfile()); |
34 } | 37 } |
craigdh
2012/09/07 16:30:05
Log that the login success event occurred (this co
Nirnimesh
2012/09/11 00:28:20
Done.
| |
35 _NotifyLoginEvent(std::string()); | |
36 } | 38 } |
37 | 39 |
40 void LoginEventObserver::Observe( | |
41 int type, | |
42 const content::NotificationSource& source, | |
43 const content::NotificationDetails& details) { | |
44 if (type == content::NOTIFICATION_LOAD_STOP) { | |
45 _NotifyLoginEvent(std::string()); | |
46 } | |
47 } | |
48 | |
49 | |
38 void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) { | 50 void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) { |
39 DictionaryValue* dict = new DictionaryValue; | 51 DictionaryValue* dict = new DictionaryValue; |
40 dict->SetString("type", "login_event"); | 52 dict->SetString("type", "login_event"); |
41 if (error_string.length()) | 53 if (error_string.length()) |
42 dict->SetString("error_string", error_string); | 54 dict->SetString("error_string", error_string); |
43 NotifyEvent(dict); | 55 NotifyEvent(dict); |
44 controller_->set_login_status_consumer(NULL); | 56 controller_->set_login_status_consumer(NULL); |
45 RemoveIfDone(); | 57 RemoveIfDone(); |
46 } | 58 } |
OLD | NEW |