OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // |
11 // If you do not need to return data to the consumer, do not use this system, | 11 // If you do not need to return data to the consumer, do not use this system, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // // Depending on your typedefs, one of these two forms will be more | 73 // // Depending on your typedefs, one of these two forms will be more |
74 // // convenient: | 74 // // convenient: |
75 // request->ForwardResult(Tuple1<int>(return_value)); | 75 // request->ForwardResult(Tuple1<int>(return_value)); |
76 // | 76 // |
77 // // -- or -- (inferior in this case) | 77 // // -- or -- (inferior in this case) |
78 // request->ForwardResult(Frontend::RequestCallbackType::TupleType( | 78 // request->ForwardResult(Frontend::RequestCallbackType::TupleType( |
79 // return_value)); | 79 // return_value)); |
80 // } | 80 // } |
81 // }; | 81 // }; |
82 | 82 |
83 #ifndef CHROME_BROWSER_CANCELABLE_REQUEST_H_ | 83 #ifndef CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
84 #define CHROME_BROWSER_CANCELABLE_REQUEST_H_ | 84 #define CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
85 | 85 |
86 #include <map> | 86 #include <map> |
87 #include <vector> | 87 #include <vector> |
88 | 88 |
89 #include "base/basictypes.h" | 89 #include "base/basictypes.h" |
90 #include "base/lock.h" | 90 #include "base/lock.h" |
91 #include "base/logging.h" | 91 #include "base/logging.h" |
92 #include "base/message_loop.h" | 92 #include "base/message_loop.h" |
93 #include "base/ref_counted.h" | 93 #include "base/ref_counted.h" |
94 #include "base/task.h" | 94 #include "base/task.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return provider < other.provider; | 267 return provider < other.provider; |
268 return handle < other.handle; | 268 return handle < other.handle; |
269 } | 269 } |
270 | 270 |
271 CancelableRequestProvider* provider; | 271 CancelableRequestProvider* provider; |
272 CancelableRequestProvider::Handle handle; | 272 CancelableRequestProvider::Handle handle; |
273 }; | 273 }; |
274 typedef std::map<PendingRequest, T> PendingRequestList; | 274 typedef std::map<PendingRequest, T> PendingRequestList; |
275 | 275 |
276 virtual T get_initial_t() const { | 276 virtual T get_initial_t() const { |
277 return 0; | 277 return NULL; |
278 } | 278 } |
279 | 279 |
280 virtual void OnRequestAdded(CancelableRequestProvider* provider, | 280 virtual void OnRequestAdded(CancelableRequestProvider* provider, |
281 CancelableRequestProvider::Handle handle) { | 281 CancelableRequestProvider::Handle handle) { |
282 DCHECK(pending_requests_.find(PendingRequest(provider, handle)) == | 282 DCHECK(pending_requests_.find(PendingRequest(provider, handle)) == |
283 pending_requests_.end()); | 283 pending_requests_.end()); |
284 pending_requests_[PendingRequest(provider, handle)] = get_initial_t(); | 284 pending_requests_[PendingRequest(provider, handle)] = get_initial_t(); |
285 } | 285 } |
286 | 286 |
287 virtual void OnRequestRemoved(CancelableRequestProvider* provider, | 287 virtual void OnRequestRemoved(CancelableRequestProvider* provider, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 : CancelableRequest<CB>(callback) { | 536 : CancelableRequest<CB>(callback) { |
537 } | 537 } |
538 | 538 |
539 virtual ~CancelableRequest1() { | 539 virtual ~CancelableRequest1() { |
540 } | 540 } |
541 | 541 |
542 // The value. | 542 // The value. |
543 Type value; | 543 Type value; |
544 }; | 544 }; |
545 | 545 |
546 #endif // CHROME_BROWSER_CANCELABLE_REQUEST_H_ | 546 #endif // CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
OLD | NEW |