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

Side by Side Diff: chrome/browser/webdata/web_data_request_manager.h

Issue 11862010: Fix WebDataRequest ownership gap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tsan bug Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Chromium settings and storage represent user-selected preferences and 5 // Chromium settings and storage represent user-selected preferences and
6 // information and MUST not be extracted, overwritten or modified except 6 // information and MUST not be extracted, overwritten or modified except
7 // through Chromium defined APIs. 7 // through Chromium defined APIs.
8 8
9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
(...skipping 13 matching lines...) Expand all
24 24
25 ////////////////////////////////////////////////////////////////////////////// 25 //////////////////////////////////////////////////////////////////////////////
26 // 26 //
27 // Webdata requests 27 // Webdata requests
28 // 28 //
29 // Every request is processed using a request object. The object contains 29 // Every request is processed using a request object. The object contains
30 // both the request parameters and the results. 30 // both the request parameters and the results.
31 ////////////////////////////////////////////////////////////////////////////// 31 //////////////////////////////////////////////////////////////////////////////
32 class WebDataRequest { 32 class WebDataRequest {
33 public: 33 public:
34 WebDataRequest(WebDataService* service, 34 WebDataRequest(WebDataServiceConsumer* consumer,
35 WebDataServiceConsumer* consumer,
36 WebDataRequestManager* manager); 35 WebDataRequestManager* manager);
37 36
38 virtual ~WebDataRequest(); 37 virtual ~WebDataRequest();
39 38
40 WebDataServiceBase::Handle GetHandle() const; 39 WebDataServiceBase::Handle GetHandle() const;
41 40
42 // Retrieves the |consumer_| set in the constructor. 41 // Retrieves the |consumer_| set in the constructor.
43 WebDataServiceConsumer* GetConsumer() const; 42 WebDataServiceConsumer* GetConsumer() const;
44 43
44 // Retrieves the original message loop the of the request.
45 MessageLoop* GetMessageLoop() const;
46
45 // Returns |true| if the request was cancelled via the |Cancel()| method. 47 // Returns |true| if the request was cancelled via the |Cancel()| method.
46 bool IsCancelled() const; 48 bool IsCancelled() const;
47 49
48 // This can be invoked from any thread. From this point we assume that 50 // This can be invoked from any thread. From this point we assume that
49 // our consumer_ reference is invalid. 51 // our consumer_ reference is invalid.
50 void Cancel(); 52 void Cancel();
51 53
52 // Invoked by the service when this request has been completed. 54 // Invoked when the request has been completed.
53 // This will notify the service in whatever thread was used to create this 55 void OnComplete();
54 // request.
55 void RequestComplete();
56 56
57 // The result is owned by the request. 57 // The result is owned by the request.
58 void SetResult(scoped_ptr<WDTypedResult> r); 58 void SetResult(scoped_ptr<WDTypedResult> r);
59 const WDTypedResult* GetResult() const; 59
60 // Transfers ownership pof result to caller. Should only be called once per
61 // result.
62 scoped_ptr<WDTypedResult> GetResult();
60 63
61 private: 64 private:
62 // Used to notify service of request completion. 65 // Used to notify manager if request is cancelled. Uses a raw ptr instead of
63 scoped_refptr<WebDataService> service_; 66 // a ref_ptr so that it can be set to NULL when a request is cancelled.
67 WebDataRequestManager* manager_;
64 68
65 // Tracks loop that the request originated on. 69 // Tracks loop that the request originated on.
66 MessageLoop* message_loop_; 70 MessageLoop* message_loop_;
67 71
68 // Identifier for this request. 72 // Identifier for this request.
69 WebDataServiceBase::Handle handle_; 73 WebDataServiceBase::Handle handle_;
70 74
71 // A lock to protect against simultaneous cancellations of the request. 75 // A lock to protect against simultaneous cancellations of the request.
72 // Cancellation affects both the |cancelled_| flag and |consumer_|. 76 // Cancellation affects both the |cancelled_| flag and |consumer_|.
73 mutable base::Lock cancel_lock_; 77 mutable base::Lock cancel_lock_;
74 bool cancelled_; 78 bool cancelled_;
75 79
76 // The originator of the service request. 80 // The originator of the service request.
77 WebDataServiceConsumer* consumer_; 81 WebDataServiceConsumer* consumer_;
78 82
79 scoped_ptr<WDTypedResult> result_; 83 scoped_ptr<WDTypedResult> result_;
80 84
81 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); 85 DISALLOW_COPY_AND_ASSIGN(WebDataRequest);
82 }; 86 };
83 87
84 ////////////////////////////////////////////////////////////////////////////// 88 //////////////////////////////////////////////////////////////////////////////
85 // 89 //
86 // Webdata Request Manager 90 // Webdata Request Manager
87 // 91 //
88 // Tracks all WebDataRequests for a WebDataService. 92 // Tracks all WebDataRequests for a WebDataService.
89 // 93 //
90 // Note: This is an internal interface, not to be used outside of webdata/ 94 // Note: This is an internal interface, not to be used outside of webdata/
91 ////////////////////////////////////////////////////////////////////////////// 95 //////////////////////////////////////////////////////////////////////////////
92 class WebDataRequestManager { 96 class WebDataRequestManager
97 : public base::RefCountedThreadSafe<WebDataRequestManager> {
93 public: 98 public:
94 WebDataRequestManager(); 99 WebDataRequestManager();
95 100
96 ~WebDataRequestManager();
97
98 // Cancel any pending request. 101 // Cancel any pending request.
99 void CancelRequest(WebDataServiceBase::Handle h); 102 void CancelRequest(WebDataServiceBase::Handle h);
100 103
101 // Invoked by request implementations when a request has been processed. 104 // Invoked by the WebDataService when |request| has been completed.
102 void RequestCompleted(WebDataServiceBase::Handle h); 105 void RequestCompleted(scoped_ptr<WebDataRequest> request);
103 106
104 // Register the request as a pending request. 107 // Register the request as a pending request.
105 void RegisterRequest(WebDataRequest* request); 108 void RegisterRequest(WebDataRequest* request);
106 109
107 // Return the next request handle. 110 // Return the next request handle.
108 int GetNextRequestHandle(); 111 int GetNextRequestHandle();
109 112
110 private: 113 private:
114 friend class base::RefCountedThreadSafe<WebDataRequestManager>;
115
116 ~WebDataRequestManager();
117
118 // This will notify the consumer in whatever thread was used to create this
119 // request.
120 void RequestCompletedOnThread(scoped_ptr<WebDataRequest> request);
121
111 // A lock to protect pending requests and next request handle. 122 // A lock to protect pending requests and next request handle.
112 base::Lock pending_lock_; 123 base::Lock pending_lock_;
113 124
114 // Next handle to be used for requests. Incremented for each use. 125 // Next handle to be used for requests. Incremented for each use.
115 WebDataServiceBase::Handle next_request_handle_; 126 WebDataServiceBase::Handle next_request_handle_;
116 127
117 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; 128 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap;
118 RequestMap pending_requests_; 129 RequestMap pending_requests_;
119 130
120 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); 131 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager);
121 }; 132 };
122 133
123 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ 134 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
OLDNEW
« no previous file with comments | « chrome/browser/api/webdata/web_data_results.cc ('k') | chrome/browser/webdata/web_data_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698