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 "mojo/services/network/url_loader_impl.h" | 5 #include "mojo/services/network/url_loader_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/trace_event/trace_event.h" | |
| 11 #include "mojo/common/common_type_converters.h" | 12 #include "mojo/common/common_type_converters.h" |
| 12 #include "mojo/common/url_type_converters.h" | 13 #include "mojo/common/url_type_converters.h" |
| 13 #include "mojo/services/network/net_adapters.h" | 14 #include "mojo/services/network/net_adapters.h" |
| 14 #include "mojo/services/network/network_context.h" | 15 #include "mojo/services/network/network_context.h" |
| 15 #include "net/base/elements_upload_data_stream.h" | 16 #include "net/base/elements_upload_data_stream.h" |
| 16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 18 #include "net/base/upload_bytes_element_reader.h" | 19 #include "net/base/upload_bytes_element_reader.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 49 url_request->GetMimeType(&mime_type); | 50 url_request->GetMimeType(&mime_type); |
| 50 response->mime_type = mime_type; | 51 response->mime_type = mime_type; |
| 51 | 52 |
| 52 std::string charset; | 53 std::string charset; |
| 53 url_request->GetCharset(&charset); | 54 url_request->GetCharset(&charset); |
| 54 response->charset = charset; | 55 response->charset = charset; |
| 55 | 56 |
| 56 return response.Pass(); | 57 return response.Pass(); |
| 57 } | 58 } |
| 58 | 59 |
| 60 void RunCallbackAndTrace(const char* event_name, | |
| 61 void* id, | |
| 62 const Callback<void(URLResponsePtr)>& callback, | |
| 63 URLResponsePtr response) { | |
| 64 callback.Run(response.Pass()); | |
| 65 TRACE_EVENT_ASYNC_END0("net", event_name, id); | |
| 66 } | |
| 67 | |
| 59 // Reads the request body upload data from a DataPipe. | 68 // Reads the request body upload data from a DataPipe. |
| 60 class UploadDataPipeElementReader : public net::UploadElementReader { | 69 class UploadDataPipeElementReader : public net::UploadElementReader { |
| 61 public: | 70 public: |
| 62 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) | 71 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) |
| 63 : pipe_(pipe.Pass()), num_bytes_(0) {} | 72 : pipe_(pipe.Pass()), num_bytes_(0) {} |
| 64 ~UploadDataPipeElementReader() override {} | 73 ~UploadDataPipeElementReader() override {} |
| 65 | 74 |
| 66 // UploadElementReader overrides: | 75 // UploadElementReader overrides: |
| 67 int Init(const net::CompletionCallback& callback) override { | 76 int Init(const net::CompletionCallback& callback) override { |
| 68 offset_ = 0; | 77 offset_ = 0; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 } | 299 } |
| 291 | 300 |
| 292 void URLLoaderImpl::Cleanup() { | 301 void URLLoaderImpl::Cleanup() { |
| 293 // The associated network context is going away and we have to destroy | 302 // The associated network context is going away and we have to destroy |
| 294 // net::URLRequest hold by this loader. | 303 // net::URLRequest hold by this loader. |
| 295 delete this; | 304 delete this; |
| 296 } | 305 } |
| 297 | 306 |
| 298 void URLLoaderImpl::Start(URLRequestPtr request, | 307 void URLLoaderImpl::Start(URLRequestPtr request, |
| 299 const Callback<void(URLResponsePtr)>& callback) { | 308 const Callback<void(URLResponsePtr)>& callback) { |
| 309 TRACE_EVENT_ASYNC_BEGIN1("net", "URLLoaderImpl::Start", this, "url", | |
| 310 request->url.get()); | |
| 311 Callback<void(URLResponsePtr)> traced_callback = | |
| 312 base::Bind(&RunCallbackAndTrace, "URLLoaderImpl::Start", this, callback); | |
| 313 | |
| 300 if (url_request_) { | 314 if (url_request_) { |
| 301 SendError(net::ERR_UNEXPECTED, callback); | 315 SendError(net::ERR_UNEXPECTED, traced_callback); |
| 302 return; | 316 return; |
| 303 } | 317 } |
| 304 | 318 |
| 305 callback_ = callback; | 319 callback_ = traced_callback; |
| 306 StartInternal(request.Pass()); | 320 StartInternal(request.Pass()); |
| 307 } | 321 } |
| 308 | 322 |
| 309 void URLLoaderImpl::FollowRedirect( | 323 void URLLoaderImpl::FollowRedirect( |
| 310 const Callback<void(URLResponsePtr)>& callback) { | 324 const Callback<void(URLResponsePtr)>& callback) { |
| 325 TRACE_EVENT_ASYNC_BEGIN0("net", "URLLoaderImpl::FollowRedirect", this); | |
| 326 Callback<void(URLResponsePtr)> traced_callback = base::Bind( | |
| 327 &RunCallbackAndTrace, "URLLoaderImpl::FollowRedirect", this, callback); | |
|
ppi
2015/08/03 14:50:22
Can the id (here being the value of |this|) be the
| |
| 328 | |
| 311 if (!redirect_info_) { | 329 if (!redirect_info_) { |
| 312 DLOG(ERROR) << "Spurious call to FollowRedirect"; | 330 DLOG(ERROR) << "Spurious call to FollowRedirect"; |
| 313 SendError(net::ERR_UNEXPECTED, callback); | 331 SendError(net::ERR_UNEXPECTED, traced_callback); |
| 314 return; | 332 return; |
| 315 } | 333 } |
| 316 DCHECK(url_request_); | 334 DCHECK(url_request_); |
| 317 DCHECK(url_request_->is_redirecting()); | 335 DCHECK(url_request_->is_redirecting()); |
| 318 DCHECK(!auto_follow_redirects_); | 336 DCHECK(!auto_follow_redirects_); |
| 319 | 337 |
| 320 callback_ = callback; | 338 callback_ = traced_callback; |
| 321 FollowRedirectInternal(); | 339 FollowRedirectInternal(); |
| 322 } | 340 } |
| 323 | 341 |
| 324 void URLLoaderImpl::QueryStatus( | 342 void URLLoaderImpl::QueryStatus( |
| 325 const Callback<void(URLLoaderStatusPtr)>& callback) { | 343 const Callback<void(URLLoaderStatusPtr)>& callback) { |
| 326 URLLoaderStatusPtr status(URLLoaderStatus::New()); | 344 URLLoaderStatusPtr status(URLLoaderStatus::New()); |
| 327 if (url_request_) { | 345 if (url_request_) { |
| 328 // A url request is owned by this class, the status is deduced from it. | 346 // A url request is owned by this class, the status is deduced from it. |
| 329 status->is_loading = url_request_->is_pending(); | 347 status->is_loading = url_request_->is_pending(); |
| 330 if (!url_request_->status().is_success()) | 348 if (!url_request_->status().is_success()) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 if ((*it)->id() == current_fetcher_id_) { | 615 if ((*it)->id() == current_fetcher_id_) { |
| 598 last_status_ = fetcher->QueryStatus(); | 616 last_status_ = fetcher->QueryStatus(); |
| 599 last_status_->is_loading = false; | 617 last_status_->is_loading = false; |
| 600 } | 618 } |
| 601 body_fetchers_.erase(it); | 619 body_fetchers_.erase(it); |
| 602 if (body_fetchers_.empty() and !binding_.is_bound()) | 620 if (body_fetchers_.empty() and !binding_.is_bound()) |
| 603 delete this; | 621 delete this; |
| 604 } | 622 } |
| 605 | 623 |
| 606 } // namespace mojo | 624 } // namespace mojo |
| OLD | NEW |