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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (result != MOJO_RESULT_OK) { | 99 if (result != MOJO_RESULT_OK) { |
100 completion_status_.error_code = net::ERR_FAILED; | 100 completion_status_.error_code = net::ERR_FAILED; |
101 has_seen_end_of_data_ = true; | 101 has_seen_end_of_data_ = true; |
102 has_received_completion_ = true; | 102 has_received_completion_ = true; |
103 NotifyCompletionIfAppropriate(); | 103 NotifyCompletionIfAppropriate(); |
104 return; | 104 return; |
105 } | 105 } |
106 ResourceDispatcher::PendingRequestInfo* request_info = | 106 ResourceDispatcher::PendingRequestInfo* request_info = |
107 resource_dispatcher_->GetPendingRequestInfo(request_id_); | 107 resource_dispatcher_->GetPendingRequestInfo(request_id_); |
108 DCHECK(request_info); | 108 DCHECK(request_info); |
109 request_info->peer->OnReceivedData(base::WrapUnique( | 109 request_info->peer->OnReceivedData(base::MakeUnique<ReceivedData>( |
110 new ReceivedData(static_cast<const char*>(buffer), available, this))); | 110 static_cast<const char*>(buffer), available, this)); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() { | 114 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() { |
115 if (has_been_cancelled_) | 115 if (has_been_cancelled_) |
116 return; | 116 return; |
117 if (!has_received_completion_ || !has_seen_end_of_data_) | 117 if (!has_received_completion_ || !has_seen_end_of_data_) |
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 |