Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: google_apis/gaia/oauth2_token_service_request.h

Issue 458753006: Fix use after free bug by calling GetTokenService in Core's ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update TSP comment (CANDIDATE). Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: google_apis/gaia/oauth2_token_service_request.h
diff --git a/google_apis/gaia/oauth2_token_service_request.h b/google_apis/gaia/oauth2_token_service_request.h
index 972e5184b85c811cf04609cb75f95e1a46cc3004..b1f0e57629d285aa48192ce3d7fabedd34043885 100644
--- a/google_apis/gaia/oauth2_token_service_request.h
+++ b/google_apis/gaia/oauth2_token_service_request.h
@@ -8,6 +8,7 @@
#include <set>
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/non_thread_safe.h"
@@ -23,10 +24,16 @@ class OAuth2TokenServiceRequest : public OAuth2TokenService::Request,
class Core;
// Interface for providing an OAuth2TokenService.
- class TokenServiceProvider {
+ //
+ // Ref-counted so that OAuth2TokenServiceRequest can ensure this object isn't
+ // destroyed out from under the token service task runner thread. Because
+ // OAuth2TokenServiceRequest has a reference, implementations of
+ // TokenServiceProvider must be capable of being destroyed on the same thread
+ // on which the OAuth2TokenServiceRequest was created.
+ class TokenServiceProvider
+ : public base::RefCountedThreadSafe<TokenServiceProvider> {
public:
TokenServiceProvider();
- virtual ~TokenServiceProvider();
// Returns the task runner on which the token service lives.
//
@@ -42,12 +49,15 @@ class OAuth2TokenServiceRequest : public OAuth2TokenService::Request,
// This method may only be called from the task runner returned by
// |GetTokenServiceTaskRunner|.
virtual OAuth2TokenService* GetTokenService() = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<TokenServiceProvider>;
+ virtual ~TokenServiceProvider();
};
// Creates and starts an access token request for |account_id| and |scopes|.
//
- // |provider| is used to get the OAuth2TokenService and must outlive the
- // returned request object.
+ // |provider| is used to get the OAuth2TokenService.
//
// |account_id| must not be empty.
//
@@ -59,23 +69,23 @@ class OAuth2TokenServiceRequest : public OAuth2TokenService::Request,
// network activities may not be canceled and the cache in OAuth2TokenService
// may be populated with the fetched results.
static scoped_ptr<OAuth2TokenServiceRequest> CreateAndStart(
- TokenServiceProvider* provider,
+ const scoped_refptr<TokenServiceProvider>& provider,
const std::string& account_id,
const OAuth2TokenService::ScopeSet& scopes,
OAuth2TokenService::Consumer* consumer);
// Invalidates |access_token| for |account_id| and |scopes|.
//
- // |provider| is used to get the OAuth2TokenService and must outlive the
- // returned request object.
+ // |provider| is used to get the OAuth2TokenService.
//
// |account_id| must not be empty.
//
// |scopes| must not be empty.
- static void InvalidateToken(TokenServiceProvider* provider,
- const std::string& account_id,
- const OAuth2TokenService::ScopeSet& scopes,
- const std::string& access_token);
+ static void InvalidateToken(
+ const scoped_refptr<TokenServiceProvider>& provider,
+ const std::string& account_id,
+ const OAuth2TokenService::ScopeSet& scopes,
+ const std::string& access_token);
virtual ~OAuth2TokenServiceRequest();

Powered by Google App Engine
This is Rietveld 408576698