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
3 // found in the LICENSE file.
5 #include "chrome/browser/automation/automation_event_observers.h"
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/chromeos/login/existing_user_controller.h"
9 using chromeos::ExistingUserController
;
11 LoginEventObserver::LoginEventObserver(
12 AutomationEventQueue
* event_queue
,
13 AutomationProvider
* automation
)
14 : AutomationEventObserver(event_queue
, false),
15 automation_(automation
->AsWeakPtr()) {
16 ExistingUserController
* controller
=
17 ExistingUserController::current_controller();
19 controller
->set_login_status_consumer(this);
22 LoginEventObserver::~LoginEventObserver() {}
24 void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure
& error
) {
25 VLOG(1) << "Login failed, error=" << error
.GetErrorString();
26 _NotifyLoginEvent(error
.GetErrorString());
29 void LoginEventObserver::OnLoginSuccess(
30 const chromeos::UserContext
& user_context
) {
31 // Profile changes after login. Ensure AutomationProvider refers to
34 automation_
->set_profile(
35 g_browser_process
->profile_manager()->GetLastUsedProfile());
37 VLOG(1) << "Successfully logged in.";
38 _NotifyLoginEvent(std::string());
41 void LoginEventObserver::_NotifyLoginEvent(const std::string
& error_string
) {
42 base::DictionaryValue
* dict
= new base::DictionaryValue
;
43 dict
->SetString("type", "login_event");
44 if (error_string
.length())
45 dict
->SetString("error_string", error_string
);
47 ExistingUserController
* controller
=
48 ExistingUserController::current_controller();
50 controller
->set_login_status_consumer(NULL
);