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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 | 80 |
81 void URLResponseBodyConsumer::Reclaim(uint32_t size) { | 81 void URLResponseBodyConsumer::Reclaim(uint32_t size) { |
82 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size); | 82 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size); |
83 DCHECK_EQ(MOJO_RESULT_OK, result); | 83 DCHECK_EQ(MOJO_RESULT_OK, result); |
84 } | 84 } |
85 | 85 |
86 void URLResponseBodyConsumer::OnReadable(MojoResult unused) { | 86 void URLResponseBodyConsumer::OnReadable(MojoResult unused) { |
87 if (has_been_cancelled_ || has_seen_end_of_data_) | 87 if (has_been_cancelled_ || has_seen_end_of_data_) |
88 return; | 88 return; |
89 | 89 |
90 // Protect |this| as RequestPeer::OnReceivedData may call deref. | |
91 scoped_refptr<URLResponseBodyConsumer> protect(this); | |
nasko
2016/11/08 01:12:12
What causes the OnReceivedData to ref-count down t
yhirano
2016/11/08 01:34:45
RequestPeer::OnReceivedData may cancel the request
nasko
2016/11/08 16:32:15
I was missing the bit about has_been_cancelled_ be
| |
92 | |
90 // TODO(yhirano): Suppress notification when deferred. | 93 // TODO(yhirano): Suppress notification when deferred. |
91 while (!has_been_cancelled_) { | 94 while (!has_been_cancelled_) { |
92 const void* buffer = nullptr; | 95 const void* buffer = nullptr; |
93 uint32_t available = 0; | 96 uint32_t available = 0; |
94 MojoResult result = mojo::BeginReadDataRaw( | 97 MojoResult result = mojo::BeginReadDataRaw( |
95 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE); | 98 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE); |
96 if (result == MOJO_RESULT_SHOULD_WAIT) | 99 if (result == MOJO_RESULT_SHOULD_WAIT) |
97 return; | 100 return; |
98 if (result == MOJO_RESULT_FAILED_PRECONDITION) { | 101 if (result == MOJO_RESULT_FAILED_PRECONDITION) { |
99 has_seen_end_of_data_ = true; | 102 has_seen_end_of_data_ = true; |
(...skipping 22 matching lines...) Expand all Loading... | |
122 return; | 125 return; |
123 // Cancel this instance in order not to notify twice. | 126 // Cancel this instance in order not to notify twice. |
124 Cancel(); | 127 Cancel(); |
125 | 128 |
126 resource_dispatcher_->OnMessageReceived( | 129 resource_dispatcher_->OnMessageReceived( |
127 ResourceMsg_RequestComplete(request_id_, completion_status_)); | 130 ResourceMsg_RequestComplete(request_id_, completion_status_)); |
128 // |this| may be deleted. | 131 // |this| may be deleted. |
129 } | 132 } |
130 | 133 |
131 } // namespace content | 134 } // namespace content |
OLD | NEW |