OLD | NEW |
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 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "chrome/browser/signin/oauth2_token_service.h" | 11 #include "chrome/browser/signin/oauth2_token_service.h" |
12 #include "chrome/browser/signin/signin_global_error.h" | 12 #include "chrome/browser/signin/signin_global_error.h" |
13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
19 } | 19 } |
20 | 20 |
21 class GoogleServiceAuthError; | 21 class GoogleServiceAuthError; |
22 class Profile; | 22 class Profile; |
23 class TokenService; | 23 class TokenService; |
24 | 24 |
25 // ProfileOAuth2TokenService is a ProfileKeyedService that retrieves | 25 // ProfileOAuth2TokenService is a BrowserContextKeyedService that retrieves |
26 // OAuth2 access tokens for a given set of scopes using the OAuth2 login | 26 // OAuth2 access tokens for a given set of scopes using the OAuth2 login |
27 // refresh token maintained by TokenService. | 27 // refresh token maintained by TokenService. |
28 // | 28 // |
29 // See |OAuth2TokenService| for usage details. | 29 // See |OAuth2TokenService| for usage details. |
30 // | 30 // |
31 // Note: after StartRequest returns, in-flight requests will continue | 31 // Note: after StartRequest returns, in-flight requests will continue |
32 // even if the TokenService refresh token that was used to initiate | 32 // even if the TokenService refresh token that was used to initiate |
33 // the request changes or is cleared. When the request completes, | 33 // the request changes or is cleared. When the request completes, |
34 // Consumer::OnGetTokenSuccess will be invoked, but the access token | 34 // Consumer::OnGetTokenSuccess will be invoked, but the access token |
35 // won't be cached. | 35 // won't be cached. |
36 // | 36 // |
37 // Note: requests should be started from the UI thread. To start a | 37 // Note: requests should be started from the UI thread. To start a |
38 // request from other thread, please use ProfileOAuth2TokenServiceRequest. | 38 // request from other thread, please use ProfileOAuth2TokenServiceRequest. |
39 class ProfileOAuth2TokenService : public OAuth2TokenService, | 39 class ProfileOAuth2TokenService : public OAuth2TokenService, |
40 public content::NotificationObserver, | 40 public content::NotificationObserver, |
41 public SigninGlobalError::AuthStatusProvider, | 41 public SigninGlobalError::AuthStatusProvider, |
42 public ProfileKeyedService { | 42 public BrowserContextKeyedService { |
43 public: | 43 public: |
44 // content::NotificationObserver listening for TokenService updates. | 44 // content::NotificationObserver listening for TokenService updates. |
45 virtual void Observe(int type, | 45 virtual void Observe(int type, |
46 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
47 const content::NotificationDetails& details) OVERRIDE; | 47 const content::NotificationDetails& details) OVERRIDE; |
48 | 48 |
49 // Initializes this token service with the profile. | 49 // Initializes this token service with the profile. |
50 virtual void Initialize(Profile* profile); | 50 virtual void Initialize(Profile* profile); |
51 | 51 |
52 // ProfileKeyedService implementation. | 52 // BrowserContextKeyedService implementation. |
53 virtual void Shutdown() OVERRIDE; | 53 virtual void Shutdown() OVERRIDE; |
54 | 54 |
55 // SigninGlobalError::AuthStatusProvider implementation. | 55 // SigninGlobalError::AuthStatusProvider implementation. |
56 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; | 56 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; |
57 | 57 |
58 // Takes injected TokenService for testing. | 58 // Takes injected TokenService for testing. |
59 bool ShouldCacheForRefreshToken(TokenService *token_service, | 59 bool ShouldCacheForRefreshToken(TokenService *token_service, |
60 const std::string& refresh_token); | 60 const std::string& refresh_token); |
61 | 61 |
62 protected: | 62 protected: |
(...skipping 29 matching lines...) Expand all Loading... |
92 // The auth status from the most-recently-completed request. | 92 // The auth status from the most-recently-completed request. |
93 GoogleServiceAuthError last_auth_error_; | 93 GoogleServiceAuthError last_auth_error_; |
94 | 94 |
95 // Registrar for notifications from the TokenService. | 95 // Registrar for notifications from the TokenService. |
96 content::NotificationRegistrar registrar_; | 96 content::NotificationRegistrar registrar_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); | 98 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); |
99 }; | 99 }; |
100 | 100 |
101 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 101 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |