Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/chromeos/login/auth/online_attempt_host.cc

Issue 290483003: Tame the proliferation of UserContext constructors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/auth/online_attempt_host.h" 5 #include "chrome/browser/chromeos/login/auth/online_attempt_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "chrome/browser/chromeos/login/auth/auth_attempt_state.h" 9 #include "chrome/browser/chromeos/login/auth/auth_attempt_state.h"
10 #include "chrome/browser/chromeos/login/auth/online_attempt.h" 10 #include "chrome/browser/chromeos/login/auth/online_attempt.h"
11 #include "chrome/browser/chromeos/login/users/user.h" 11 #include "chrome/browser/chromeos/login/users/user.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "google_apis/gaia/gaia_auth_util.h"
15 14
16 namespace chromeos { 15 namespace chromeos {
17 16
18 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate) 17 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate)
19 : delegate_(delegate), weak_ptr_factory_(this) {} 18 : delegate_(delegate), weak_ptr_factory_(this) {}
20 19
21 OnlineAttemptHost::~OnlineAttemptHost() { 20 OnlineAttemptHost::~OnlineAttemptHost() {
22 Reset(); 21 Reset();
23 } 22 }
24 23
25 void OnlineAttemptHost::Check(Profile* profile, 24 void OnlineAttemptHost::Check(Profile* profile,
26 const UserContext& user_context) { 25 const UserContext& user_context) {
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
28 std::string attempt_hash = base::SHA1HashString( 27 std::string attempt_hash = base::SHA1HashString(
29 user_context.GetUserID() + "\n" + user_context.GetPassword()); 28 user_context.GetUserID() + "\n" + user_context.GetPassword());
30 if (attempt_hash != current_attempt_hash_) { 29 if (attempt_hash != current_attempt_hash_) {
31 Reset(); 30 Reset();
32 current_attempt_hash_ = attempt_hash; 31 current_attempt_hash_ = attempt_hash;
33 current_username_ = user_context.GetUserID(); 32 current_username_ = user_context.GetUserID();
34 33
35 state_.reset( 34 state_.reset(new AuthAttemptState(user_context,
36 new AuthAttemptState( 35 User::USER_TYPE_REGULAR,
37 UserContext(gaia::CanonicalizeEmail(user_context.GetUserID()), 36 false, // unlock
38 user_context.GetPassword(), 37 false, // online_complete
39 user_context.GetAuthCode()), 38 false)); // user_is_new
40 std::string(), // login_token 39 online_attempt_.reset(new OnlineAttempt(state_.get(), this));
41 std::string(), // login_captcha
42 User::USER_TYPE_REGULAR,
43 false)); // user_is_new.
44 online_attempt_.reset(new OnlineAttempt(state_.get(),
45 this));
46 online_attempt_->Initiate(profile); 40 online_attempt_->Initiate(profile);
47 } 41 }
48 } 42 }
49 43
50 void OnlineAttemptHost::Reset() { 44 void OnlineAttemptHost::Reset() {
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
52 online_attempt_.reset(NULL); 46 online_attempt_.reset(NULL);
53 current_attempt_hash_.clear(); 47 current_attempt_hash_.clear();
54 current_username_.clear(); 48 current_username_.clear();
55 } 49 }
(...skipping 11 matching lines...) Expand all
67 } 61 }
68 } 62 }
69 63
70 void OnlineAttemptHost::ResolveOnUIThread(bool success) { 64 void OnlineAttemptHost::ResolveOnUIThread(bool success) {
71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
72 delegate_->OnChecked(current_username_, success); 66 delegate_->OnChecked(current_username_, success);
73 Reset(); 67 Reset();
74 } 68 }
75 69
76 } // namespace chromeos 70 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698