| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "url_request_adapter.h" | 5 #include "url_request_adapter.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void URLRequestAdapter::Start() { | 119 void URLRequestAdapter::Start() { |
| 120 context_->PostTaskToNetworkThread( | 120 context_->PostTaskToNetworkThread( |
| 121 FROM_HERE, | 121 FROM_HERE, |
| 122 base::Bind(&URLRequestAdapter::OnInitiateConnection, | 122 base::Bind(&URLRequestAdapter::OnInitiateConnection, |
| 123 base::Unretained(this))); | 123 base::Unretained(this))); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, | 126 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, |
| 127 int bytes_len, bool is_last_chunk) { | 127 int bytes_len, bool is_last_chunk) { |
| 128 DCHECK(OnNetworkThread()); | 128 DCHECK(OnNetworkThread()); |
| 129 // Request could have completed and been destroyed on the network thread |
| 130 // while appendChunk was posting the task from an application thread. |
| 131 if (!url_request_) { |
| 132 VLOG(1) << "Cannot append chunk to destroyed request: " |
| 133 << url_.possibly_invalid_spec().c_str(); |
| 134 return; |
| 135 } |
| 129 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); | 136 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); |
| 130 } | 137 } |
| 131 | 138 |
| 132 void URLRequestAdapter::OnInitiateConnection() { | 139 void URLRequestAdapter::OnInitiateConnection() { |
| 133 DCHECK(OnNetworkThread()); | 140 DCHECK(OnNetworkThread()); |
| 134 if (canceled_) { | 141 if (canceled_) { |
| 135 return; | 142 return; |
| 136 } | 143 } |
| 137 | 144 |
| 138 VLOG(1) << "Starting chromium request: " | 145 VLOG(1) << "Starting chromium request: " |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 unsigned char* URLRequestAdapter::Data() const { | 344 unsigned char* URLRequestAdapter::Data() const { |
| 338 DCHECK(OnNetworkThread()); | 345 DCHECK(OnNetworkThread()); |
| 339 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); | 346 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); |
| 340 } | 347 } |
| 341 | 348 |
| 342 bool URLRequestAdapter::OnNetworkThread() const { | 349 bool URLRequestAdapter::OnNetworkThread() const { |
| 343 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 350 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
| 344 } | 351 } |
| 345 | 352 |
| 346 } // namespace cronet | 353 } // namespace cronet |
| OLD | NEW |