OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 WebDataServiceConsumer* consumer, | 35 WebDataServiceConsumer* consumer, |
36 WebDataRequestManager* manager); | 36 WebDataRequestManager* manager); |
37 | 37 |
38 virtual ~WebDataRequest(); | 38 virtual ~WebDataRequest(); |
39 | 39 |
40 WebDataServiceBase::Handle GetHandle() const; | 40 WebDataServiceBase::Handle GetHandle() const; |
41 | 41 |
42 // Retrieves the |consumer_| set in the constructor. | 42 // Retrieves the |consumer_| set in the constructor. |
43 WebDataServiceConsumer* GetConsumer() const; | 43 WebDataServiceConsumer* GetConsumer() const; |
44 | 44 |
45 // Retrieves the original message loop the of the request. | |
46 MessageLoop* GetMessageLoop() const; | |
47 | |
45 // Returns |true| if the request was cancelled via the |Cancel()| method. | 48 // Returns |true| if the request was cancelled via the |Cancel()| method. |
46 bool IsCancelled() const; | 49 bool IsCancelled() const; |
47 | 50 |
48 // This can be invoked from any thread. From this point we assume that | 51 // This can be invoked from any thread. From this point we assume that |
49 // our consumer_ reference is invalid. | 52 // our consumer_ reference is invalid. |
50 void Cancel(); | 53 void Cancel(); |
51 | 54 |
52 // Invoked by the service when this request has been completed. | |
53 // This will notify the service in whatever thread was used to create this | |
54 // request. | |
55 void RequestComplete(); | |
56 | |
57 // The result is owned by the request. | 55 // The result is owned by the request. |
58 void SetResult(scoped_ptr<WDTypedResult> r); | 56 void SetResult(scoped_ptr<WDTypedResult> r); |
59 const WDTypedResult* GetResult() const; | 57 const WDTypedResult* GetResult() const; |
60 | 58 |
61 private: | 59 private: |
62 // Used to notify service of request completion. | 60 // Used to notify service of request completion. |
63 scoped_refptr<WebDataService> service_; | 61 scoped_refptr<WebDataService> service_; |
64 | 62 |
63 // Used to notify manager if request is cancelled. | |
64 WebDataRequestManager* manager_; | |
65 | |
65 // Tracks loop that the request originated on. | 66 // Tracks loop that the request originated on. |
66 MessageLoop* message_loop_; | 67 MessageLoop* message_loop_; |
67 | 68 |
68 // Identifier for this request. | 69 // Identifier for this request. |
69 WebDataServiceBase::Handle handle_; | 70 WebDataServiceBase::Handle handle_; |
70 | 71 |
71 // A lock to protect against simultaneous cancellations of the request. | 72 // A lock to protect against simultaneous cancellations of the request. |
72 // Cancellation affects both the |cancelled_| flag and |consumer_|. | 73 // Cancellation affects both the |cancelled_| flag and |consumer_|. |
73 mutable base::Lock cancel_lock_; | 74 mutable base::Lock cancel_lock_; |
74 bool cancelled_; | 75 bool cancelled_; |
(...skipping 13 matching lines...) Expand all Loading... | |
88 // Tracks all WebDataRequests for a WebDataService. | 89 // Tracks all WebDataRequests for a WebDataService. |
89 // | 90 // |
90 // Note: This is an internal interface, not to be used outside of webdata/ | 91 // Note: This is an internal interface, not to be used outside of webdata/ |
91 ////////////////////////////////////////////////////////////////////////////// | 92 ////////////////////////////////////////////////////////////////////////////// |
92 class WebDataRequestManager { | 93 class WebDataRequestManager { |
93 public: | 94 public: |
94 WebDataRequestManager(); | 95 WebDataRequestManager(); |
95 | 96 |
96 ~WebDataRequestManager(); | 97 ~WebDataRequestManager(); |
97 | 98 |
98 // Cancel any pending request. | 99 // Tries to cancel request, returns true if request was found and |
100 // cancelled successfully -- used for clean up of WebDataRequest references. | |
101 bool MaybeCancelRequest(WebDataServiceBase::Handle h); | |
102 | |
103 // Cancel any pending request (expects pending_requests_ map to contain |h|). | |
erikwright (departed)
2013/01/16 19:00:23
replace 'expects' with something more explicit. Do
| |
99 void CancelRequest(WebDataServiceBase::Handle h); | 104 void CancelRequest(WebDataServiceBase::Handle h); |
100 | 105 |
101 // Invoked by request implementations when a request has been processed. | 106 // Invoked by the WebDataService when |request| has been completed. |
102 void RequestCompleted(WebDataServiceBase::Handle h); | 107 void RequestCompleted(scoped_ptr<WebDataRequest> request); |
108 | |
109 // This will notify the consumer in whatever thread was used to create this | |
110 // request. | |
111 void RequestCompletedOnThread(scoped_ptr<WebDataRequest> request); | |
erikwright (departed)
2013/01/16 19:00:23
This can be private, right?
| |
103 | 112 |
104 // Register the request as a pending request. | 113 // Register the request as a pending request. |
105 void RegisterRequest(WebDataRequest* request); | 114 void RegisterRequest(WebDataRequest* request); |
106 | 115 |
107 // Return the next request handle. | 116 // Return the next request handle. |
108 int GetNextRequestHandle(); | 117 int GetNextRequestHandle(); |
109 | 118 |
110 private: | 119 private: |
111 // A lock to protect pending requests and next request handle. | 120 // A lock to protect pending requests and next request handle. |
112 base::Lock pending_lock_; | 121 base::Lock pending_lock_; |
113 | 122 |
114 // Next handle to be used for requests. Incremented for each use. | 123 // Next handle to be used for requests. Incremented for each use. |
115 WebDataServiceBase::Handle next_request_handle_; | 124 WebDataServiceBase::Handle next_request_handle_; |
116 | 125 |
117 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; | 126 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; |
118 RequestMap pending_requests_; | 127 RequestMap pending_requests_; |
119 | 128 |
120 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); | 129 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); |
121 }; | 130 }; |
122 | 131 |
123 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | 132 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ |
OLD | NEW |