Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: components/cronet/android/url_request_adapter.cc

Issue 617393005: Make URLRequestContextAdapter initialization asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->GetNetworkTaskRunner()->PostTask(
80 FROM_HERE, 80 FROM_HERE,
81 base::Bind(&URLRequestAdapter::OnAppendChunk, 81 base::Bind(&URLRequestAdapter::OnAppendChunk,
82 base::Unretained(this), 82 base::Unretained(this),
83 Passed(buf.Pass()), 83 Passed(buf.Pass()),
84 bytes_len, 84 bytes_len,
85 is_last_chunk)); 85 is_last_chunk));
mmenke 2014/10/02 19:51:18 Need to do the same here (And for basically everyt
xunjieli 2014/10/02 21:39:41 Done.
86 } 86 }
87 87
88 std::string URLRequestAdapter::GetHeader(const std::string& name) const { 88 std::string URLRequestAdapter::GetHeader(const std::string& name) const {
89 std::string value; 89 std::string value;
90 if (url_request_ != NULL) { 90 if (url_request_ != NULL) {
91 url_request_->GetResponseHeaderByName(name, &value); 91 url_request_->GetResponseHeaderByName(name, &value);
92 } 92 }
93 return value; 93 return value;
94 } 94 }
95 95
96 net::HttpResponseHeaders* URLRequestAdapter::GetResponseHeaders() const { 96 net::HttpResponseHeaders* URLRequestAdapter::GetResponseHeaders() const {
97 if (url_request_ == NULL) { 97 if (url_request_ == NULL) {
98 return NULL; 98 return NULL;
99 } 99 }
100 return url_request_->response_headers(); 100 return url_request_->response_headers();
101 } 101 }
102 102
103 std::string URLRequestAdapter::GetNegotiatedProtocol() const { 103 std::string URLRequestAdapter::GetNegotiatedProtocol() const {
104 if (url_request_ == NULL) 104 if (url_request_ == NULL)
105 return std::string(); 105 return std::string();
106 return url_request_->response_info().npn_negotiated_protocol; 106 return url_request_->response_info().npn_negotiated_protocol;
107 } 107 }
108 108
109 void URLRequestAdapter::Start() { 109 void URLRequestAdapter::Start() {
110 context_->GetNetworkTaskRunner()->PostTask( 110 context_->RunTask(base::Bind(&URLRequestAdapter::OnInitiateConnection,
111 FROM_HERE, 111 base::Unretained(this)));
112 base::Bind(&URLRequestAdapter::OnInitiateConnection,
113 base::Unretained(this)));
114 } 112 }
115 113
116 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, 114 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes,
117 int bytes_len, bool is_last_chunk) { 115 int bytes_len, bool is_last_chunk) {
118 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk); 116 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk);
119 } 117 }
120 118
121 void URLRequestAdapter::OnInitiateConnection() { 119 void URLRequestAdapter::OnInitiateConnection() {
122 if (canceled_) { 120 if (canceled_) {
123 return; 121 return;
(...skipping 29 matching lines...) Expand all
153 151
154 void URLRequestAdapter::Cancel() { 152 void URLRequestAdapter::Cancel() {
155 if (canceled_) { 153 if (canceled_) {
156 return; 154 return;
157 } 155 }
158 156
159 canceled_ = true; 157 canceled_ = true;
160 158
161 context_->GetNetworkTaskRunner()->PostTask( 159 context_->GetNetworkTaskRunner()->PostTask(
162 FROM_HERE, 160 FROM_HERE,
163 base::Bind(&URLRequestAdapter::OnCancelRequest, base::Unretained(this))); 161 base::Bind(&URLRequestAdapter::OnCancelRequest, base::Unretained(this)));
mmenke 2014/10/02 19:51:17 Need to do the same here. A bit of a pain, but we
xunjieli 2014/10/02 21:39:41 Done.
164 } 162 }
165 163
166 void URLRequestAdapter::OnCancelRequest() { 164 void URLRequestAdapter::OnCancelRequest() {
167 VLOG(1) << "Canceling chromium request: " << url_.possibly_invalid_spec(); 165 VLOG(1) << "Canceling chromium request: " << url_.possibly_invalid_spec();
168 166
169 if (url_request_ != NULL) { 167 if (url_request_ != NULL) {
170 url_request_->Cancel(); 168 url_request_->Cancel();
171 } 169 }
172 170
173 OnRequestCanceled(); 171 OnRequestCanceled();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 288
291 delegate_->OnBytesRead(this); 289 delegate_->OnBytesRead(this);
292 delegate_->OnRequestFinished(this); 290 delegate_->OnRequestFinished(this);
293 } 291 }
294 292
295 unsigned char* URLRequestAdapter::Data() const { 293 unsigned char* URLRequestAdapter::Data() const {
296 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); 294 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer());
297 } 295 }
298 296
299 } // namespace cronet 297 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698