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

Side by Side Diff: content/child/resource_dispatcher.cc

Issue 2804843005: Implement the infrastructure of creating WorkerFetchContext in worker global scope. (Closed)
Patch Set: s/WebScheduler.h/web_scheduler.h/ Created 3 years, 8 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
« no previous file with comments | « content/child/resource_dispatcher.h ('k') | content/child/runtime_features.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/child/resource_dispatcher.h" 7 #include "content/child/resource_dispatcher.h"
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/atomic_sequence_num.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/debug/alias.h" 14 #include "base/debug/alias.h"
14 #include "base/debug/dump_without_crashing.h" 15 #include "base/debug/dump_without_crashing.h"
15 #include "base/debug/stack_trace.h" 16 #include "base/debug/stack_trace.h"
16 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/memory/shared_memory.h" 19 #include "base/memory/shared_memory.h"
19 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
20 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::debug::Alias(&last_err); 61 base::debug::Alias(&last_err);
61 #endif 62 #endif
62 CHECK(false); 63 CHECK(false);
63 } 64 }
64 65
65 // Each resource request is assigned an ID scoped to this process. 66 // Each resource request is assigned an ID scoped to this process.
66 int MakeRequestID() { 67 int MakeRequestID() {
67 // NOTE: The resource_dispatcher_host also needs probably unique 68 // NOTE: The resource_dispatcher_host also needs probably unique
68 // request_ids, so they count down from -2 (-1 is a special we're 69 // request_ids, so they count down from -2 (-1 is a special we're
69 // screwed value), while the renderer process counts up. 70 // screwed value), while the renderer process counts up.
70 static int next_request_id = 0; 71 static base::StaticAtomicSequenceNumber sequence;
71 return next_request_id++; 72 return sequence.GetNext(); // We start at zero.
72 } 73 }
73 74
74 void CheckSchemeForReferrerPolicy(const ResourceRequest& request) { 75 void CheckSchemeForReferrerPolicy(const ResourceRequest& request) {
75 if ((request.referrer_policy == blink::kWebReferrerPolicyDefault || 76 if ((request.referrer_policy == blink::kWebReferrerPolicyDefault ||
76 request.referrer_policy == 77 request.referrer_policy ==
77 blink::kWebReferrerPolicyNoReferrerWhenDowngrade) && 78 blink::kWebReferrerPolicyNoReferrerWhenDowngrade) &&
78 request.referrer.SchemeIsCryptographic() && 79 request.referrer.SchemeIsCryptographic() &&
79 !request.url.SchemeIsCryptographic()) { 80 !request.url.SchemeIsCryptographic()) {
80 LOG(FATAL) << "Trying to send secure referrer for insecure request " 81 LOG(FATAL) << "Trying to send secure referrer for insecure request "
81 << "without an appropriate referrer policy.\n" 82 << "without an appropriate referrer policy.\n"
82 << "URL = " << request.url << "\n" 83 << "URL = " << request.url << "\n"
83 << "Referrer = " << request.referrer; 84 << "Referrer = " << request.referrer;
84 } 85 }
85 } 86 }
86 87
87 } // namespace 88 } // namespace
88 89
89 ResourceDispatcher::ResourceDispatcher( 90 ResourceDispatcher::ResourceDispatcher(
90 IPC::Sender* sender, 91 IPC::Sender* sender,
91 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) 92 scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner)
92 : message_sender_(sender), 93 : message_sender_(sender),
93 delegate_(NULL), 94 delegate_(NULL),
94 io_timestamp_(base::TimeTicks()), 95 io_timestamp_(base::TimeTicks()),
95 main_thread_task_runner_(main_thread_task_runner), 96 thread_task_runner_(thread_task_runner),
96 weak_factory_(this) { 97 weak_factory_(this) {}
97 }
98 98
99 ResourceDispatcher::~ResourceDispatcher() { 99 ResourceDispatcher::~ResourceDispatcher() {
100 } 100 }
101 101
102 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { 102 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) {
103 if (!IsResourceDispatcherMessage(message)) { 103 if (!IsResourceDispatcherMessage(message)) {
104 return false; 104 return false;
105 } 105 }
106 106
107 int request_id; 107 int request_id;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 // Cancel loading. 395 // Cancel loading.
396 it->second->url_loader = nullptr; 396 it->second->url_loader = nullptr;
397 // Clear URLLoaderClient to stop receiving further Mojo IPC from the browser 397 // Clear URLLoaderClient to stop receiving further Mojo IPC from the browser
398 // process. 398 // process.
399 it->second->url_loader_client = nullptr; 399 it->second->url_loader_client = nullptr;
400 400
401 // Always delete the pending_request asyncly so that cancelling the request 401 // Always delete the pending_request asyncly so that cancelling the request
402 // doesn't delete the request context info while its response is still being 402 // doesn't delete the request context info while its response is still being
403 // handled. 403 // handled.
404 main_thread_task_runner_->DeleteSoon(FROM_HERE, it->second.release()); 404 thread_task_runner_->DeleteSoon(FROM_HERE, it->second.release());
405 pending_requests_.erase(it); 405 pending_requests_.erase(it);
406 406
407 if (release_downloaded_file) { 407 if (release_downloaded_file) {
408 message_sender_->Send( 408 message_sender_->Send(
409 new ResourceHostMsg_ReleaseDownloadedFile(request_id)); 409 new ResourceHostMsg_ReleaseDownloadedFile(request_id));
410 } 410 }
411 411
412 if (resource_scheduling_filter_.get()) 412 if (resource_scheduling_filter_.get())
413 resource_scheduling_filter_->ClearRequestIdTaskRunner(request_id); 413 resource_scheduling_filter_->ClearRequestIdTaskRunner(request_id);
414 414
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (request_info->url_loader_client) 463 if (request_info->url_loader_client)
464 request_info->url_loader_client->SetDefersLoading(); 464 request_info->url_loader_client->SetDefersLoading();
465 } else if (request_info->is_deferred) { 465 } else if (request_info->is_deferred) {
466 request_info->is_deferred = false; 466 request_info->is_deferred = false;
467 467
468 if (request_info->url_loader_client) 468 if (request_info->url_loader_client)
469 request_info->url_loader_client->UnsetDefersLoading(); 469 request_info->url_loader_client->UnsetDefersLoading();
470 470
471 FollowPendingRedirect(request_id, request_info); 471 FollowPendingRedirect(request_id, request_info);
472 472
473 main_thread_task_runner_->PostTask( 473 thread_task_runner_->PostTask(
474 FROM_HERE, base::Bind(&ResourceDispatcher::FlushDeferredMessages, 474 FROM_HERE, base::Bind(&ResourceDispatcher::FlushDeferredMessages,
475 weak_factory_.GetWeakPtr(), request_id)); 475 weak_factory_.GetWeakPtr(), request_id));
476 } 476 }
477 } 477 }
478 478
479 void ResourceDispatcher::DidChangePriority(int request_id, 479 void ResourceDispatcher::DidChangePriority(int request_id,
480 net::RequestPriority new_priority, 480 net::RequestPriority new_priority,
481 int intra_priority_value) { 481 int intra_priority_value) {
482 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 482 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
483 DCHECK(request_info); 483 DCHECK(request_info);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 pending_requests_[request_id] = base::MakeUnique<PendingRequestInfo>( 632 pending_requests_[request_id] = base::MakeUnique<PendingRequestInfo>(
633 std::move(peer), request->resource_type, request->origin_pid, 633 std::move(peer), request->resource_type, request->origin_pid,
634 frame_origin, request->url, request->download_to_file); 634 frame_origin, request->url, request->download_to_file);
635 635
636 if (resource_scheduling_filter_.get() && loading_task_runner) { 636 if (resource_scheduling_filter_.get() && loading_task_runner) {
637 resource_scheduling_filter_->SetRequestIdTaskRunner(request_id, 637 resource_scheduling_filter_->SetRequestIdTaskRunner(request_id,
638 loading_task_runner); 638 loading_task_runner);
639 } 639 }
640 640
641 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 641 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
642 loading_task_runner ? loading_task_runner : main_thread_task_runner_; 642 loading_task_runner ? loading_task_runner : thread_task_runner_;
643 643
644 if (consumer_handle.is_valid()) { 644 if (consumer_handle.is_valid()) {
645 pending_requests_[request_id]->url_loader_client = 645 pending_requests_[request_id]->url_loader_client =
646 base::MakeUnique<URLLoaderClientImpl>(request_id, this, task_runner); 646 base::MakeUnique<URLLoaderClientImpl>(request_id, this, task_runner);
647 647
648 task_runner->PostTask(FROM_HERE, 648 task_runner->PostTask(FROM_HERE,
649 base::Bind(&ResourceDispatcher::ContinueForNavigation, 649 base::Bind(&ResourceDispatcher::ContinueForNavigation,
650 weak_factory_.GetWeakPtr(), request_id, 650 weak_factory_.GetWeakPtr(), request_id,
651 base::Passed(std::move(consumer_handle)))); 651 base::Passed(std::move(consumer_handle))));
652 652
653 return request_id; 653 return request_id;
654 } 654 }
655 655
656 if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) { 656 if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) {
657 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 657 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
658 loading_task_runner ? loading_task_runner : main_thread_task_runner_; 658 loading_task_runner ? loading_task_runner : thread_task_runner_;
659 std::unique_ptr<URLLoaderClientImpl> client( 659 std::unique_ptr<URLLoaderClientImpl> client(
660 new URLLoaderClientImpl(request_id, this, std::move(task_runner))); 660 new URLLoaderClientImpl(request_id, this, std::move(task_runner)));
661 mojom::URLLoaderAssociatedPtr url_loader; 661 mojom::URLLoaderAssociatedPtr url_loader;
662 mojom::URLLoaderClientPtr client_ptr; 662 mojom::URLLoaderClientPtr client_ptr;
663 client->Bind(&client_ptr); 663 client->Bind(&client_ptr);
664 url_loader_factory->CreateLoaderAndStart( 664 url_loader_factory->CreateLoaderAndStart(
665 MakeRequest(&url_loader), routing_id, request_id, 665 MakeRequest(&url_loader), routing_id, request_id,
666 mojom::kURLLoadOptionNone, *request, std::move(client_ptr)); 666 mojom::kURLLoadOptionNone, *request, std::move(client_ptr));
667 pending_requests_[request_id]->url_loader = std::move(url_loader); 667 pending_requests_[request_id]->url_loader = std::move(url_loader);
668 pending_requests_[request_id]->url_loader_client = std::move(client); 668 pending_requests_[request_id]->url_loader_client = std::move(client);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 delete message; 837 delete message;
838 } 838 }
839 } 839 }
840 840
841 void ResourceDispatcher::SetResourceSchedulingFilter( 841 void ResourceDispatcher::SetResourceSchedulingFilter(
842 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { 842 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) {
843 resource_scheduling_filter_ = resource_scheduling_filter; 843 resource_scheduling_filter_ = resource_scheduling_filter;
844 } 844 }
845 845
846 } // namespace content 846 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.h ('k') | content/child/runtime_features.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698