OLD | NEW |
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 void ProfileOAuth2TokenService::OnRefreshTokenAvailable( |
8 #include "base/message_loop/message_loop.h" | 8 const std::string& account_id) { |
9 #include "base/stl_util.h" | 9 CancelRequestsForAccount(account_id); |
10 #include "base/time/time.h" | 10 ClearCacheForAccount(account_id); |
11 #include "components/signin/core/browser/signin_client.h" | 11 } |
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" | |
15 | 12 |
16 ProfileOAuth2TokenService::ProfileOAuth2TokenService() | 13 void ProfileOAuth2TokenService::OnRefreshTokenRevoked( |
17 : client_(NULL), | 14 const std::string& account_id) { |
18 signin_error_controller_(NULL) {} | 15 CancelRequestsForAccount(account_id); |
| 16 ClearCacheForAccount(account_id); |
| 17 } |
19 | 18 |
20 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {} | 19 ProfileOAuth2TokenService::ProfileOAuth2TokenService( |
| 20 OAuth2TokenServiceDelegate* delegate) |
| 21 : OAuth2TokenService(delegate) { |
| 22 AddObserver(this); |
| 23 } |
21 | 24 |
22 void ProfileOAuth2TokenService::Initialize( | 25 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() { |
23 SigninClient* client, | 26 RemoveObserver(this); |
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 } | 27 } |
32 | 28 |
33 void ProfileOAuth2TokenService::Shutdown() { | 29 void ProfileOAuth2TokenService::Shutdown() { |
34 DCHECK(client_) << "Shutdown() called without matching call to Initialize()"; | 30 CancelAllRequests(); |
35 } | 31 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 } | 32 } |
63 | 33 |
64 void ProfileOAuth2TokenService::LoadCredentials( | 34 void ProfileOAuth2TokenService::LoadCredentials( |
65 const std::string& primary_account_id) { | 35 const std::string& primary_account_id) { |
66 // Empty implementation by default. | 36 GetDelegate()->LoadCredentials(primary_account_id); |
67 } | 37 } |
68 | 38 |
69 void ProfileOAuth2TokenService::UpdateCredentials( | 39 void ProfileOAuth2TokenService::UpdateCredentials( |
70 const std::string& account_id, | 40 const std::string& account_id, |
71 const std::string& refresh_token) { | 41 const std::string& refresh_token) { |
72 NOTREACHED(); | 42 GetDelegate()->UpdateCredentials(account_id, refresh_token); |
73 } | 43 } |
74 | 44 |
75 void ProfileOAuth2TokenService::RevokeAllCredentials() { | 45 void ProfileOAuth2TokenService::RevokeCredentials( |
76 // Empty implementation by default. | 46 const std::string& account_id) { |
| 47 GetDelegate()->RevokeCredentials(account_id); |
77 } | 48 } |
OLD | NEW |