Chromium Code Reviews| 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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 | 652 |
| 653 private: | 653 private: |
| 654 // Executes the callback and notifies the provider and the consumer that this | 654 // Executes the callback and notifies the provider and the consumer that this |
| 655 // request has been completed. This must be called on the callback_thread_. | 655 // request has been completed. This must be called on the callback_thread_. |
| 656 void ExecuteCallback(const TupleType& param) { | 656 void ExecuteCallback(const TupleType& param) { |
| 657 if (!canceled_.IsSet()) { | 657 if (!canceled_.IsSet()) { |
| 658 WillExecute(); | 658 WillExecute(); |
| 659 | 659 |
| 660 // Execute the callback. | 660 // Execute the callback. |
| 661 callback_->RunWithParams(param); | 661 callback_->RunWithParams(param); |
| 662 } | |
| 662 | 663 |
| 663 // Notify the provider that the request is complete. The provider will | 664 // Notify the provider that the request is complete. The provider will |
| 664 // notify the consumer for us. | 665 // notify the consumer for us. Note that in the case where the callback |
| 666 // does |delete this|, we may be canceled when the callback returns. | |
| 667 if (!canceled_.IsSet()) | |
|
sky
2011/05/10 22:56:29
If 'this' has been deleted by RunWIthParams, than
Sheridan Rawlins
2011/05/10 23:09:48
Ok, so the comment is wrong. It does technically
| |
| 665 NotifyCompleted(); | 668 NotifyCompleted(); |
| 666 } | |
| 667 } | 669 } |
| 668 | 670 |
| 669 // This should only be executed if !canceled_.IsSet(), | 671 // This should only be executed if !canceled_.IsSet(), |
| 670 // otherwise the pointers may be invalid. | 672 // otherwise the pointers may be invalid. |
| 671 scoped_ptr<CallbackType> callback_; | 673 scoped_ptr<CallbackType> callback_; |
| 672 }; | 674 }; |
| 673 | 675 |
| 674 // A CancelableRequest with a single value. This is intended for use when | 676 // A CancelableRequest with a single value. This is intended for use when |
| 675 // the provider provides a single value. The provider fills the result into | 677 // the provider provides a single value. The provider fills the result into |
| 676 // the value, and notifies the request with a pointer to the value. For example, | 678 // the value, and notifies the request with a pointer to the value. For example, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 695 } | 697 } |
| 696 | 698 |
| 697 // The value. | 699 // The value. |
| 698 Type value; | 700 Type value; |
| 699 | 701 |
| 700 protected: | 702 protected: |
| 701 virtual ~CancelableRequest1() {} | 703 virtual ~CancelableRequest1() {} |
| 702 }; | 704 }; |
| 703 | 705 |
| 704 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ | 706 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ |
| OLD | NEW |