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

Side by Side Diff: components/signin/core/browser/profile_oauth2_token_service.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update for google_apis_unittests Created 5 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
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 "components/signin/core/browser/profile_oauth2_token_service.h" 5 #include "components/signin/core/browser/profile_oauth2_token_service.h"
6 6
7 #include "base/bind.h" 7 #include "google_apis/gaia/oauth2_token_service_delegate.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "base/time/time.h"
11 #include "components/signin/core/browser/signin_client.h"
12 #include "components/signin/core/browser/signin_error_controller.h"
13 #include "google_apis/gaia/gaia_auth_util.h"
14 #include "net/url_request/url_request_context_getter.h" 8 #include "net/url_request/url_request_context_getter.h"
15 9
16 ProfileOAuth2TokenService::ProfileOAuth2TokenService() 10 ProfileOAuth2TokenService::ProfileOAuth2TokenService(
17 : client_(NULL), 11 OAuth2TokenServiceDelegate* delegate)
18 signin_error_controller_(NULL) {} 12 : OAuth2TokenService(delegate) {
13 }
19 14
20 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {} 15 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {}
21 16
22 void ProfileOAuth2TokenService::Initialize(
23 SigninClient* client,
24 SigninErrorController* signin_error_controller) {
25 DCHECK(client);
26 DCHECK(!client_);
27 DCHECK(signin_error_controller);
28 DCHECK(!signin_error_controller_);
29 client_ = client;
30 signin_error_controller_ = signin_error_controller;
31 }
32
33 void ProfileOAuth2TokenService::Shutdown() { 17 void ProfileOAuth2TokenService::Shutdown() {
34 DCHECK(client_) << "Shutdown() called without matching call to Initialize()"; 18 CancelAllRequests();
35 } 19 GetDelegate()->Shutdown();
36
37 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
38 return NULL;
39 }
40
41 void ProfileOAuth2TokenService::UpdateAuthError(
42 const std::string& account_id,
43 const GoogleServiceAuthError& error) {
44 NOTREACHED();
45 }
46
47 void ProfileOAuth2TokenService::ValidateAccountId(
48 const std::string& account_id) const {
49 DCHECK(!account_id.empty());
50
51 // If the account is given as an email, make sure its a canonical email.
52 // Note that some tests don't use email strings as account id, and after
53 // the gaia id migration it won't be an email. So only check for
54 // canonicalization if the account_id is suspected to be an email.
55 if (account_id.find('@') != std::string::npos)
56 DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id);
57 }
58
59 std::vector<std::string> ProfileOAuth2TokenService::GetAccounts() {
60 NOTREACHED();
61 return std::vector<std::string>();
62 } 20 }
63 21
64 void ProfileOAuth2TokenService::LoadCredentials( 22 void ProfileOAuth2TokenService::LoadCredentials(
65 const std::string& primary_account_id) { 23 const std::string& primary_account_id) {
66 // Empty implementation by default. 24 CancelAllRequests();
25 GetDelegate()->LoadCredentials(primary_account_id);
Roger Tawa OOO till Jul 10th 2015/05/28 14:54:43 Do we really need to call CancelAllRequests() on l
gogerald1 2015/06/03 18:12:58 Done. Confirmed with chromeos guy
67 } 26 }
68 27
69 void ProfileOAuth2TokenService::UpdateCredentials( 28 void ProfileOAuth2TokenService::UpdateCredentials(
70 const std::string& account_id, 29 const std::string& account_id,
71 const std::string& refresh_token) { 30 const std::string& refresh_token) {
72 NOTREACHED(); 31 std::string present_refresh_token =
32 GetDelegate()->GetRefreshToken(account_id);
33 if (!present_refresh_token.empty() &&
34 present_refresh_token == refresh_token) {
35 CancelRequestsForAccount(account_id);
36 ClearCacheForAccount(account_id);
37 }
38 GetDelegate()->UpdateCredentials(account_id, refresh_token);
73 } 39 }
74 40
75 void ProfileOAuth2TokenService::RevokeAllCredentials() { 41 void ProfileOAuth2TokenService::RevokeCredentials(
76 // Empty implementation by default. 42 const std::string& account_id) {
77 } 43 GetDelegate()->RevokeCredentials(account_id);
44 }
Roger Tawa OOO till Jul 10th 2015/05/28 14:54:43 I don't think we need these three methods in this
gogerald1 2015/06/03 18:12:58 Done.
Roger Tawa OOO till Jul 10th 2015/06/04 18:19:55 You say done, but the three methods are still here
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698