OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // CancelableRequestProviders and Consumers work together to make requests that | 5 // CancelableRequestProviders and Consumers work together to make requests that |
6 // execute on a background thread in the provider and return data to the | 6 // execute on a background thread in the provider and return data to the |
7 // consumer. These class collaborate to keep a list of open requests and to | 7 // consumer. These class collaborate to keep a list of open requests and to |
8 // make sure that requests to not outlive either of the objects involved in the | 8 // make sure that requests to not outlive either of the objects involved in the |
9 // transaction. | 9 // transaction. |
10 // | 10 // |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 // Returns true if there are any pending requests. | 238 // Returns true if there are any pending requests. |
239 bool HasPendingRequests() const; | 239 bool HasPendingRequests() const; |
240 | 240 |
241 // Returns the number of pending requests. | 241 // Returns the number of pending requests. |
242 size_t PendingRequestCount() const; | 242 size_t PendingRequestCount() const; |
243 | 243 |
244 // Cancels all requests outstanding. | 244 // Cancels all requests outstanding. |
245 void CancelAllRequests(); | 245 void CancelAllRequests(); |
246 | 246 |
| 247 // Cancels all requests outstanding matching the client data. |
| 248 void CancelAllRequestsForClientData(T client_data); |
| 249 |
247 // Returns the handle for the first request that has the specified client data | 250 // Returns the handle for the first request that has the specified client data |
248 // (in |handle|). Returns true if there is a request for the specified client | 251 // (in |handle|). Returns true if there is a request for the specified client |
249 // data, false otherwise. | 252 // data, false otherwise. |
250 bool GetFirstHandleForClientData(T client_data, | 253 bool GetFirstHandleForClientData(T client_data, |
251 CancelableRequestProvider::Handle* handle); | 254 CancelableRequestProvider::Handle* handle); |
252 | 255 |
253 // Gets the client data for all pending requests. | 256 // Gets the client data for all pending requests. |
254 void GetAllClientData(std::vector<T>* data); | 257 void GetAllClientData(std::vector<T>* data); |
255 | 258 |
256 protected: | 259 protected: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 return pending_requests_.size(); | 345 return pending_requests_.size(); |
343 } | 346 } |
344 | 347 |
345 template<class T> | 348 template<class T> |
346 void CancelableRequestConsumerTSimple<T>::CancelAllRequests() { | 349 void CancelableRequestConsumerTSimple<T>::CancelAllRequests() { |
347 // TODO(atwilson): This code is not thread safe as it is called from the | 350 // TODO(atwilson): This code is not thread safe as it is called from the |
348 // consumer thread (via the destructor) and accesses pending_requests_ | 351 // consumer thread (via the destructor) and accesses pending_requests_ |
349 // without acquiring the provider lock (http://crbug.com/85970). | 352 // without acquiring the provider lock (http://crbug.com/85970). |
350 PendingRequestList copied_requests(pending_requests_); | 353 PendingRequestList copied_requests(pending_requests_); |
351 for (typename PendingRequestList::iterator i = copied_requests.begin(); | 354 for (typename PendingRequestList::iterator i = copied_requests.begin(); |
352 i != copied_requests.end(); ++i) | 355 i != copied_requests.end(); ++i) { |
353 i->first.provider->CancelRequest(i->first.handle); | 356 i->first.provider->CancelRequest(i->first.handle); |
| 357 } |
354 copied_requests.clear(); | 358 copied_requests.clear(); |
355 | 359 |
356 // That should have cleared all the pending items. | 360 // That should have cleared all the pending items. |
357 DCHECK(pending_requests_.empty()); | 361 DCHECK(pending_requests_.empty()); |
358 } | 362 } |
359 | 363 |
360 template<class T> | 364 template<class T> |
| 365 void CancelableRequestConsumerTSimple<T>::CancelAllRequestsForClientData( |
| 366 T client_data) { |
| 367 PendingRequestList copied_requests(pending_requests_); |
| 368 for (typename PendingRequestList::const_iterator i = copied_requests.begin(); |
| 369 i != copied_requests.end(); ++i) { |
| 370 if (i->second == client_data) |
| 371 i->first.provider->CancelRequest(i->first.handle); |
| 372 } |
| 373 copied_requests.clear(); |
| 374 } |
| 375 |
| 376 template<class T> |
361 bool CancelableRequestConsumerTSimple<T>::GetFirstHandleForClientData( | 377 bool CancelableRequestConsumerTSimple<T>::GetFirstHandleForClientData( |
362 T client_data, | 378 T client_data, |
363 CancelableRequestProvider::Handle* handle) { | 379 CancelableRequestProvider::Handle* handle) { |
364 for (typename PendingRequestList::const_iterator i = | 380 for (typename PendingRequestList::const_iterator i = |
365 pending_requests_.begin(); i != pending_requests_.end(); ++i) { | 381 pending_requests_.begin(); i != pending_requests_.end(); ++i) { |
366 if (i->second == client_data) { | 382 if (i->second == client_data) { |
367 *handle = i->first.handle; | 383 *handle = i->first.handle; |
368 return true; | 384 return true; |
369 } | 385 } |
370 } | 386 } |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 723 } |
708 | 724 |
709 // The value. | 725 // The value. |
710 Type value; | 726 Type value; |
711 | 727 |
712 protected: | 728 protected: |
713 virtual ~CancelableRequest1() {} | 729 virtual ~CancelableRequest1() {} |
714 }; | 730 }; |
715 | 731 |
716 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ | 732 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ |
OLD | NEW |