OLD | NEW |
1 // Copyright 2012 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 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ | 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ | 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
12 #include "google_apis/gaia/oauth2_token_service.h" | 14 #include "google_apis/gaia/oauth2_token_service.h" |
13 | 15 |
14 class Profile; | 16 // OAuth2TokenServiceRequest represents an asynchronous request to an |
| 17 // OAuth2TokenService that may live in another thread. |
| 18 // |
| 19 // An OAuth2TokenServiceRequest can be created and started from any thread. |
| 20 class OAuth2TokenServiceRequest : public OAuth2TokenService::Request, |
| 21 public base::NonThreadSafe { |
| 22 public: |
| 23 class Core; |
15 | 24 |
16 // ProfileOAuth2TokenServiceRequest represents a request to fetch an | 25 // Interface for providing an OAuth2TokenService. |
17 // OAuth2 access token for a given set of |scopes| by calling |profile|'s | 26 class TokenServiceProvider { |
18 // ProfileOAuth2TokenService. A request can be created and started from | 27 public: |
19 // any thread with an object |consumer| that will be called back on the | 28 TokenServiceProvider(); |
20 // same thread when fetching completes. If the request is destructed | 29 virtual ~TokenServiceProvider(); |
21 // before |consumer| is called, |consumer| will never be called back. (Note | 30 |
22 // the actual network activities are not canceled and the cache in | 31 // Returns the task runner on which the token service lives. |
23 // ProfileOAuth2TokenService will be populated with the fetched results.) | 32 // |
24 class ProfileOAuth2TokenServiceRequest : public OAuth2TokenService::Request, | 33 // This method may be called from any thread. |
25 public base::NonThreadSafe { | 34 virtual scoped_refptr<base::SingleThreadTaskRunner> |
26 public: | 35 GetTokenServiceTaskRunner() = 0; |
27 // Creates and starts a request for |account_id| and |scopes|. | 36 |
28 // Uses the primary account id if |account_id| is the empty string. | 37 // Returns a pointer to a token service. |
29 static ProfileOAuth2TokenServiceRequest* CreateAndStart( | 38 // |
30 Profile* profile, | 39 // Caller does not own the token service and must not delete it. The token |
| 40 // service must outlive all instances of OAuth2TokenServiceRequest. |
| 41 // |
| 42 // This method may only be called from the task runner returned by |
| 43 // |GetTokenServiceTaskRunner|. |
| 44 virtual OAuth2TokenService* GetTokenService() = 0; |
| 45 }; |
| 46 |
| 47 // Creates and starts an access token request for |account_id| and |scopes|. |
| 48 // |
| 49 // |provider| is used to get the OAuth2TokenService and must outlive the |
| 50 // returned request object. |
| 51 // |
| 52 // |account_id| must not be empty. |
| 53 // |
| 54 // |scopes| must not be empty. |
| 55 // |
| 56 // |consumer| will be invoked in the same thread that invoked CreateAndStart |
| 57 // and must outlive the returned request object. Destroying the request |
| 58 // object ensure that |consumer| will not be called. However, the actual |
| 59 // network activities may not be canceled and the cache in OAuth2TokenService |
| 60 // may be populated with the fetched results. |
| 61 static scoped_ptr<OAuth2TokenServiceRequest> CreateAndStart( |
| 62 TokenServiceProvider* provider, |
31 const std::string& account_id, | 63 const std::string& account_id, |
32 const OAuth2TokenService::ScopeSet& scopes, | 64 const OAuth2TokenService::ScopeSet& scopes, |
33 OAuth2TokenService::Consumer* consumer); | 65 OAuth2TokenService::Consumer* consumer); |
34 | 66 |
35 virtual ~ProfileOAuth2TokenServiceRequest(); | 67 // Invalidates |access_token| for |account_id| and |scopes|. |
| 68 // |
| 69 // |provider| is used to get the OAuth2TokenService and must outlive the |
| 70 // returned request object. |
| 71 // |
| 72 // |account_id| must not be empty. |
| 73 // |
| 74 // |scopes| must not be empty. |
| 75 static void InvalidateToken(TokenServiceProvider* provider, |
| 76 const std::string& account_id, |
| 77 const OAuth2TokenService::ScopeSet& scopes, |
| 78 const std::string& access_token); |
36 | 79 |
37 // Overridden from Request: | 80 virtual ~OAuth2TokenServiceRequest(); |
| 81 |
| 82 // OAuth2TokenService::Request. |
38 virtual std::string GetAccountId() const OVERRIDE; | 83 virtual std::string GetAccountId() const OVERRIDE; |
39 | 84 |
40 private: | 85 private: |
41 class Core; | 86 OAuth2TokenServiceRequest(const std::string& account_id); |
42 friend class Core; | |
43 | 87 |
44 ProfileOAuth2TokenServiceRequest(Profile* profile, | 88 void StartWithCore(const scoped_refptr<Core>& core); |
45 const std::string& account_id, | |
46 const OAuth2TokenService::ScopeSet& scopes, | |
47 OAuth2TokenService::Consumer* consumer); | |
48 | 89 |
49 OAuth2TokenService::Consumer* const consumer_; | 90 const std::string account_id_; |
50 scoped_refptr<Core> core_; | 91 scoped_refptr<Core> core_; |
51 | 92 |
52 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceRequest); | 93 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceRequest); |
53 }; | 94 }; |
54 | 95 |
55 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ | 96 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
OLD | NEW |