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_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
6 #define CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // A specialization of ProfileOAuth2TokenService that will be returned by | 21 // A specialization of ProfileOAuth2TokenService that will be returned by |
22 // ProfileOAuth2TokenServiceFactory for OS_ANDROID. This instance uses | 22 // ProfileOAuth2TokenServiceFactory for OS_ANDROID. This instance uses |
23 // native Android features to lookup OAuth2 tokens. | 23 // native Android features to lookup OAuth2 tokens. |
24 // | 24 // |
25 // See |ProfileOAuth2TokenService| for usage details. | 25 // See |ProfileOAuth2TokenService| for usage details. |
26 // | 26 // |
27 // Note: requests should be started from the UI thread. To start a | 27 // Note: requests should be started from the UI thread. To start a |
28 // request from other thread, please use ProfileOAuth2TokenServiceRequest. | 28 // request from other thread, please use ProfileOAuth2TokenServiceRequest. |
29 class AndroidProfileOAuth2TokenService : public ProfileOAuth2TokenService { | 29 class AndroidProfileOAuth2TokenService : public ProfileOAuth2TokenService { |
30 public: | 30 public: |
31 | |
32 // Callback from FetchOAuth2Token. | |
33 // Arguments: | |
34 // - the error, or NONE if the token fetch was successful. | |
35 // - the OAuth2 access token. | |
36 // - the expiry time of the token (may be null, indicating that the expiry | |
37 // time is unknown. | |
38 typedef base::Callback<void( | |
39 const GoogleServiceAuthError&, const std::string&, const base::Time&)> | |
40 FetchOAuth2TokenCallback; | |
41 | |
42 // Start the OAuth2 access token for the given scopes using | |
43 // ProfileSyncServiceAndroid. | |
44 virtual scoped_ptr<OAuth2TokenService::Request> StartRequest( | |
45 const OAuth2TokenService::ScopeSet& scopes, | |
46 OAuth2TokenService::Consumer* consumer) OVERRIDE; | |
47 | |
48 // StartRequest() fetches a token for the currently signed-in account; this | 31 // StartRequest() fetches a token for the currently signed-in account; this |
49 // version uses the account corresponding to |username|. This allows fetching | 32 // version uses the account corresponding to |username|. This allows fetching |
50 // tokens before a user is signed-in (e.g. during the sign-in flow). | 33 // tokens before a user is signed-in (e.g. during the sign-in flow). |
51 scoped_ptr<OAuth2TokenService::Request> StartRequestForUsername( | 34 scoped_ptr<OAuth2TokenService::Request> StartRequestForUsername( |
52 const std::string& username, | 35 const std::string& username, |
53 const OAuth2TokenService::ScopeSet& scopes, | 36 const OAuth2TokenService::ScopeSet& scopes, |
54 OAuth2TokenService::Consumer* consumer); | 37 OAuth2TokenService::Consumer* consumer); |
55 | 38 |
56 virtual bool RefreshTokenIsAvailable() OVERRIDE; | 39 virtual bool RefreshTokenIsAvailable() OVERRIDE; |
57 virtual void InvalidateToken(const ScopeSet& scopes, | 40 virtual void InvalidateToken(const ScopeSet& scopes, |
58 const std::string& invalid_token) OVERRIDE; | 41 const std::string& invalid_token) OVERRIDE; |
59 | 42 |
60 // Registers the AndroidProfileOAuth2TokenService's native methods through | 43 // Registers the AndroidProfileOAuth2TokenService's native methods through |
61 // JNI. | 44 // JNI. |
62 static bool Register(JNIEnv* env); | 45 static bool Register(JNIEnv* env); |
63 | 46 |
64 protected: | 47 protected: |
65 friend class ProfileOAuth2TokenServiceFactory; | 48 friend class ProfileOAuth2TokenServiceFactory; |
66 AndroidProfileOAuth2TokenService(); | 49 AndroidProfileOAuth2TokenService(); |
67 virtual ~AndroidProfileOAuth2TokenService(); | 50 virtual ~AndroidProfileOAuth2TokenService(); |
68 | 51 |
69 // virtual for testing. | 52 // Overridden from OAuth2TokenService to intercept token fetch requests and |
70 virtual void FetchOAuth2Token(const std::string& username, | 53 // redirect them to the Account Manager. |
71 const std::string& scope, | 54 virtual void FetchOAuth2Token(RequestImpl* request, |
72 const FetchOAuth2TokenCallback& callback); | 55 net::URLRequestContextGetter* getter, |
| 56 const std::string& client_id, |
| 57 const std::string& client_secret, |
| 58 const ScopeSet& scopes) OVERRIDE; |
| 59 |
| 60 // Low-level helper function used by both FetchOAuth2Token and |
| 61 // StartRequestForUsername to fetch tokens. virtual to enable mocks. |
| 62 virtual void FetchOAuth2TokenWithUsername( |
| 63 RequestImpl* request, |
| 64 const std::string& username, |
| 65 const ScopeSet& scope); |
73 | 66 |
74 private: | 67 private: |
75 DISALLOW_COPY_AND_ASSIGN(AndroidProfileOAuth2TokenService); | 68 DISALLOW_COPY_AND_ASSIGN(AndroidProfileOAuth2TokenService); |
76 }; | 69 }; |
77 | 70 |
78 #endif // CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 71 #endif // CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |