Chromium Code Reviews| Index: google_apis/gaia/oauth2_token_service_proxy.h |
| diff --git a/google_apis/gaia/oauth2_token_service_proxy.h b/google_apis/gaia/oauth2_token_service_proxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0a12a0dfafbe424a4241dc00b7092ba72a4fed0f |
| --- /dev/null |
| +++ b/google_apis/gaia/oauth2_token_service_proxy.h |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ |
| +#define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ |
| + |
| +#include "base/threading/non_thread_safe.h" |
| +#include "google_apis/gaia/oauth2_token_service.h" |
| + |
| +class GoogleServiceAuthError; |
| + |
| +// OAuth2TokenServiceProxy provides a subset of the OAuth2TokenService interface |
| +// and can be instantiated and used from any thread. OAuth2TokenServiceProxy |
| +// itself is a NonThreadSafe class and should called only on the thread on which |
| +// it is created. |
| +// |
| +// OAuth2TokenServiceProxy differs from OAuth2TokenService in that it uses |
| +// callbacks instead of the OAuth2TokenService::Consumer interface. |
| +class OAuth2TokenServiceProxy : public base::NonThreadSafe { |
| + public: |
| + typedef base::Callback<void(const GoogleServiceAuthError& /* error */, |
| + const std::string& /* access_token */, |
| + const base::Time& /* expiration_time */)> |
|
maniscalco
2014/05/27 22:41:25
After talking with pavely@, I'm inclined to remove
|
| + RequestTokenCallback; |
| + |
| + // Construct an OAuth2TokenServiceProxy. |
| + // |
| + // |token_service_task_runner| is the message loop |token_service| lives on. |
| + // |
| + // |token_service| must outlive this object. |
| + OAuth2TokenServiceProxy( |
| + const scoped_refptr<base::SequencedTaskRunner>& token_service_task_runner, |
| + OAuth2TokenService* token_service); |
| + |
| + // Destroying the OAuth2TokenServiceProxy will eventually cancel any |
| + // outstanding requests. Why eventually? Why not immediately? The requests |
| + // may not be executing in this thread so we cannot guarantee that upon |
| + // completion of the destructor they have been cancelled. If you don't want |
| + // to receive callbacks from outstanding requests, use WeakPtrs in your |
| + // callback. |
| + virtual ~OAuth2TokenServiceProxy(); |
| + |
| + // See OAuth2TokenService::StartRequest. |
| + // |
| + // |callback| will be invoked when the request has completed (successfully or |
| + // not). |
| + // |
| + // |requester_id| is a string that describes the service requesting the token. |
| + void RequestToken(const std::string& account_id, |
| + const OAuth2TokenService::ScopeSet& scopes, |
| + const RequestTokenCallback& callback, |
| + const std::string& requester_id); |
| + |
| + // See OAuth2TokenService::InvalidateToken. |
| + void InvalidateToken(const std::string& account_id, |
| + const OAuth2TokenService::ScopeSet& scopes, |
| + const std::string& access_token); |
| + |
| + private: |
| + class Core; |
| + // The thread that core_ lives on. |
| + scoped_refptr<base::SequencedTaskRunner> core_task_runner_; |
| + // Lives in the token_service_task_runner_ thread and must be destroyed there. |
| + scoped_refptr<Core> core_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceProxy); |
| +}; |
| + |
| +#endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_PROXY_H_ |