| 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/common/resource_dispatcher.h" | 7 #include "content/common/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/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/shared_memory.h" | 16 #include "base/shared_memory.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "content/common/inter_process_time_ticks_converter.h" | 18 #include "content/common/inter_process_time_ticks_converter.h" |
| 19 #include "content/common/request_extra_data.h" | 19 #include "content/common/request_extra_data.h" |
| 20 #include "content/common/resource_messages.h" | 20 #include "content/common/resource_messages.h" |
| 21 #include "content/public/common/resource_dispatcher_delegate.h" | 21 #include "content/public/common/resource_dispatcher_delegate.h" |
| 22 #include "content/public/common/resource_response.h" | 22 #include "content/public/common/resource_response.h" |
| 23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "net/base/request_priority.h" |
| 25 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 26 #include "webkit/glue/resource_request_body.h" | 27 #include "webkit/glue/resource_request_body.h" |
| 27 #include "webkit/glue/resource_type.h" | 28 #include "webkit/glue/resource_type.h" |
| 28 | 29 |
| 29 using webkit_glue::ResourceLoaderBridge; | 30 using webkit_glue::ResourceLoaderBridge; |
| 30 using webkit_glue::ResourceRequestBody; | 31 using webkit_glue::ResourceRequestBody; |
| 31 using webkit_glue::ResourceResponseInfo; | 32 using webkit_glue::ResourceResponseInfo; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 55 public: | 56 public: |
| 56 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | 57 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, |
| 57 const ResourceLoaderBridge::RequestInfo& request_info); | 58 const ResourceLoaderBridge::RequestInfo& request_info); |
| 58 virtual ~IPCResourceLoaderBridge(); | 59 virtual ~IPCResourceLoaderBridge(); |
| 59 | 60 |
| 60 // ResourceLoaderBridge | 61 // ResourceLoaderBridge |
| 61 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; | 62 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; |
| 62 virtual bool Start(Peer* peer) OVERRIDE; | 63 virtual bool Start(Peer* peer) OVERRIDE; |
| 63 virtual void Cancel() OVERRIDE; | 64 virtual void Cancel() OVERRIDE; |
| 64 virtual void SetDefersLoading(bool value) OVERRIDE; | 65 virtual void SetDefersLoading(bool value) OVERRIDE; |
| 66 virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE; |
| 65 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; | 67 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; |
| 66 | 68 |
| 67 private: | 69 private: |
| 68 ResourceLoaderBridge::Peer* peer_; | 70 ResourceLoaderBridge::Peer* peer_; |
| 69 | 71 |
| 70 // The resource dispatcher for this loader. The bridge doesn't own it, but | 72 // The resource dispatcher for this loader. The bridge doesn't own it, but |
| 71 // it's guaranteed to outlive the bridge. | 73 // it's guaranteed to outlive the bridge. |
| 72 ResourceDispatcher* dispatcher_; | 74 ResourceDispatcher* dispatcher_; |
| 73 | 75 |
| 74 // The request to send, created on initialization for modification and | 76 // The request to send, created on initialization for modification and |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 188 |
| 187 void IPCResourceLoaderBridge::SetDefersLoading(bool value) { | 189 void IPCResourceLoaderBridge::SetDefersLoading(bool value) { |
| 188 if (request_id_ < 0) { | 190 if (request_id_ < 0) { |
| 189 NOTREACHED() << "Trying to (un)defer an unstarted request"; | 191 NOTREACHED() << "Trying to (un)defer an unstarted request"; |
| 190 return; | 192 return; |
| 191 } | 193 } |
| 192 | 194 |
| 193 dispatcher_->SetDefersLoading(request_id_, value); | 195 dispatcher_->SetDefersLoading(request_id_, value); |
| 194 } | 196 } |
| 195 | 197 |
| 198 void IPCResourceLoaderBridge::DidChangePriority( |
| 199 net::RequestPriority new_priority) { |
| 200 if (request_id_ < 0) { |
| 201 NOTREACHED() << "Trying to change priority of an unstarted request"; |
| 202 return; |
| 203 } |
| 204 |
| 205 dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority); |
| 206 } |
| 207 |
| 196 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { | 208 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { |
| 197 if (request_id_ != -1) { | 209 if (request_id_ != -1) { |
| 198 NOTREACHED() << "Starting a request twice"; | 210 NOTREACHED() << "Starting a request twice"; |
| 199 response->error_code = net::ERR_FAILED; | 211 response->error_code = net::ERR_FAILED; |
| 200 return; | 212 return; |
| 201 } | 213 } |
| 202 | 214 |
| 203 request_id_ = MakeRequestID(); | 215 request_id_ = MakeRequestID(); |
| 204 is_synchronous_request_ = true; | 216 is_synchronous_request_ = true; |
| 205 | 217 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 request_info.is_deferred = false; | 554 request_info.is_deferred = false; |
| 543 | 555 |
| 544 FollowPendingRedirect(request_id, request_info); | 556 FollowPendingRedirect(request_id, request_info); |
| 545 | 557 |
| 546 MessageLoop::current()->PostTask(FROM_HERE, | 558 MessageLoop::current()->PostTask(FROM_HERE, |
| 547 base::Bind(&ResourceDispatcher::FlushDeferredMessages, | 559 base::Bind(&ResourceDispatcher::FlushDeferredMessages, |
| 548 weak_factory_.GetWeakPtr(), request_id)); | 560 weak_factory_.GetWeakPtr(), request_id)); |
| 549 } | 561 } |
| 550 } | 562 } |
| 551 | 563 |
| 564 void ResourceDispatcher::DidChangePriority( |
| 565 int routing_id, int request_id, net::RequestPriority new_priority) { |
| 566 DCHECK(ContainsKey(pending_requests_, request_id)); |
| 567 message_sender()->Send(new ResourceHostMsg_DidChangePriority( |
| 568 routing_id, request_id, new_priority)); |
| 569 } |
| 570 |
| 552 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() | 571 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() |
| 553 : peer(NULL), | 572 : peer(NULL), |
| 554 resource_type(ResourceType::SUB_RESOURCE), | 573 resource_type(ResourceType::SUB_RESOURCE), |
| 555 is_deferred(false), | 574 is_deferred(false), |
| 556 buffer_size(0) { | 575 buffer_size(0) { |
| 557 } | 576 } |
| 558 | 577 |
| 559 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( | 578 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( |
| 560 webkit_glue::ResourceLoaderBridge::Peer* peer, | 579 webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 561 ResourceType::Type resource_type, | 580 ResourceType::Type resource_type, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 745 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
| 727 while (!queue->empty()) { | 746 while (!queue->empty()) { |
| 728 IPC::Message* message = queue->front(); | 747 IPC::Message* message = queue->front(); |
| 729 ReleaseResourcesInDataMessage(*message); | 748 ReleaseResourcesInDataMessage(*message); |
| 730 queue->pop_front(); | 749 queue->pop_front(); |
| 731 delete message; | 750 delete message; |
| 732 } | 751 } |
| 733 } | 752 } |
| 734 | 753 |
| 735 } // namespace content | 754 } // namespace content |
| OLD | NEW |