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 "components/cronet/android/url_request_adapter.h" | 5 #include "components/cronet/android/url_request_adapter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 context_->PostTaskToNetworkThread( | 123 context_->PostTaskToNetworkThread( |
124 FROM_HERE, | 124 FROM_HERE, |
125 base::Bind(&URLRequestAdapter::OnInitiateConnection, | 125 base::Bind(&URLRequestAdapter::OnInitiateConnection, |
126 base::Unretained(this))); | 126 base::Unretained(this))); |
127 } | 127 } |
128 | 128 |
129 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, | 129 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, |
130 int bytes_len, bool is_last_chunk) { | 130 int bytes_len, bool is_last_chunk) { |
131 DCHECK(OnNetworkThread()); | 131 DCHECK(OnNetworkThread()); |
132 // Request could have completed and been destroyed on the network thread | 132 // Request could have completed and been destroyed on the network thread |
133 // while appendChunk was posting the task from an application thread. | 133 // while appendChunk was posting the task from an application thread. |
eroman
2016/03/22 19:05:37
This comment and subsequent VLOG() don't seem cong
mmenke
2016/03/22 20:01:50
Comment seems correct - you can actually succeed w
| |
134 if (!url_request_) { | 134 if (!chunked_upload_writer_->AppendData(bytes.get(), bytes_len, |
135 is_last_chunk)) { | |
135 VLOG(1) << "Cannot append chunk to destroyed request: " | 136 VLOG(1) << "Cannot append chunk to destroyed request: " |
136 << url_.possibly_invalid_spec().c_str(); | 137 << url_.possibly_invalid_spec().c_str(); |
137 return; | 138 return; |
138 } | 139 } |
139 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); | |
140 } | 140 } |
141 | 141 |
142 void URLRequestAdapter::OnInitiateConnection() { | 142 void URLRequestAdapter::OnInitiateConnection() { |
143 DCHECK(OnNetworkThread()); | 143 DCHECK(OnNetworkThread()); |
144 if (canceled_) { | 144 if (canceled_) { |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 VLOG(1) << "Starting chromium request: " | 148 VLOG(1) << "Starting chromium request: " |
149 << url_.possibly_invalid_spec().c_str() | 149 << url_.possibly_invalid_spec().c_str() |
150 << " priority: " << RequestPriorityToString(priority_); | 150 << " priority: " << RequestPriorityToString(priority_); |
151 url_request_ = context_->GetURLRequestContext()->CreateRequest( | 151 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
152 url_, net::DEFAULT_PRIORITY, this); | 152 url_, net::DEFAULT_PRIORITY, this); |
153 int flags = net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES; | 153 int flags = net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES; |
154 if (context_->load_disable_cache()) | 154 if (context_->load_disable_cache()) |
155 flags |= net::LOAD_DISABLE_CACHE; | 155 flags |= net::LOAD_DISABLE_CACHE; |
156 url_request_->SetLoadFlags(flags); | 156 url_request_->SetLoadFlags(flags); |
157 url_request_->set_method(method_); | 157 url_request_->set_method(method_); |
158 url_request_->SetExtraRequestHeaders(headers_); | 158 url_request_->SetExtraRequestHeaders(headers_); |
159 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { | 159 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { |
160 std::string user_agent; | 160 std::string user_agent; |
161 user_agent = context_->GetUserAgent(url_); | 161 user_agent = context_->GetUserAgent(url_); |
162 url_request_->SetExtraRequestHeaderByName( | 162 url_request_->SetExtraRequestHeaderByName( |
163 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); | 163 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); |
164 } | 164 } |
165 | 165 |
166 if (upload_data_stream_) { | 166 if (upload_data_stream_) { |
167 url_request_->set_upload(std::move(upload_data_stream_)); | 167 url_request_->set_upload(std::move(upload_data_stream_)); |
168 } else if (chunked_upload_) { | 168 } else if (chunked_upload_) { |
169 url_request_->EnableChunkedUpload(); | 169 scoped_ptr<net::ChunkedUploadDataStream> chunked_upload_data_stream( |
170 new net::ChunkedUploadDataStream(0)); | |
171 chunked_upload_writer_ = chunked_upload_data_stream->CreateWriter(); | |
172 url_request_->set_upload(std::move(chunked_upload_data_stream)); | |
eroman
2016/03/22 19:05:37
This looked wrong when first reading it because of
mmenke
2016/03/22 20:01:50
Done.
| |
170 } | 173 } |
171 | 174 |
172 url_request_->SetPriority(priority_); | 175 url_request_->SetPriority(priority_); |
173 | 176 |
174 url_request_->Start(); | 177 url_request_->Start(); |
175 } | 178 } |
176 | 179 |
177 void URLRequestAdapter::Cancel() { | 180 void URLRequestAdapter::Cancel() { |
178 context_->PostTaskToNetworkThread( | 181 context_->PostTaskToNetworkThread( |
179 FROM_HERE, | 182 FROM_HERE, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 unsigned char* URLRequestAdapter::Data() const { | 324 unsigned char* URLRequestAdapter::Data() const { |
322 DCHECK(OnNetworkThread()); | 325 DCHECK(OnNetworkThread()); |
323 return reinterpret_cast<unsigned char*>(read_buffer_->data()); | 326 return reinterpret_cast<unsigned char*>(read_buffer_->data()); |
324 } | 327 } |
325 | 328 |
326 bool URLRequestAdapter::OnNetworkThread() const { | 329 bool URLRequestAdapter::OnNetworkThread() const { |
327 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 330 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
328 } | 331 } |
329 | 332 |
330 } // namespace cronet | 333 } // namespace cronet |
OLD | NEW |