Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 120 |
| 121 CancelableRequestProvider(); | 121 CancelableRequestProvider(); |
| 122 virtual ~CancelableRequestProvider(); | 122 virtual ~CancelableRequestProvider(); |
| 123 | 123 |
| 124 // Called by the enduser of the request to cancel it. This MUST be called on | 124 // Called by the enduser of the request to cancel it. This MUST be called on |
| 125 // the same thread that originally issued the request (which is also the same | 125 // the same thread that originally issued the request (which is also the same |
| 126 // thread that would have received the callback if it was not canceled). | 126 // thread that would have received the callback if it was not canceled). |
| 127 // handle must be for a valid pending (not yet complete or cancelled) request. | 127 // handle must be for a valid pending (not yet complete or cancelled) request. |
| 128 void CancelRequest(Handle handle); | 128 void CancelRequest(Handle handle); |
| 129 | 129 |
| 130 // Provide factory method so Handle can be treated as opaque. | |
| 131 static Handle InvalidHandle(); | |
| 132 | |
| 133 // Provide validity method so Handle can be treated as opaque. | |
| 134 static bool HandleIsValid(Handle handle); | |
| 135 | |
| 130 protected: | 136 protected: |
| 137 static const Handle kFirstHandle; | |
|
James Hawkins
2011/03/22 22:59:49
Can these be private?
Sheridan Rawlins
2011/03/23 00:39:52
Done.
| |
| 138 static const Handle kInvalidHandle; | |
| 139 | |
| 131 // Adds a new request and initializes it. This is called by a derived class | 140 // Adds a new request and initializes it. This is called by a derived class |
| 132 // to add a new request. The request's Init() will be called (which is why | 141 // to add a new request. The request's Init() will be called (which is why |
| 133 // the consumer is required. The handle to the new request is returned. | 142 // the consumer is required. The handle to the new request is returned. |
| 134 Handle AddRequest(CancelableRequestBase* request, | 143 Handle AddRequest(CancelableRequestBase* request, |
| 135 CancelableRequestConsumerBase* consumer); | 144 CancelableRequestConsumerBase* consumer); |
| 136 | 145 |
| 137 // Called by the CancelableRequest when the request has executed. It will | 146 // Called by the CancelableRequest when the request has executed. It will |
| 138 // be removed from the list of pending requests (as opposed to canceling, | 147 // be removed from the list of pending requests (as opposed to canceling, |
| 139 // which will also set some state on the request). | 148 // which will also set some state on the request). |
| 140 void RequestCompleted(Handle handle); | 149 void RequestCompleted(Handle handle); |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 } | 704 } |
| 696 | 705 |
| 697 // The value. | 706 // The value. |
| 698 Type value; | 707 Type value; |
| 699 | 708 |
| 700 protected: | 709 protected: |
| 701 virtual ~CancelableRequest1() {} | 710 virtual ~CancelableRequest1() {} |
| 702 }; | 711 }; |
| 703 | 712 |
| 704 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ | 713 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ |
| OLD | NEW |