Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ | |
| 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ | |
| 7 | |
| 8 #include "base/threading/non_thread_safe.h" | |
| 9 #include "google_apis/gaia/oauth2_token_service.h" | |
| 10 | |
| 11 class GoogleServiceAuthError; | |
| 12 | |
| 13 // OAuth2TokenServiceProxy provides a subset of the OAuth2TokenService interface | |
| 14 // and can be instantiated and used from any thread. OAuth2TokenServiceProxy | |
| 15 // itself is a NonThreadSafe class and should called only on the thread on which | |
| 16 // it is created. | |
| 17 // | |
| 18 // OAuth2TokenServiceProxy differs from OAuth2TokenService in that it uses | |
| 19 // callbacks instead of the OAuth2TokenService::Consumer interface. | |
| 20 class OAuth2TokenServiceProxy : public base::NonThreadSafe { | |
| 21 public: | |
| 22 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, | |
| 23 const std::string& /* access_token */, | |
| 24 const base::Time& /* expiration_time */)> | |
|
maniscalco
2014/05/27 22:41:25
After talking with pavely@, I'm inclined to remove
| |
| 25 RequestTokenCallback; | |
| 26 | |
| 27 // Construct an OAuth2TokenServiceProxy. | |
| 28 // | |
| 29 // |token_service_task_runner| is the message loop |token_service| lives on. | |
| 30 // | |
| 31 // |token_service| must outlive this object. | |
| 32 OAuth2TokenServiceProxy( | |
| 33 const scoped_refptr<base::SequencedTaskRunner>& token_service_task_runner, | |
| 34 OAuth2TokenService* token_service); | |
| 35 | |
| 36 // Destroying the OAuth2TokenServiceProxy will eventually cancel any | |
| 37 // outstanding requests. Why eventually? Why not immediately? The requests | |
| 38 // may not be executing in this thread so we cannot guarantee that upon | |
| 39 // completion of the destructor they have been cancelled. If you don't want | |
| 40 // to receive callbacks from outstanding requests, use WeakPtrs in your | |
| 41 // callback. | |
| 42 virtual ~OAuth2TokenServiceProxy(); | |
| 43 | |
| 44 // See OAuth2TokenService::StartRequest. | |
| 45 // | |
| 46 // |callback| will be invoked when the request has completed (successfully or | |
| 47 // not). | |
| 48 // | |
| 49 // |requester_id| is a string that describes the service requesting the token. | |
| 50 void RequestToken(const std::string& account_id, | |
| 51 const OAuth2TokenService::ScopeSet& scopes, | |
| 52 const RequestTokenCallback& callback, | |
| 53 const std::string& requester_id); | |
| 54 | |
| 55 // See OAuth2TokenService::InvalidateToken. | |
| 56 void InvalidateToken(const std::string& account_id, | |
| 57 const OAuth2TokenService::ScopeSet& scopes, | |
| 58 const std::string& access_token); | |
| 59 | |
| 60 private: | |
| 61 class Core; | |
| 62 // The thread that core_ lives on. | |
| 63 scoped_refptr<base::SequencedTaskRunner> core_task_runner_; | |
| 64 // Lives in the token_service_task_runner_ thread and must be destroyed there. | |
| 65 scoped_refptr<Core> core_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceProxy); | |
| 68 }; | |
| 69 | |
| 70 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ | |
| OLD | NEW |