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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.cc

Issue 2646343007: [Mojo-Loading] Implement URLLoader::SetPriority (Closed)
Patch Set: rebase Created 3 years, 11 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 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "content/browser/loader/downloaded_temp_file_impl.h" 19 #include "content/browser/loader/downloaded_temp_file_impl.h"
20 #include "content/browser/loader/netlog_observer.h" 20 #include "content/browser/loader/netlog_observer.h"
21 #include "content/browser/loader/resource_controller.h" 21 #include "content/browser/loader/resource_controller.h"
22 #include "content/browser/loader/resource_dispatcher_host_impl.h" 22 #include "content/browser/loader/resource_dispatcher_host_impl.h"
23 #include "content/browser/loader/resource_request_info_impl.h" 23 #include "content/browser/loader/resource_request_info_impl.h"
24 #include "content/browser/loader/resource_scheduler.h"
24 #include "content/browser/loader/upload_progress_tracker.h" 25 #include "content/browser/loader/upload_progress_tracker.h"
25 #include "content/common/resource_request_completion_status.h" 26 #include "content/common/resource_request_completion_status.h"
26 #include "content/public/browser/global_request_id.h" 27 #include "content/public/browser/global_request_id.h"
27 #include "content/public/browser/resource_dispatcher_host_delegate.h" 28 #include "content/public/browser/resource_dispatcher_host_delegate.h"
28 #include "content/public/common/resource_response.h" 29 #include "content/public/common/resource_response.h"
29 #include "mojo/public/c/system/data_pipe.h" 30 #include "mojo/public/c/system/data_pipe.h"
30 #include "mojo/public/cpp/bindings/message.h" 31 #include "mojo/public/cpp/bindings/message.h"
31 #include "net/base/io_buffer.h" 32 #include "net/base/io_buffer.h"
32 #include "net/base/mime_sniffer.h" 33 #include "net/base/mime_sniffer.h"
34 #include "net/base/request_priority.h"
33 #include "net/url_request/redirect_info.h" 35 #include "net/url_request/redirect_info.h"
34 36
35 namespace content { 37 namespace content {
36 namespace { 38 namespace {
37 39
38 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; 40 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize;
39 41
40 // MimeTypeResourceHandler *implicitly* requires that the buffer size 42 // MimeTypeResourceHandler *implicitly* requires that the buffer size
41 // returned from OnWillRead should be larger than certain size. 43 // returned from OnWillRead should be larger than certain size.
42 // TODO(yhirano): Fix MimeTypeResourceHandler. 44 // TODO(yhirano): Fix MimeTypeResourceHandler.
(...skipping 15 matching lines...) Expand all
58 did_init = true; 60 did_init = true;
59 61
60 GetNumericArg("resource-buffer-size", &g_allocation_size); 62 GetNumericArg("resource-buffer-size", &g_allocation_size);
61 } 63 }
62 64
63 void NotReached(mojom::URLLoaderAssociatedRequest mojo_request, 65 void NotReached(mojom::URLLoaderAssociatedRequest mojo_request,
64 mojom::URLLoaderClientAssociatedPtr url_loader_client) { 66 mojom::URLLoaderClientAssociatedPtr url_loader_client) {
65 NOTREACHED(); 67 NOTREACHED();
66 } 68 }
67 69
70 net::RequestPriority NetRequestPriorityForMojoRequestPriority(
71 mojom::RequestPriority priority) {
72 switch (priority) {
73 case mojom::RequestPriority::kThrottled:
74 return net::THROTTLED;
75 case mojom::RequestPriority::kIdle:
76 return net::IDLE;
77 case mojom::RequestPriority::kLowest:
78 return net::LOWEST;
79 case mojom::RequestPriority::kLow:
80 return net::LOW;
81 case mojom::RequestPriority::kMedium:
82 return net::MEDIUM;
83 case mojom::RequestPriority::kHighest:
84 return net::HIGHEST;
85 }
86
87 NOTREACHED();
88 return static_cast<net::RequestPriority>(priority);
89 }
90
68 } // namespace 91 } // namespace
69 92
70 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle 93 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle
71 // between WriterIOBuffer and MojoAsyncResourceHandler. 94 // between WriterIOBuffer and MojoAsyncResourceHandler.
72 class MojoAsyncResourceHandler::SharedWriter final 95 class MojoAsyncResourceHandler::SharedWriter final
73 : public base::RefCountedThreadSafe<SharedWriter> { 96 : public base::RefCountedThreadSafe<SharedWriter> {
74 public: 97 public:
75 explicit SharedWriter(mojo::ScopedDataPipeProducerHandle writer) 98 explicit SharedWriter(mojo::ScopedDataPipeProducerHandle writer)
76 : writer_(std::move(writer)) {} 99 : writer_(std::move(writer)) {}
77 mojo::DataPipeProducerHandle writer() { return writer_.get(); } 100 mojo::DataPipeProducerHandle writer() { return writer_.get(); }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 ReportBadMessage("Malformed FollowRedirect request"); 357 ReportBadMessage("Malformed FollowRedirect request");
335 return; 358 return;
336 } 359 }
337 360
338 DCHECK(!did_defer_on_writing_); 361 DCHECK(!did_defer_on_writing_);
339 did_defer_on_redirect_ = false; 362 did_defer_on_redirect_ = false;
340 request()->LogUnblocked(); 363 request()->LogUnblocked();
341 controller()->Resume(); 364 controller()->Resume();
342 } 365 }
343 366
367 void MojoAsyncResourceHandler::SetPriority(mojom::RequestPriority priority,
368 int32_t intra_priority_value) {
369 ResourceDispatcherHostImpl::Get()->scheduler()->ReprioritizeRequest(
370 request(), NetRequestPriorityForMojoRequestPriority(priority),
371 intra_priority_value);
372 }
373
344 void MojoAsyncResourceHandler::OnWritableForTesting() { 374 void MojoAsyncResourceHandler::OnWritableForTesting() {
345 OnWritable(MOJO_RESULT_OK); 375 OnWritable(MOJO_RESULT_OK);
346 } 376 }
347 377
348 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { 378 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) {
349 g_allocation_size = size; 379 g_allocation_size = size;
350 } 380 }
351 381
352 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, 382 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data,
353 uint32_t* available) { 383 uint32_t* available) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, 574 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK,
545 weak_factory_.GetWeakPtr())); 575 weak_factory_.GetWeakPtr()));
546 } 576 }
547 577
548 void MojoAsyncResourceHandler::OnUploadProgressACK() { 578 void MojoAsyncResourceHandler::OnUploadProgressACK() {
549 if (upload_progress_tracker_) 579 if (upload_progress_tracker_)
550 upload_progress_tracker_->OnAckReceived(); 580 upload_progress_tracker_->OnAckReceived();
551 } 581 }
552 582
553 } // namespace content 583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698