Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: content/browser/cancelable_request.h

Issue 7001015: Let CancelableRequest Execute callbacks which do delete this. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove comment's ambiguous |delete this|. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 it is possible for the callback to
666 // cancel this request; we must check canceled again.
667 if (!canceled_.IsSet())
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
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_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698