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