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
53
54
55
56
57
58
59
|
// 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"
#include "content/public/browser/notification_service.h"
LoginEventObserver::LoginEventObserver(
AutomationEventQueue* event_queue,
chromeos::ExistingUserController* controller,
AutomationProvider* automation)
: AutomationEventObserver(event_queue, false),
controller_(controller),
automation_(automation->AsWeakPtr()) {
controller_->set_login_status_consumer(this);
}
LoginEventObserver::~LoginEventObserver() {}
void LoginEventObserver::OnLoginFailure(const chromeos::LoginFailure& error) {
_NotifyLoginEvent(error.GetErrorString());
}
void LoginEventObserver::OnLoginSuccess(const std::string& username,
const std::string& password,
bool pending_requests,
bool using_oauth) {
// 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. Waiting for a page to load";
registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllBrowserContextsAndSources());
}
void LoginEventObserver::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_LOAD_STOP) {
VLOG(1) << "Page load done.";
_NotifyLoginEvent(std::string());
}
}
void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) {
DictionaryValue* dict = new DictionaryValue;
dict->SetString("type", "login_event");
if (error_string.length())
dict->SetString("error_string", error_string);
NotifyEvent(dict);
controller_->set_login_status_consumer(NULL);
RemoveIfDone();
}
|