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

Side by Side Diff: chrome/browser/signin/profile_oauth2_token_service.cc

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed code review feedback. Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/signin/profile_oauth2_token_service.h" 5 #include "chrome/browser/signin/profile_oauth2_token_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 last_auth_error_(GoogleServiceAuthError::NONE) { 61 last_auth_error_(GoogleServiceAuthError::NONE) {
62 } 62 }
63 63
64 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() { 64 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {
65 DCHECK(!signin_global_error_.get()) << 65 DCHECK(!signin_global_error_.get()) <<
66 "ProfileOAuth2TokenService::Initialize called but not " 66 "ProfileOAuth2TokenService::Initialize called but not "
67 "ProfileOAuth2TokenService::Shutdown"; 67 "ProfileOAuth2TokenService::Shutdown";
68 } 68 }
69 69
70 void ProfileOAuth2TokenService::Initialize(Profile* profile) { 70 void ProfileOAuth2TokenService::Initialize(Profile* profile) {
71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
72
73 DCHECK(profile); 71 DCHECK(profile);
74 DCHECK(!profile_); 72 DCHECK(!profile_);
75 profile_ = profile; 73 profile_ = profile;
76 74
77 signin_global_error_.reset(new SigninGlobalError(profile)); 75 signin_global_error_.reset(new SigninGlobalError(profile));
78 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 76 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
79 signin_global_error_.get()); 77 signin_global_error_.get());
80 signin_global_error_->AddProvider(this); 78 signin_global_error_->AddProvider(this);
81 79
82 content::Source<TokenService> token_service_source( 80 content::Source<TokenService> token_service_source(
83 TokenServiceFactory::GetForProfile(profile)); 81 TokenServiceFactory::GetForProfile(profile));
84 registrar_.Add(this, 82 registrar_.Add(this,
85 chrome::NOTIFICATION_TOKENS_CLEARED, 83 chrome::NOTIFICATION_TOKENS_CLEARED,
86 token_service_source); 84 token_service_source);
87 registrar_.Add(this, 85 registrar_.Add(this,
88 chrome::NOTIFICATION_TOKEN_AVAILABLE, 86 chrome::NOTIFICATION_TOKEN_AVAILABLE,
89 token_service_source); 87 token_service_source);
90 registrar_.Add(this, 88 registrar_.Add(this,
91 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, 89 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
92 token_service_source); 90 token_service_source);
93 } 91 }
94 92
95 void ProfileOAuth2TokenService::Shutdown() { 93 void ProfileOAuth2TokenService::Shutdown() {
94 DCHECK(profile_) << "Shutdown() called without matching call to Initialize()";
96 CancelAllRequests(); 95 CancelAllRequests();
97 signin_global_error_->RemoveProvider(this); 96 signin_global_error_->RemoveProvider(this);
98 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 97 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
99 signin_global_error_.get()); 98 signin_global_error_.get());
100 signin_global_error_.reset(); 99 signin_global_error_.reset();
101 } 100 }
102 101
103 std::string ProfileOAuth2TokenService::GetRefreshToken() { 102 std::string ProfileOAuth2TokenService::GetRefreshToken() {
104 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 103 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
105 if (!token_service || !token_service->HasOAuthLoginToken()) { 104 if (!token_service || !token_service->HasOAuthLoginToken()) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 314 }
316 } 315 }
317 316
318 if (!old_login_token.empty() && 317 if (!old_login_token.empty() &&
319 refresh_tokens_.count(GetAccountId(profile_)) == 0) { 318 refresh_tokens_.count(GetAccountId(profile_)) == 0) {
320 UpdateCredentials(GetAccountId(profile_), old_login_token); 319 UpdateCredentials(GetAccountId(profile_), old_login_token);
321 } 320 }
322 321
323 FireRefreshTokensLoaded(); 322 FireRefreshTokensLoaded();
324 } 323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698