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/chromeos/login/login_performer.h" | 5 #include "chrome/browser/chromeos/login/login_performer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
13 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
14 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/boot_times_loader.h" | 16 #include "chrome/browser/chromeos/boot_times_loader.h" |
18 #include "chrome/browser/chromeos/login/login_utils.h" | 17 #include "chrome/browser/chromeos/login/login_utils.h" |
19 #include "chrome/browser/chromeos/login/screen_locker.h" | 18 #include "chrome/browser/chromeos/login/screen_locker.h" |
20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
21 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
22 #include "chrome/browser/policy/browser_policy_connector.h" | 21 #include "chrome/browser/policy/browser_policy_connector.h" |
23 #include "chrome/browser/policy/device_local_account_policy_service.h" | 22 #include "chrome/browser/policy/device_local_account_policy_service.h" |
24 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | |
29 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
30 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
31 #include "chromeos/dbus/session_manager_client.h" | 29 #include "chromeos/dbus/session_manager_client.h" |
32 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
34 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
36 #include "google_apis/gaia/gaia_auth_util.h" | 34 #include "google_apis/gaia/gaia_auth_util.h" |
37 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
38 #include "net/cookies/cookie_monster.h" | 36 #include "net/cookies/cookie_monster.h" |
(...skipping 14 matching lines...) Expand all Loading... |
53 | 51 |
54 LoginPerformer::LoginPerformer(Delegate* delegate) | 52 LoginPerformer::LoginPerformer(Delegate* delegate) |
55 : ALLOW_THIS_IN_INITIALIZER_LIST(online_attempt_host_(this)), | 53 : ALLOW_THIS_IN_INITIALIZER_LIST(online_attempt_host_(this)), |
56 last_login_failure_(LoginFailure::None()), | 54 last_login_failure_(LoginFailure::None()), |
57 delegate_(delegate), | 55 delegate_(delegate), |
58 password_changed_(false), | 56 password_changed_(false), |
59 password_changed_callback_count_(0), | 57 password_changed_callback_count_(0), |
60 screen_lock_requested_(false), | 58 screen_lock_requested_(false), |
61 initial_online_auth_pending_(false), | 59 initial_online_auth_pending_(false), |
62 auth_mode_(AUTH_MODE_INTERNAL), | 60 auth_mode_(AUTH_MODE_INTERNAL), |
63 using_oauth_( | |
64 !CommandLine::ForCurrentProcess()->HasSwitch( | |
65 switches::kSkipOAuthLogin)), | |
66 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 61 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
67 DCHECK(default_performer_ == NULL) | 62 DCHECK(default_performer_ == NULL) |
68 << "LoginPerformer should have only one instance."; | 63 << "LoginPerformer should have only one instance."; |
69 default_performer_ = this; | 64 default_performer_ = this; |
70 } | 65 } |
71 | 66 |
72 LoginPerformer::~LoginPerformer() { | 67 LoginPerformer::~LoginPerformer() { |
73 DVLOG(1) << "Deleting LoginPerformer"; | 68 DVLOG(1) << "Deleting LoginPerformer"; |
74 DCHECK(default_performer_ != NULL) << "Default instance should exist."; | 69 DCHECK(default_performer_ != NULL) << "Default instance should exist."; |
75 default_performer_ = NULL; | 70 default_performer_ = NULL; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // 0 - New regular user, login success offline and online. | 135 // 0 - New regular user, login success offline and online. |
141 // - or - | 136 // - or - |
142 // Existing regular user, login success offline and online, offline | 137 // Existing regular user, login success offline and online, offline |
143 // authentication took longer than online authentication. | 138 // authentication took longer than online authentication. |
144 // - or - | 139 // - or - |
145 // Public account user, login successful. | 140 // Public account user, login successful. |
146 // 1 - Existing regular user, login success offline only. | 141 // 1 - Existing regular user, login success offline only. |
147 UMA_HISTOGRAM_ENUMERATION("Login.SuccessReason", pending_requests, 2); | 142 UMA_HISTOGRAM_ENUMERATION("Login.SuccessReason", pending_requests, 2); |
148 | 143 |
149 VLOG(1) << "LoginSuccess, pending_requests " << pending_requests; | 144 VLOG(1) << "LoginSuccess, pending_requests " << pending_requests; |
150 if (delegate_) { | 145 DCHECK(delegate_); |
151 // After delegate_->OnLoginSuccess(...) is called, delegate_ releases | 146 // After delegate_->OnLoginSuccess(...) is called, delegate_ releases |
152 // LoginPerformer ownership. LP now manages it's lifetime on its own. | 147 // LoginPerformer ownership. LP now manages it's lifetime on its own. |
153 // 2 things could make it exist longer: | 148 // 2 things could make it exist longer: |
154 // 1. ScreenLock active (pending correct new password input) | 149 // 1. ScreenLock active (pending correct new password input) |
155 // 2. Pending online auth request. | 150 // 2. Pending online auth request. |
156 if (!pending_requests) | 151 if (!pending_requests) |
157 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 152 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
158 else | 153 else |
159 initial_online_auth_pending_ = true; | 154 initial_online_auth_pending_ = true; |
160 | 155 |
161 delegate_->OnLoginSuccess(username, | 156 delegate_->OnLoginSuccess(username, |
162 password, | 157 password, |
163 pending_requests, | 158 pending_requests, |
164 using_oauth); | 159 using_oauth); |
165 return; | |
166 } else { | |
167 // Online login has succeeded. | |
168 DCHECK(!pending_requests) | |
169 << "Pending request w/o delegate_ should not happen!"; | |
170 // It is not guaranted, that profile creation has been finished yet. So use | |
171 // async version here. | |
172 ProfileManager::CreateDefaultProfileAsync( | |
173 base::Bind(&LoginPerformer::OnProfileCreated, | |
174 weak_factory_.GetWeakPtr())); | |
175 } | |
176 } | |
177 | |
178 void LoginPerformer::OnProfileCreated( | |
179 Profile* profile, | |
180 Profile::CreateStatus status) { | |
181 CHECK(profile); | |
182 switch (status) { | |
183 case Profile::CREATE_STATUS_INITIALIZED: | |
184 break; | |
185 case Profile::CREATE_STATUS_CREATED: | |
186 return; | |
187 case Profile::CREATE_STATUS_FAIL: | |
188 default: | |
189 NOTREACHED(); | |
190 return; | |
191 } | |
192 | |
193 if (using_oauth_) | |
194 LoginUtils::Get()->StartTokenServices(profile); | |
195 | |
196 // Don't unlock screen if it was locked while we're waiting | |
197 // for initial online auth. | |
198 if (ScreenLocker::default_screen_locker() && | |
199 !initial_online_auth_pending_) { | |
200 DVLOG(1) << "Online login OK - unlocking screen."; | |
201 RequestScreenUnlock(); | |
202 // Do not delete itself just yet, wait for unlock. | |
203 // See ResolveScreenUnlocked(). | |
204 return; | |
205 } | |
206 initial_online_auth_pending_ = false; | |
207 // There's nothing else that's holding LP from deleting itself - | |
208 // no ScreenLock, no pending requests. | |
209 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
210 } | 160 } |
211 | 161 |
212 void LoginPerformer::OnOffTheRecordLoginSuccess() { | 162 void LoginPerformer::OnOffTheRecordLoginSuccess() { |
213 content::RecordAction( | 163 content::RecordAction( |
214 UserMetricsAction("Login_GuestLoginSuccess")); | 164 UserMetricsAction("Login_GuestLoginSuccess")); |
215 | 165 |
216 if (delegate_) | 166 if (delegate_) |
217 delegate_->OnOffTheRecordLoginSuccess(); | 167 delegate_->OnOffTheRecordLoginSuccess(); |
218 else | 168 else |
219 NOTREACHED(); | 169 NOTREACHED(); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 profile, | 509 profile, |
560 username_, | 510 username_, |
561 password_, | 511 password_, |
562 std::string(), | 512 std::string(), |
563 std::string())); | 513 std::string())); |
564 } | 514 } |
565 password_.clear(); | 515 password_.clear(); |
566 } | 516 } |
567 | 517 |
568 } // namespace chromeos | 518 } // namespace chromeos |
OLD | NEW |