OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 classes collaborate to keep a list of open requests and to | 7 // consumer. These classes collaborate to keep a list of open requests and to |
8 // make sure that requests do not outlive either of the objects involved in the | 8 // make sure that requests do not outlive either of the objects involved in the |
9 // transaction. | 9 // transaction. |
10 // | 10 // |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 consumer_->DidExecute(provider_, handle_); | 580 consumer_->DidExecute(provider_, handle_); |
581 } | 581 } |
582 | 582 |
583 // Cover method for CancelableRequestConsumerBase::WillExecute. | 583 // Cover method for CancelableRequestConsumerBase::WillExecute. |
584 void WillExecute() { | 584 void WillExecute() { |
585 consumer_->WillExecute(provider_, handle_); | 585 consumer_->WillExecute(provider_, handle_); |
586 } | 586 } |
587 | 587 |
588 // The message loop that this request was created on. The callback will | 588 // The message loop that this request was created on. The callback will |
589 // happen on the same thread. | 589 // happen on the same thread. |
590 MessageLoop* callback_thread_; | 590 base::MessageLoop* callback_thread_; |
591 | 591 |
592 // The provider for this request. When we execute, we will notify this that | 592 // The provider for this request. When we execute, we will notify this that |
593 // request is complete to it can remove us from the requests it tracks. | 593 // request is complete to it can remove us from the requests it tracks. |
594 CancelableRequestProvider* provider_; | 594 CancelableRequestProvider* provider_; |
595 | 595 |
596 // Notified after we execute that the request is complete. This should only | 596 // Notified after we execute that the request is complete. This should only |
597 // be accessed if !canceled_.IsSet(), otherwise the pointer is invalid. | 597 // be accessed if !canceled_.IsSet(), otherwise the pointer is invalid. |
598 CancelableRequestConsumerBase* consumer_; | 598 CancelableRequestConsumerBase* consumer_; |
599 | 599 |
600 // The handle to this request inside the provider. This will be initialized | 600 // The handle to this request inside the provider. This will be initialized |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // calling this. It is optional in the cancelled case. In the non-cancelled | 663 // calling this. It is optional in the cancelled case. In the non-cancelled |
664 // case, this MUST be called. | 664 // case, this MUST be called. |
665 // | 665 // |
666 // If there are any pointers in the parameters, they must live at least as | 666 // If there are any pointers in the parameters, they must live at least as |
667 // long as the request so that it can be forwarded to the other thread. | 667 // long as the request so that it can be forwarded to the other thread. |
668 // For complex objects, this would typically be done by having a derived | 668 // For complex objects, this would typically be done by having a derived |
669 // request own the data itself. | 669 // request own the data itself. |
670 void ForwardResult(const TupleType& param) { | 670 void ForwardResult(const TupleType& param) { |
671 DCHECK(callback_.get()); | 671 DCHECK(callback_.get()); |
672 if (!canceled()) { | 672 if (!canceled()) { |
673 if (callback_thread_ == MessageLoop::current()) { | 673 if (callback_thread_ == base::MessageLoop::current()) { |
674 // We can do synchronous callbacks when we're on the same thread. | 674 // We can do synchronous callbacks when we're on the same thread. |
675 ExecuteCallback(param); | 675 ExecuteCallback(param); |
676 } else { | 676 } else { |
677 callback_thread_->PostTask( | 677 callback_thread_->PostTask( |
678 FROM_HERE, | 678 FROM_HERE, |
679 base::Bind(&CancelableRequest<CB>::ExecuteCallback, this, param)); | 679 base::Bind(&CancelableRequest<CB>::ExecuteCallback, this, param)); |
680 } | 680 } |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 } | 1007 } |
1008 | 1008 |
1009 // The value. | 1009 // The value. |
1010 Type value; | 1010 Type value; |
1011 | 1011 |
1012 protected: | 1012 protected: |
1013 virtual ~CancelableRequest1() {} | 1013 virtual ~CancelableRequest1() {} |
1014 }; | 1014 }; |
1015 | 1015 |
1016 #endif // CHROME_BROWSER_COMMON_CANCELABLE_REQUEST_H_ | 1016 #endif // CHROME_BROWSER_COMMON_CANCELABLE_REQUEST_H_ |
OLD | NEW |