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

Unified Diff: components/webdata/common/web_data_request_manager.h

Issue 2571923002: Fix threading issues in WebDataRequestManager. (Closed)
Patch Set: Created 4 years 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: components/webdata/common/web_data_request_manager.h
diff --git a/components/webdata/common/web_data_request_manager.h b/components/webdata/common/web_data_request_manager.h
index 836c12e0d5ef280e7b7e218ed7bcba5f3bc6c6ba..f69dfc21645252ee297f821a77f99b8491a6a3b3 100644
--- a/components/webdata/common/web_data_request_manager.h
+++ b/components/webdata/common/web_data_request_manager.h
@@ -26,7 +26,7 @@ class WebDataRequestManager;
//////////////////////////////////////////////////////////////////////////////
//
-// Webdata requests
+// WebData requests
//
// Every request is processed using a request object. The object contains
// both the request parameters and the results.
@@ -38,58 +38,59 @@ class WebDataRequest {
virtual ~WebDataRequest();
+ // Returns the identifier for this request.
WebDataServiceBase::Handle GetHandle() const;
+ // Returns |true| if the request was cancelled (or has already completed).
+ bool IsCancelled() const;
+
+ private:
+ // Internal debugging helper to assert that the manager pointer is valid and
+ // that the manager's lock is held by the current thread.
+ void AssertThreadSafe() const;
+
// Retrieves the |consumer_| set in the constructor.
WebDataServiceConsumer* GetConsumer() const;
// Retrieves the original task runner of the request.
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const;
- // Returns |true| if the request was cancelled via the |Cancel()| method.
- bool IsCancelled() const;
-
- // This can be invoked from any thread. From this point we assume that
- // our consumer_ reference is invalid.
- void Cancel();
-
- // Invoked when the request has been completed.
- void OnComplete();
+ // Marks the current request as inactive, either due to cancellation or
+ // completion.
+ void MarkAsInactive();
// The result is owned by the request.
void SetResult(std::unique_ptr<WDTypedResult> r);
- // Transfers ownership pof result to caller. Should only be called once per
+ // Transfers ownership of result to caller. Should only be called once per
// result.
std::unique_ptr<WDTypedResult> GetResult();
- private:
- // Used to notify manager if request is cancelled. Uses a raw ptr instead of
- // a ref_ptr so that it can be set to NULL when a request is cancelled.
- WebDataRequestManager* manager_;
-
// Tracks task runner that the request originated on.
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// Identifier for this request.
- WebDataServiceBase::Handle handle_;
+ const WebDataServiceBase::Handle handle_;
- // A lock to protect against simultaneous cancellations of the request.
- // Cancellation affects both the |cancelled_| flag and |consumer_|.
- mutable base::Lock cancel_lock_;
- bool cancelled_;
+ // Used to notify manager if request is cancelled. Uses a raw ptr instead of
+ // a ref_ptr so that it can be set to NULL when a request is cancelled or
+ // completed.
+ WebDataRequestManager* manager_;
// The originator of the service request.
WebDataServiceConsumer* consumer_;
std::unique_ptr<WDTypedResult> result_;
+ // For access to the web request mutable state under the manager's lock.
+ friend class WebDataRequestManager;
Mathieu 2016/12/14 01:13:46 I've seen those statements be right under the priv
Roger McFarlane (Chromium) 2016/12/14 14:02:49 Done.
+
DISALLOW_COPY_AND_ASSIGN(WebDataRequest);
};
//////////////////////////////////////////////////////////////////////////////
//
-// Webdata Request Manager
+// WebData Request Manager
//
// Tracks all WebDataRequests for a WebDataService.
//
@@ -104,7 +105,8 @@ class WebDataRequestManager
void CancelRequest(WebDataServiceBase::Handle h);
// Invoked by the WebDataService when |request| has been completed.
- void RequestCompleted(std::unique_ptr<WebDataRequest> request);
+ void RequestCompleted(std::unique_ptr<WebDataRequest> request,
+ std::unique_ptr<WDTypedResult> result);
// Register the request as a pending request.
void RegisterRequest(WebDataRequest* request);
@@ -112,6 +114,10 @@ class WebDataRequestManager
// Return the next request handle.
int GetNextRequestHandle();
+ // A debugging aid to assert that the pending_lock_ is held by the current
+ // thread.
+ void AssertLockedByCurrentThread() const { pending_lock_.AssertAcquired(); }
+
private:
friend class base::RefCountedThreadSafe<WebDataRequestManager>;

Powered by Google App Engine
This is Rietveld 408576698