Chromium Code Reviews| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 69 |
| 70 void URLRequestAdapter::EnableChunkedUpload() { | 70 void URLRequestAdapter::EnableChunkedUpload() { |
| 71 chunked_upload_ = true; | 71 chunked_upload_ = true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void URLRequestAdapter::AppendChunk(const char* bytes, int bytes_len, | 74 void URLRequestAdapter::AppendChunk(const char* bytes, int bytes_len, |
| 75 bool is_last_chunk) { | 75 bool is_last_chunk) { |
| 76 VLOG(1) << "AppendChunk, len: " << bytes_len << ", last: " << is_last_chunk; | 76 VLOG(1) << "AppendChunk, len: " << bytes_len << ", last: " << is_last_chunk; |
| 77 scoped_ptr<char[]> buf(new char[bytes_len]); | 77 scoped_ptr<char[]> buf(new char[bytes_len]); |
| 78 memcpy(buf.get(), bytes, bytes_len); | 78 memcpy(buf.get(), bytes, bytes_len); |
| 79 context_->GetNetworkTaskRunner()->PostTask( | 79 context_->RunTask(base::Bind(&URLRequestAdapter::OnAppendChunk, |
| 80 FROM_HERE, | 80 base::Unretained(this), |
| 81 base::Bind(&URLRequestAdapter::OnAppendChunk, | 81 Passed(buf.Pass()), |
| 82 base::Unretained(this), | 82 bytes_len, |
| 83 Passed(buf.Pass()), | 83 is_last_chunk)); |
| 84 bytes_len, | |
| 85 is_last_chunk)); | |
| 86 } | 84 } |
| 87 | 85 |
| 88 std::string URLRequestAdapter::GetHeader(const std::string& name) const { | 86 std::string URLRequestAdapter::GetHeader(const std::string& name) const { |
| 89 std::string value; | 87 std::string value; |
| 90 if (url_request_ != NULL) { | 88 if (url_request_ != NULL) { |
| 91 url_request_->GetResponseHeaderByName(name, &value); | 89 url_request_->GetResponseHeaderByName(name, &value); |
| 92 } | 90 } |
| 93 return value; | 91 return value; |
| 94 } | 92 } |
| 95 | 93 |
| 96 net::HttpResponseHeaders* URLRequestAdapter::GetResponseHeaders() const { | 94 net::HttpResponseHeaders* URLRequestAdapter::GetResponseHeaders() const { |
| 97 if (url_request_ == NULL) { | 95 if (url_request_ == NULL) { |
| 98 return NULL; | 96 return NULL; |
| 99 } | 97 } |
| 100 return url_request_->response_headers(); | 98 return url_request_->response_headers(); |
| 101 } | 99 } |
| 102 | 100 |
| 103 std::string URLRequestAdapter::GetNegotiatedProtocol() const { | 101 std::string URLRequestAdapter::GetNegotiatedProtocol() const { |
| 104 if (url_request_ == NULL) | 102 if (url_request_ == NULL) |
| 105 return std::string(); | 103 return std::string(); |
| 106 return url_request_->response_info().npn_negotiated_protocol; | 104 return url_request_->response_info().npn_negotiated_protocol; |
| 107 } | 105 } |
| 108 | 106 |
| 109 void URLRequestAdapter::Start() { | 107 void URLRequestAdapter::Start() { |
| 110 context_->GetNetworkTaskRunner()->PostTask( | 108 context_->RunTask(base::Bind(&URLRequestAdapter::OnInitiateConnection, |
| 111 FROM_HERE, | 109 base::Unretained(this))); |
| 112 base::Bind(&URLRequestAdapter::OnInitiateConnection, | |
| 113 base::Unretained(this))); | |
| 114 } | 110 } |
| 115 | 111 |
| 116 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, | 112 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, |
| 117 int bytes_len, bool is_last_chunk) { | 113 int bytes_len, bool is_last_chunk) { |
| 118 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); | 114 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); |
| 119 } | 115 } |
| 120 | 116 |
| 121 void URLRequestAdapter::OnInitiateConnection() { | 117 void URLRequestAdapter::OnInitiateConnection() { |
| 122 if (canceled_) { | 118 if (canceled_) { |
| 123 return; | 119 return; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 151 url_request_->Start(); | 147 url_request_->Start(); |
| 152 } | 148 } |
| 153 | 149 |
| 154 void URLRequestAdapter::Cancel() { | 150 void URLRequestAdapter::Cancel() { |
| 155 if (canceled_) { | 151 if (canceled_) { |
| 156 return; | 152 return; |
| 157 } | 153 } |
| 158 | 154 |
| 159 canceled_ = true; | 155 canceled_ = true; |
| 160 | 156 |
| 161 context_->GetNetworkTaskRunner()->PostTask( | 157 context_->RunTask( |
| 162 FROM_HERE, | |
| 163 base::Bind(&URLRequestAdapter::OnCancelRequest, base::Unretained(this))); | 158 base::Bind(&URLRequestAdapter::OnCancelRequest, base::Unretained(this))); |
| 164 } | 159 } |
| 165 | 160 |
| 166 void URLRequestAdapter::OnCancelRequest() { | 161 void URLRequestAdapter::OnCancelRequest() { |
| 167 VLOG(1) << "Canceling chromium request: " << url_.possibly_invalid_spec(); | 162 VLOG(1) << "Canceling chromium request: " << url_.possibly_invalid_spec(); |
| 168 | 163 |
| 169 if (url_request_ != NULL) { | 164 if (url_request_ != NULL) { |
| 170 url_request_->Cancel(); | 165 url_request_->Cancel(); |
| 171 } | 166 } |
| 172 | 167 |
| 173 OnRequestCanceled(); | 168 OnRequestCanceled(); |
| 174 } | 169 } |
| 175 | 170 |
| 176 void URLRequestAdapter::Destroy() { | 171 void URLRequestAdapter::Destroy() { |
| 177 context_->GetNetworkTaskRunner()->PostTask( | 172 context_->GetNetworkTaskRunner()->PostTask( |
| 178 FROM_HERE, base::Bind(&URLRequestAdapter::OnDestroyRequest, this)); | 173 FROM_HERE, base::Bind(&URLRequestAdapter::OnDestroyRequest, this)); |
|
mmenke
2014/10/02 22:11:52
Sorry, this should also use RunTask, as it's theor
xunjieli
2014/10/03 14:32:55
Done.
| |
| 179 } | 174 } |
| 180 | 175 |
| 181 // static | 176 // static |
| 182 void URLRequestAdapter::OnDestroyRequest(URLRequestAdapter* self) { | 177 void URLRequestAdapter::OnDestroyRequest(URLRequestAdapter* self) { |
| 183 VLOG(1) << "Destroying chromium request: " | 178 VLOG(1) << "Destroying chromium request: " |
| 184 << self->url_.possibly_invalid_spec(); | 179 << self->url_.possibly_invalid_spec(); |
| 185 delete self; | 180 delete self; |
| 186 } | 181 } |
| 187 | 182 |
| 188 void URLRequestAdapter::OnResponseStarted(net::URLRequest* request) { | 183 void URLRequestAdapter::OnResponseStarted(net::URLRequest* request) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 285 |
| 291 delegate_->OnBytesRead(this); | 286 delegate_->OnBytesRead(this); |
| 292 delegate_->OnRequestFinished(this); | 287 delegate_->OnRequestFinished(this); |
| 293 } | 288 } |
| 294 | 289 |
| 295 unsigned char* URLRequestAdapter::Data() const { | 290 unsigned char* URLRequestAdapter::Data() const { |
| 296 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); | 291 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); |
| 297 } | 292 } |
| 298 | 293 |
| 299 } // namespace cronet | 294 } // namespace cronet |
| OLD | NEW |