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

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: Merge with ToT 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()) {
106 return std::string(); 105 return std::string();
107 } 106 }
108 return token_service->GetOAuth2LoginRefreshToken(); 107 return token_service->GetOAuth2LoginRefreshToken();
109 } 108 }
110 109
110 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
111 return profile_->GetRequestContext();
112 }
113
111 void ProfileOAuth2TokenService::UpdateAuthError( 114 void ProfileOAuth2TokenService::UpdateAuthError(
112 const GoogleServiceAuthError& error) { 115 const GoogleServiceAuthError& error) {
113 // Do not report connection errors as these are not actually auth errors. 116 // Do not report connection errors as these are not actually auth errors.
114 // We also want to avoid masking a "real" auth error just because we 117 // We also want to avoid masking a "real" auth error just because we
115 // subsequently get a transient network error. 118 // subsequently get a transient network error.
116 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) 119 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED)
117 return; 120 return;
118 121
119 if (error.state() != last_auth_error_.state()) { 122 if (error.state() != last_auth_error_.state()) {
120 last_auth_error_ = error; 123 last_auth_error_ = error;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 default: 160 default:
158 NOTREACHED() << "Invalid notification type=" << type; 161 NOTREACHED() << "Invalid notification type=" << type;
159 break; 162 break;
160 } 163 }
161 } 164 }
162 165
163 GoogleServiceAuthError ProfileOAuth2TokenService::GetAuthStatus() const { 166 GoogleServiceAuthError ProfileOAuth2TokenService::GetAuthStatus() const {
164 return last_auth_error_; 167 return last_auth_error_;
165 } 168 }
166 169
167 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
168 return profile_->GetRequestContext();
169 }
170
171 void ProfileOAuth2TokenService::RegisterCacheEntry( 170 void ProfileOAuth2TokenService::RegisterCacheEntry(
172 const std::string& refresh_token, 171 const std::string& refresh_token,
173 const ScopeSet& scopes, 172 const ScopeSet& scopes,
174 const std::string& access_token, 173 const std::string& access_token,
175 const base::Time& expiration_date) { 174 const base::Time& expiration_date) {
176 if (ShouldCacheForRefreshToken(TokenServiceFactory::GetForProfile(profile_), 175 if (ShouldCacheForRefreshToken(TokenServiceFactory::GetForProfile(profile_),
177 refresh_token)) { 176 refresh_token)) {
178 OAuth2TokenService::RegisterCacheEntry(refresh_token, 177 OAuth2TokenService::RegisterCacheEntry(refresh_token,
179 scopes, 178 scopes,
180 access_token, 179 access_token,
(...skipping 134 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
« no previous file with comments | « chrome/browser/signin/profile_oauth2_token_service.h ('k') | chrome/browser/signin/profile_oauth2_token_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698