| OLD | NEW |
| 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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "content/child/high_priority_resource_filter.h" |
| 18 #include "content/child/request_extra_data.h" | 19 #include "content/child/request_extra_data.h" |
| 19 #include "content/child/request_info.h" | 20 #include "content/child/request_info.h" |
| 20 #include "content/child/site_isolation_policy.h" | 21 #include "content/child/site_isolation_policy.h" |
| 21 #include "content/child/sync_load_response.h" | 22 #include "content/child/sync_load_response.h" |
| 22 #include "content/common/inter_process_time_ticks_converter.h" | 23 #include "content/common/inter_process_time_ticks_converter.h" |
| 23 #include "content/common/resource_messages.h" | 24 #include "content/common/resource_messages.h" |
| 24 #include "content/public/child/request_peer.h" | 25 #include "content/public/child/request_peer.h" |
| 25 #include "content/public/child/resource_dispatcher_delegate.h" | 26 #include "content/public/child/resource_dispatcher_delegate.h" |
| 26 #include "content/public/common/resource_response.h" | 27 #include "content/public/common/resource_response.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 response->data.swap(result.data); | 259 response->data.swap(result.data); |
| 259 response->download_file_path = result.download_file_path; | 260 response->download_file_path = result.download_file_path; |
| 260 } | 261 } |
| 261 | 262 |
| 262 // ResourceDispatcher --------------------------------------------------------- | 263 // ResourceDispatcher --------------------------------------------------------- |
| 263 | 264 |
| 264 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) | 265 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) |
| 265 : message_sender_(sender), | 266 : message_sender_(sender), |
| 266 weak_factory_(this), | 267 weak_factory_(this), |
| 267 delegate_(NULL), | 268 delegate_(NULL), |
| 269 high_priority_resource_filter_(NULL), |
| 268 io_timestamp_(base::TimeTicks()) { | 270 io_timestamp_(base::TimeTicks()) { |
| 269 } | 271 } |
| 270 | 272 |
| 271 ResourceDispatcher::~ResourceDispatcher() { | 273 ResourceDispatcher::~ResourceDispatcher() { |
| 272 } | 274 } |
| 273 | 275 |
| 274 // ResourceDispatcher implementation ------------------------------------------ | 276 // ResourceDispatcher implementation ------------------------------------------ |
| 275 | 277 |
| 276 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { | 278 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { |
| 277 if (!IsResourceDispatcherMessage(message)) { | 279 if (!IsResourceDispatcherMessage(message)) { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 const GURL& request_url, | 574 const GURL& request_url, |
| 573 bool download_to_file) { | 575 bool download_to_file) { |
| 574 // Compute a unique request_id for this renderer process. | 576 // Compute a unique request_id for this renderer process. |
| 575 int id = MakeRequestID(); | 577 int id = MakeRequestID(); |
| 576 pending_requests_[id] = PendingRequestInfo(callback, | 578 pending_requests_[id] = PendingRequestInfo(callback, |
| 577 resource_type, | 579 resource_type, |
| 578 origin_pid, | 580 origin_pid, |
| 579 frame_origin, | 581 frame_origin, |
| 580 request_url, | 582 request_url, |
| 581 download_to_file); | 583 download_to_file); |
| 584 if (high_priority_resource_filter_) |
| 585 high_priority_resource_filter_->AddPendingRequest(id, resource_type); |
| 582 return id; | 586 return id; |
| 583 } | 587 } |
| 584 | 588 |
| 585 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 589 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
| 586 PendingRequestList::iterator it = pending_requests_.find(request_id); | 590 PendingRequestList::iterator it = pending_requests_.find(request_id); |
| 587 if (it == pending_requests_.end()) | 591 if (it == pending_requests_.end()) |
| 588 return false; | 592 return false; |
| 589 | 593 |
| 590 PendingRequestInfo& request_info = it->second; | 594 PendingRequestInfo& request_info = it->second; |
| 591 | 595 |
| 596 if (high_priority_resource_filter_) |
| 597 high_priority_resource_filter_->RemovePendingRequest(request_id); |
| 598 |
| 592 bool release_downloaded_file = request_info.download_to_file; | 599 bool release_downloaded_file = request_info.download_to_file; |
| 593 | 600 |
| 594 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); | 601 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); |
| 595 pending_requests_.erase(it); | 602 pending_requests_.erase(it); |
| 596 | 603 |
| 597 if (release_downloaded_file) { | 604 if (release_downloaded_file) { |
| 598 message_sender_->Send( | 605 message_sender_->Send( |
| 599 new ResourceHostMsg_ReleaseDownloadedFile(request_id)); | 606 new ResourceHostMsg_ReleaseDownloadedFile(request_id)); |
| 600 } | 607 } |
| 601 | 608 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 878 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
| 872 while (!queue->empty()) { | 879 while (!queue->empty()) { |
| 873 IPC::Message* message = queue->front(); | 880 IPC::Message* message = queue->front(); |
| 874 ReleaseResourcesInDataMessage(*message); | 881 ReleaseResourcesInDataMessage(*message); |
| 875 queue->pop_front(); | 882 queue->pop_front(); |
| 876 delete message; | 883 delete message; |
| 877 } | 884 } |
| 878 } | 885 } |
| 879 | 886 |
| 880 } // namespace content | 887 } // namespace content |
| OLD | NEW |