blob: f5e180d38cc75abf07143e47d1779bb6c38c6805 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/automation/automation_event_observers.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
using chromeos::ExistingUserController;
LoginEventObserver::LoginEventObserver(
AutomationEventQueue* event_queue,
AutomationProvider* automation)
: AutomationEventObserver(event_queue, false),
automation_(automation->AsWeakPtr()) {
ExistingUserController* controller =
ExistingUserController::current_controller();
DCHECK(controller);
controller->set_login_status_consumer(this);
}
LoginEventObserver::~LoginEventObserver() {}
void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) {
VLOG(1) << "Login failed, error=" << error.GetErrorString();
_NotifyLoginEvent(error.GetErrorString());
}
void LoginEventObserver::OnLoginSuccess(
const chromeos::UserContext& user_context) {
// Profile changes after login. Ensure AutomationProvider refers to
// the correct one.
if (automation_) {
automation_->set_profile(
g_browser_process->profile_manager()->GetLastUsedProfile());
}
VLOG(1) << "Successfully logged in.";
_NotifyLoginEvent(std::string());
}
void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) {
base::DictionaryValue* dict = new base::DictionaryValue;
dict->SetString("type", "login_event");
if (error_string.length())
dict->SetString("error_string", error_string);
NotifyEvent(dict);
ExistingUserController* controller =
ExistingUserController::current_controller();
if (controller)
controller->set_login_status_consumer(NULL);
RemoveIfDone();
}
|