Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/loader/mojo_async_resource_handler.h" | 5 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/browser/loader/downloaded_temp_file_impl.h" | 17 #include "content/browser/loader/downloaded_temp_file_impl.h" |
| 18 #include "content/browser/loader/netlog_observer.h" | 18 #include "content/browser/loader/netlog_observer.h" |
| 19 #include "content/browser/loader/resource_controller.h" | 19 #include "content/browser/loader/resource_controller.h" |
| 20 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 20 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 21 #include "content/browser/loader/resource_request_info_impl.h" | 21 #include "content/browser/loader/resource_request_info_impl.h" |
| 22 #include "content/browser/loader/resource_scheduler.h" | |
| 22 #include "content/common/resource_request_completion_status.h" | 23 #include "content/common/resource_request_completion_status.h" |
| 23 #include "content/public/browser/global_request_id.h" | 24 #include "content/public/browser/global_request_id.h" |
| 24 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 25 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 25 #include "content/public/common/resource_response.h" | 26 #include "content/public/common/resource_response.h" |
| 26 #include "mojo/public/c/system/data_pipe.h" | 27 #include "mojo/public/c/system/data_pipe.h" |
| 27 #include "mojo/public/cpp/bindings/message.h" | 28 #include "mojo/public/cpp/bindings/message.h" |
| 28 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
| 29 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| 30 #include "net/base/mime_sniffer.h" | 31 #include "net/base/mime_sniffer.h" |
| 32 #include "net/base/request_priority.h" | |
| 31 #include "net/url_request/redirect_info.h" | 33 #include "net/url_request/redirect_info.h" |
| 32 | 34 |
| 33 namespace content { | 35 namespace content { |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; | 38 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; |
| 37 | 39 |
| 38 // MimeTypeResourceHandler *implicitly* requires that the buffer size | 40 // MimeTypeResourceHandler *implicitly* requires that the buffer size |
| 39 // returned from OnWillRead should be larger than certain size. | 41 // returned from OnWillRead should be larger than certain size. |
| 40 // TODO(yhirano): Fix MimeTypeResourceHandler. | 42 // TODO(yhirano): Fix MimeTypeResourceHandler. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 56 did_init = true; | 58 did_init = true; |
| 57 | 59 |
| 58 GetNumericArg("resource-buffer-size", &g_allocation_size); | 60 GetNumericArg("resource-buffer-size", &g_allocation_size); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void NotReached(mojom::URLLoaderAssociatedRequest mojo_request, | 63 void NotReached(mojom::URLLoaderAssociatedRequest mojo_request, |
| 62 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 64 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 63 NOTREACHED(); | 65 NOTREACHED(); |
| 64 } | 66 } |
| 65 | 67 |
| 68 net::RequestPriority NetRequestPriorityForMojoRequestPriority( | |
| 69 mojom::RequestPriority priority) { | |
| 70 switch (priority) { | |
| 71 case mojom::RequestPriority::kThrottled: | |
| 72 return net::THROTTLED; | |
| 73 case mojom::RequestPriority::kIdle: | |
| 74 return net::IDLE; | |
| 75 case mojom::RequestPriority::kLowest: | |
| 76 return net::LOWEST; | |
| 77 case mojom::RequestPriority::kLow: | |
| 78 return net::LOW; | |
| 79 case mojom::RequestPriority::kMedium: | |
| 80 return net::MEDIUM; | |
| 81 case mojom::RequestPriority::kHighest: | |
| 82 return net::HIGHEST; | |
|
dcheng
2017/01/24 19:07:18
Can we add an EnumTraits and typemap this instead?
yhirano
2017/01/27 07:53:55
Done.
| |
| 83 } | |
| 84 | |
| 85 NOTREACHED(); | |
| 86 return static_cast<net::RequestPriority>(priority); | |
| 87 } | |
| 88 | |
| 66 } // namespace | 89 } // namespace |
| 67 | 90 |
| 68 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle | 91 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle |
| 69 // between WriterIOBuffer and MojoAsyncResourceHandler. | 92 // between WriterIOBuffer and MojoAsyncResourceHandler. |
| 70 class MojoAsyncResourceHandler::SharedWriter final | 93 class MojoAsyncResourceHandler::SharedWriter final |
| 71 : public base::RefCountedThreadSafe<SharedWriter> { | 94 : public base::RefCountedThreadSafe<SharedWriter> { |
| 72 public: | 95 public: |
| 73 explicit SharedWriter(mojo::ScopedDataPipeProducerHandle writer) | 96 explicit SharedWriter(mojo::ScopedDataPipeProducerHandle writer) |
| 74 : writer_(std::move(writer)) {} | 97 : writer_(std::move(writer)) {} |
| 75 mojo::DataPipeProducerHandle writer() { return writer_.get(); } | 98 mojo::DataPipeProducerHandle writer() { return writer_.get(); } |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 ReportBadMessage("Malformed FollowRedirect request"); | 343 ReportBadMessage("Malformed FollowRedirect request"); |
| 321 return; | 344 return; |
| 322 } | 345 } |
| 323 | 346 |
| 324 DCHECK(!did_defer_on_writing_); | 347 DCHECK(!did_defer_on_writing_); |
| 325 did_defer_on_redirect_ = false; | 348 did_defer_on_redirect_ = false; |
| 326 request()->LogUnblocked(); | 349 request()->LogUnblocked(); |
| 327 controller()->Resume(); | 350 controller()->Resume(); |
| 328 } | 351 } |
| 329 | 352 |
| 353 void MojoAsyncResourceHandler::SetPriority(mojom::RequestPriority priority, | |
| 354 int32_t intra_priority_value) { | |
| 355 ResourceDispatcherHostImpl::Get()->scheduler()->ReprioritizeRequest( | |
| 356 request(), NetRequestPriorityForMojoRequestPriority(priority), | |
| 357 intra_priority_value); | |
| 358 } | |
| 359 | |
| 330 void MojoAsyncResourceHandler::OnWritableForTesting() { | 360 void MojoAsyncResourceHandler::OnWritableForTesting() { |
| 331 OnWritable(MOJO_RESULT_OK); | 361 OnWritable(MOJO_RESULT_OK); |
| 332 } | 362 } |
| 333 | 363 |
| 334 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { | 364 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { |
| 335 g_allocation_size = size; | 365 g_allocation_size = size; |
| 336 } | 366 } |
| 337 | 367 |
| 338 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, | 368 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, |
| 339 uint32_t* available) { | 369 uint32_t* available) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 mojom::URLLoaderAssociatedRequest mojo_request, | 531 mojom::URLLoaderAssociatedRequest mojo_request, |
| 502 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 532 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 503 binding_.Unbind(); | 533 binding_.Unbind(); |
| 504 binding_.Bind(std::move(mojo_request)); | 534 binding_.Bind(std::move(mojo_request)); |
| 505 binding_.set_connection_error_handler( | 535 binding_.set_connection_error_handler( |
| 506 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 536 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 507 url_loader_client_ = std::move(url_loader_client); | 537 url_loader_client_ = std::move(url_loader_client); |
| 508 } | 538 } |
| 509 | 539 |
| 510 } // namespace content | 540 } // namespace content |
| OLD | NEW |