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 "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.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 "google_apis/gaia/oauth2_token_service.h" | 14 #include "google_apis/gaia/oauth2_token_service.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 class URLRequestContextGetter; | 17 class URLRequestContextGetter; |
18 } | 18 } |
19 | 19 |
20 class GoogleServiceAuthError; | 20 class GoogleServiceAuthError; |
21 class Profile; | 21 class Profile; |
22 class SigninGlobalError; | 22 class SigninGlobalError; |
23 | 23 |
24 // ProfileOAuth2TokenService is a BrowserContextKeyedService that retrieves | 24 // ProfileOAuth2TokenService is a class that retrieves |
25 // OAuth2 access tokens for a given set of scopes using the OAuth2 login | 25 // OAuth2 access tokens for a given set of scopes using the OAuth2 login |
26 // refresh tokens. | 26 // refresh tokens. |
27 // | 27 // |
28 // See |OAuth2TokenService| for usage details. | 28 // See |OAuth2TokenService| for usage details. |
29 // | 29 // |
30 // Note: after StartRequest returns, in-flight requests will continue | 30 // Note: after StartRequest returns, in-flight requests will continue |
31 // even if the TokenService refresh token that was used to initiate | 31 // even if the TokenService refresh token that was used to initiate |
32 // the request changes or is cleared. When the request completes, | 32 // the request changes or is cleared. When the request completes, |
33 // Consumer::OnGetTokenSuccess will be invoked, but the access token | 33 // Consumer::OnGetTokenSuccess will be invoked, but the access token |
34 // won't be cached. | 34 // won't be cached. |
35 // | 35 // |
36 // Note: requests should be started from the UI thread. To start a | 36 // Note: requests should be started from the UI thread. To start a |
37 // request from other thread, please use ProfileOAuth2TokenServiceRequest. | 37 // request from other thread, please use ProfileOAuth2TokenServiceRequest. |
38 class ProfileOAuth2TokenService : public OAuth2TokenService, | 38 class ProfileOAuth2TokenService : public OAuth2TokenService { |
39 public BrowserContextKeyedService { | |
40 public: | 39 public: |
| 40 virtual ~ProfileOAuth2TokenService(); |
| 41 |
41 // Initializes this token service with the profile. | 42 // Initializes this token service with the profile. |
42 virtual void Initialize(Profile* profile); | 43 virtual void Initialize(Profile* profile); |
43 | 44 |
44 // BrowserContextKeyedService implementation. | 45 virtual void Shutdown(); |
45 virtual void Shutdown() OVERRIDE; | |
46 | 46 |
47 // Gets an account id of the primary account related to the profile. | 47 // Gets an account id of the primary account related to the profile. |
48 // DEPRECATED: Use SigninManagerBase::GetAuthenticatedAccountId() instead. | 48 // DEPRECATED: Use SigninManagerBase::GetAuthenticatedAccountId() instead. |
49 std::string GetPrimaryAccountId(); | 49 std::string GetPrimaryAccountId(); |
50 | 50 |
51 // Lists account IDs of all accounts with a refresh token. | 51 // Lists account IDs of all accounts with a refresh token. |
52 virtual std::vector<std::string> GetAccounts() OVERRIDE; | 52 virtual std::vector<std::string> GetAccounts() OVERRIDE; |
53 | 53 |
54 // Loads credentials from a backing persistent store to make them available | 54 // Loads credentials from a backing persistent store to make them available |
55 // after service is used between profile restarts. | 55 // after service is used between profile restarts. |
(...skipping 19 matching lines...) Expand all Loading... |
75 } | 75 } |
76 | 76 |
77 const SigninGlobalError* signin_global_error() const { | 77 const SigninGlobalError* signin_global_error() const { |
78 return signin_global_error_.get(); | 78 return signin_global_error_.get(); |
79 } | 79 } |
80 | 80 |
81 Profile* profile() const { return profile_; } | 81 Profile* profile() const { return profile_; } |
82 | 82 |
83 protected: | 83 protected: |
84 ProfileOAuth2TokenService(); | 84 ProfileOAuth2TokenService(); |
85 virtual ~ProfileOAuth2TokenService(); | |
86 | 85 |
87 // OAuth2TokenService overrides. | 86 // OAuth2TokenService overrides. |
88 // Note: These methods are overriden so that ProfileOAuth2TokenService is a | 87 // Note: These methods are overriden so that ProfileOAuth2TokenService is a |
89 // concrete class. | 88 // concrete class. |
90 | 89 |
91 // Simply returns NULL and should be overriden by subsclasses. | 90 // Simply returns NULL and should be overriden by subsclasses. |
92 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 91 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
93 | 92 |
94 // Default implementation of this method is NOTREACHED as it should be be | 93 // Default implementation of this method is NOTREACHED as it should be be |
95 // overriden by subclasses. | 94 // overriden by subclasses. |
(...skipping 12 matching lines...) Expand all Loading... |
108 // Used to show auth errors in the wrench menu. The SigninGlobalError is | 107 // Used to show auth errors in the wrench menu. The SigninGlobalError is |
109 // different than most GlobalErrors in that its lifetime is controlled by | 108 // different than most GlobalErrors in that its lifetime is controlled by |
110 // ProfileOAuth2TokenService (so we can expose a reference for use in the | 109 // ProfileOAuth2TokenService (so we can expose a reference for use in the |
111 // wrench menu). | 110 // wrench menu). |
112 scoped_ptr<SigninGlobalError> signin_global_error_; | 111 scoped_ptr<SigninGlobalError> signin_global_error_; |
113 | 112 |
114 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); | 113 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); |
115 }; | 114 }; |
116 | 115 |
117 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 116 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |