| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/child/url_response_body_consumer.h" | 5 #include "content/child/url_response_body_consumer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/child/resource_dispatcher.h" | 10 #include "content/child/resource_dispatcher.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 scoped_refptr<URLResponseBodyConsumer> consumer_; | 38 scoped_refptr<URLResponseBodyConsumer> consumer_; |
| 39 | 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(ReceivedData); | 40 DISALLOW_COPY_AND_ASSIGN(ReceivedData); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 URLResponseBodyConsumer::URLResponseBodyConsumer( | 43 URLResponseBodyConsumer::URLResponseBodyConsumer( |
| 44 int request_id, | 44 int request_id, |
| 45 ResourceDispatcher* resource_dispatcher, | 45 ResourceDispatcher* resource_dispatcher, |
| 46 mojo::ScopedDataPipeConsumerHandle handle, | 46 mojo::ScopedDataPipeConsumerHandle handle, |
| 47 base::SingleThreadTaskRunner* task_runner) | 47 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 48 : request_id_(request_id), | 48 : request_id_(request_id), |
| 49 resource_dispatcher_(resource_dispatcher), | 49 resource_dispatcher_(resource_dispatcher), |
| 50 handle_(std::move(handle)), | 50 handle_(std::move(handle)), |
| 51 handle_watcher_(task_runner), |
| 51 has_seen_end_of_data_(!handle_.is_valid()) { | 52 has_seen_end_of_data_(!handle_.is_valid()) { |
| 52 handle_watcher_.Start( | 53 handle_watcher_.Start( |
| 53 handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, | 54 handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, |
| 54 base::Bind(&URLResponseBodyConsumer::OnReadable, base::Unretained(this))); | 55 base::Bind(&URLResponseBodyConsumer::OnReadable, base::Unretained(this))); |
| 55 task_runner->PostTask( | 56 task_runner->PostTask( |
| 56 FROM_HERE, base::Bind(&URLResponseBodyConsumer::OnReadable, AsWeakPtr(), | 57 FROM_HERE, base::Bind(&URLResponseBodyConsumer::OnReadable, AsWeakPtr(), |
| 57 MOJO_RESULT_OK)); | 58 MOJO_RESULT_OK)); |
| 58 } | 59 } |
| 59 | 60 |
| 60 URLResponseBodyConsumer::~URLResponseBodyConsumer() {} | 61 URLResponseBodyConsumer::~URLResponseBodyConsumer() {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 76 void URLResponseBodyConsumer::Reclaim(uint32_t size) { | 77 void URLResponseBodyConsumer::Reclaim(uint32_t size) { |
| 77 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size); | 78 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size); |
| 78 DCHECK_EQ(MOJO_RESULT_OK, result); | 79 DCHECK_EQ(MOJO_RESULT_OK, result); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void URLResponseBodyConsumer::OnReadable(MojoResult unused) { | 82 void URLResponseBodyConsumer::OnReadable(MojoResult unused) { |
| 82 if (has_been_cancelled_ || has_seen_end_of_data_) | 83 if (has_been_cancelled_ || has_seen_end_of_data_) |
| 83 return; | 84 return; |
| 84 | 85 |
| 85 // TODO(yhirano): Suppress notification when deferred. | 86 // TODO(yhirano): Suppress notification when deferred. |
| 86 // TODO(yhirano): Run this operation on the loading task runner. | |
| 87 while (!has_been_cancelled_) { | 87 while (!has_been_cancelled_) { |
| 88 const void* buffer = nullptr; | 88 const void* buffer = nullptr; |
| 89 uint32_t available = 0; | 89 uint32_t available = 0; |
| 90 MojoResult result = mojo::BeginReadDataRaw( | 90 MojoResult result = mojo::BeginReadDataRaw( |
| 91 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE); | 91 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE); |
| 92 if (result == MOJO_RESULT_SHOULD_WAIT) | 92 if (result == MOJO_RESULT_SHOULD_WAIT) |
| 93 return; | 93 return; |
| 94 if (result == MOJO_RESULT_FAILED_PRECONDITION) { | 94 if (result == MOJO_RESULT_FAILED_PRECONDITION) { |
| 95 has_seen_end_of_data_ = true; | 95 has_seen_end_of_data_ = true; |
| 96 NotifyCompletionIfAppropriate(); | 96 NotifyCompletionIfAppropriate(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 118 return; | 118 return; |
| 119 // Cancel this instance in order not to notify twice. | 119 // Cancel this instance in order not to notify twice. |
| 120 Cancel(); | 120 Cancel(); |
| 121 | 121 |
| 122 resource_dispatcher_->OnMessageReceived( | 122 resource_dispatcher_->OnMessageReceived( |
| 123 ResourceMsg_RequestComplete(request_id_, completion_status_)); | 123 ResourceMsg_RequestComplete(request_id_, completion_status_)); |
| 124 // |this| may be deleted. | 124 // |this| may be deleted. |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace content | 127 } // namespace content |
| OLD | NEW |