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

Unified Diff: google_apis/gaia/oauth2_token_service_request.cc

Issue 317773003: Ensure OAuth2TokenServiceRequest::Core is destroyed on owner thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Run loop in TearDown to ensure core is freed before unit test terminates. Created 6 years, 6 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
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_token_service_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gaia/oauth2_token_service_request.cc
diff --git a/google_apis/gaia/oauth2_token_service_request.cc b/google_apis/gaia/oauth2_token_service_request.cc
index c946fde088e89f31d7edbf1206bfe22adbbe1e4a..672015241779a45d4e8f1dea882947d0844c3011 100644
--- a/google_apis/gaia/oauth2_token_service_request.cc
+++ b/google_apis/gaia/oauth2_token_service_request.cc
@@ -71,6 +71,8 @@ class OAuth2TokenServiceRequest::Core
private:
friend class base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core>;
+ void DoNothing();
+
scoped_refptr<base::SingleThreadTaskRunner> token_service_task_runner_;
OAuth2TokenServiceRequest* owner_;
TokenServiceProvider* provider_;
@@ -104,10 +106,16 @@ void OAuth2TokenServiceRequest::Core::Stop() {
// Detaches |owner_| from this instance so |owner_| will be called back only
// if |Stop()| has never been called.
owner_ = NULL;
- token_service_task_runner_->PostTask(
+
+ // We are stopping and will likely be destroyed soon. Use a reply closure
+ // (DoNothing) to retain "this" and ensure we are destroyed in the owner
+ // thread, not the task runner thread. PostTaskAndReply guarantees that the
+ // reply closure will execute after StopOnTokenServiceThread has completed.
+ token_service_task_runner_->PostTaskAndReply(
FROM_HERE,
base::Bind(&OAuth2TokenServiceRequest::Core::StopOnTokenServiceThread,
- this));
+ this),
+ base::Bind(&OAuth2TokenServiceRequest::Core::DoNothing, this));
}
bool OAuth2TokenServiceRequest::Core::IsStopped() const {
@@ -130,6 +138,10 @@ OAuth2TokenServiceRequest* OAuth2TokenServiceRequest::Core::owner() {
return owner_;
}
+void OAuth2TokenServiceRequest::Core::DoNothing() {
+ DCHECK(CalledOnValidThread());
+}
+
namespace {
// An implementation of Core for getting an access token.
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_token_service_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698