Chromium Code Reviews| 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/request_extra_data.h" | 18 #include "content/child/request_extra_data.h" |
| 19 #include "content/child/site_isolation_policy.h" | 19 #include "content/child/site_isolation_policy.h" |
| 20 #include "content/child/webparserresourcebridge_impl.h" | |
| 20 #include "content/common/inter_process_time_ticks_converter.h" | 21 #include "content/common/inter_process_time_ticks_converter.h" |
| 21 #include "content/common/resource_messages.h" | 22 #include "content/common/resource_messages.h" |
| 22 #include "content/public/child/resource_dispatcher_delegate.h" | 23 #include "content/public/child/resource_dispatcher_delegate.h" |
| 23 #include "content/public/common/resource_response.h" | 24 #include "content/public/common/resource_response.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 #include "net/base/request_priority.h" | 27 #include "net/base/request_priority.h" |
| 27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 28 #include "webkit/common/resource_type.h" | 29 #include "webkit/common/resource_type.h" |
| 29 | 30 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | 72 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, |
| 72 const ResourceLoaderBridge::RequestInfo& request_info); | 73 const ResourceLoaderBridge::RequestInfo& request_info); |
| 73 virtual ~IPCResourceLoaderBridge(); | 74 virtual ~IPCResourceLoaderBridge(); |
| 74 | 75 |
| 75 // ResourceLoaderBridge | 76 // ResourceLoaderBridge |
| 76 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; | 77 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; |
| 77 virtual bool Start(Peer* peer) OVERRIDE; | 78 virtual bool Start(Peer* peer) OVERRIDE; |
| 78 virtual void Cancel() OVERRIDE; | 79 virtual void Cancel() OVERRIDE; |
| 79 virtual void SetDefersLoading(bool value) OVERRIDE; | 80 virtual void SetDefersLoading(bool value) OVERRIDE; |
| 80 virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE; | 81 virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE; |
| 82 virtual blink::WebParserResourceBridge* | |
| 83 ConstructParserResourceBridge() OVERRIDE; | |
| 81 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; | 84 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; |
| 82 | 85 |
| 83 private: | 86 private: |
| 84 ResourceLoaderBridge::Peer* peer_; | 87 ResourceLoaderBridge::Peer* peer_; |
| 85 | 88 |
| 86 // The resource dispatcher for this loader. The bridge doesn't own it, but | 89 // The resource dispatcher for this loader. The bridge doesn't own it, but |
| 87 // it's guaranteed to outlive the bridge. | 90 // it's guaranteed to outlive the bridge. |
| 88 ResourceDispatcher* dispatcher_; | 91 ResourceDispatcher* dispatcher_; |
| 89 | 92 |
| 90 // The request to send, created on initialization for modification and | 93 // The request to send, created on initialization for modification and |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 void IPCResourceLoaderBridge::DidChangePriority( | 227 void IPCResourceLoaderBridge::DidChangePriority( |
| 225 net::RequestPriority new_priority) { | 228 net::RequestPriority new_priority) { |
| 226 if (request_id_ < 0) { | 229 if (request_id_ < 0) { |
| 227 NOTREACHED() << "Trying to change priority of an unstarted request"; | 230 NOTREACHED() << "Trying to change priority of an unstarted request"; |
| 228 return; | 231 return; |
| 229 } | 232 } |
| 230 | 233 |
| 231 dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority); | 234 dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority); |
| 232 } | 235 } |
| 233 | 236 |
| 237 blink::WebParserResourceBridge* | |
| 238 IPCResourceLoaderBridge::ConstructParserResourceBridge() { | |
| 239 if (request_id_ < 0) { | |
| 240 NOTREACHED() << "Trying to set parser-resource bridge on unstarted request"; | |
| 241 return NULL; | |
| 242 } | |
| 243 | |
| 244 return dispatcher_->ConstructParserResourceBridge(request_id_); | |
| 245 } | |
| 246 | |
| 234 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { | 247 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { |
| 235 if (request_id_ != -1) { | 248 if (request_id_ != -1) { |
| 236 NOTREACHED() << "Starting a request twice"; | 249 NOTREACHED() << "Starting a request twice"; |
| 237 response->error_code = net::ERR_FAILED; | 250 response->error_code = net::ERR_FAILED; |
| 238 return; | 251 return; |
| 239 } | 252 } |
| 240 | 253 |
| 241 request_id_ = MakeRequestID(); | 254 request_id_ = MakeRequestID(); |
| 242 is_synchronous_request_ = true; | 255 is_synchronous_request_ = true; |
| 243 | 256 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 } | 628 } |
| 616 } | 629 } |
| 617 | 630 |
| 618 void ResourceDispatcher::DidChangePriority( | 631 void ResourceDispatcher::DidChangePriority( |
| 619 int routing_id, int request_id, net::RequestPriority new_priority) { | 632 int routing_id, int request_id, net::RequestPriority new_priority) { |
| 620 DCHECK(ContainsKey(pending_requests_, request_id)); | 633 DCHECK(ContainsKey(pending_requests_, request_id)); |
| 621 message_sender()->Send(new ResourceHostMsg_DidChangePriority( | 634 message_sender()->Send(new ResourceHostMsg_DidChangePriority( |
| 622 request_id, new_priority)); | 635 request_id, new_priority)); |
| 623 } | 636 } |
| 624 | 637 |
| 638 blink::WebParserResourceBridge* | |
| 639 ResourceDispatcher::ConstructParserResourceBridge(int request_id) { | |
| 640 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | |
| 641 DCHECK(request_info != NULL); | |
|
jam
2013/12/17 00:44:40
nit: this dcheck isn't necessary. in release build
oystein (OOO til 10th of July)
2013/12/17 01:07:27
Done.
| |
| 642 | |
| 643 base::SharedMemoryHandle shm_handle; | |
| 644 if (request_info->buffer != NULL) { | |
|
jam
2013/12/17 00:44:40
nit: "!= NULL" is redundant, convention is to skip
oystein (OOO til 10th of July)
2013/12/17 01:07:27
I fixed the possible ones, but for the request_inf
| |
| 645 bool handle_ok = request_info->buffer->ShareToProcess( | |
| 646 base::GetCurrentProcessHandle(), &shm_handle); | |
| 647 DCHECK(handle_ok); | |
| 648 } | |
| 649 | |
| 650 return new WebParserResourceBridgeImpl(request_id, weak_factory_.GetWeakPtr(), | |
| 651 shm_handle, request_info->buffer_size); | |
| 652 } | |
| 653 | |
| 654 void ResourceDispatcher::OnParserResourceMessageFilterAdded(int request_id) { | |
| 655 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | |
| 656 if (request_info == NULL) | |
| 657 return; // We can safely ignore completed requests here. | |
| 658 | |
| 659 request_info->peer->OnParserResourceMessageFilterAdded(); | |
| 660 } | |
| 661 | |
| 625 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() | 662 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() |
| 626 : peer(NULL), | 663 : peer(NULL), |
| 627 resource_type(ResourceType::SUB_RESOURCE), | 664 resource_type(ResourceType::SUB_RESOURCE), |
| 628 is_deferred(false), | 665 is_deferred(false), |
| 629 buffer_size(0) { | 666 buffer_size(0) { |
| 630 } | 667 } |
| 631 | 668 |
| 632 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( | 669 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( |
| 633 webkit_glue::ResourceLoaderBridge::Peer* peer, | 670 webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 634 ResourceType::Type resource_type, | 671 ResourceType::Type resource_type, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 840 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
| 804 while (!queue->empty()) { | 841 while (!queue->empty()) { |
| 805 IPC::Message* message = queue->front(); | 842 IPC::Message* message = queue->front(); |
| 806 ReleaseResourcesInDataMessage(*message); | 843 ReleaseResourcesInDataMessage(*message); |
| 807 queue->pop_front(); | 844 queue->pop_front(); |
| 808 delete message; | 845 delete message; |
| 809 } | 846 } |
| 810 } | 847 } |
| 811 | 848 |
| 812 } // namespace content | 849 } // namespace content |
| OLD | NEW |