| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This is the browser side of the resource dispatcher, it receives requests | 5 // This is the browser side of the resource dispatcher, it receives requests |
| 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and | 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and |
| 7 // dispatches them to URLRequests. It then fowards the messages from the | 7 // dispatches them to URLRequests. It then fowards the messages from the |
| 8 // URLRequests back to the correct process for handling. | 8 // URLRequests back to the correct process for handling. |
| 9 // | 9 // |
| 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 11 | 11 |
| 12 #ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 12 #ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| 13 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 13 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| 14 | 14 |
| 15 #include <map> | 15 #include <map> |
| 16 #include <string> |
| 17 #include <vector> |
| 16 | 18 |
| 19 #include "base/basictypes.h" |
| 20 #include "base/logging.h" |
| 17 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 18 #include "base/process.h" | 22 #include "base/process.h" |
| 19 #include "base/timer.h" | 23 #include "base/timer.h" |
| 20 #include "chrome/browser/renderer_host/resource_handler.h" | 24 #include "chrome/browser/renderer_host/resource_handler.h" |
| 21 #include "chrome/common/child_process_info.h" | 25 #include "chrome/common/child_process_info.h" |
| 22 #include "chrome/common/filter_policy.h" | 26 #include "chrome/common/filter_policy.h" |
| 23 #include "chrome/common/ipc_message.h" | 27 #include "chrome/common/ipc_message.h" |
| 24 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 25 #include "webkit/glue/resource_type.h" | 29 #include "webkit/glue/resource_type.h" |
| 26 | 30 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 class Receiver : public IPC::Message::Sender, | 56 class Receiver : public IPC::Message::Sender, |
| 53 public ChildProcessInfo { | 57 public ChildProcessInfo { |
| 54 public: | 58 public: |
| 55 // Return the URLRequestContext for the given request. | 59 // Return the URLRequestContext for the given request. |
| 56 // If NULL is returned, the default context for the profile is used. | 60 // If NULL is returned, the default context for the profile is used. |
| 57 virtual URLRequestContext* GetRequestContext( | 61 virtual URLRequestContext* GetRequestContext( |
| 58 uint32 request_id, | 62 uint32 request_id, |
| 59 const ViewHostMsg_Resource_Request& request_data) = 0; | 63 const ViewHostMsg_Resource_Request& request_data) = 0; |
| 60 | 64 |
| 61 protected: | 65 protected: |
| 62 Receiver(ChildProcessInfo::ProcessType type) : ChildProcessInfo(type) { } | 66 explicit Receiver(ChildProcessInfo::ProcessType type) |
| 67 : ChildProcessInfo(type) { } |
| 63 virtual ~Receiver() { } | 68 virtual ~Receiver() { } |
| 64 }; | 69 }; |
| 65 | 70 |
| 66 // Holds the data we would like to associate with each request | 71 // Holds the data we would like to associate with each request |
| 67 class ExtraRequestInfo : public URLRequest::UserData { | 72 class ExtraRequestInfo : public URLRequest::UserData { |
| 68 friend class ResourceDispatcherHost; | 73 friend class ResourceDispatcherHost; |
| 69 public: | 74 public: |
| 70 ExtraRequestInfo(ResourceHandler* handler, | 75 ExtraRequestInfo(ResourceHandler* handler, |
| 71 ChildProcessInfo::ProcessType process_type, | 76 ChildProcessInfo::ProcessType process_type, |
| 72 int process_id, | 77 int process_id, |
| 73 int route_id, | 78 int route_id, |
| 74 int request_id, | 79 int request_id, |
| 75 std::string frame_origin, | 80 std::string frame_origin, |
| 76 std::string main_frame_origin, | 81 std::string main_frame_origin, |
| 77 ResourceType::Type resource_type, | 82 ResourceType::Type resource_type, |
| 78 uint64 upload_size) | 83 uint64 upload_size) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Whether this request has started reading any bytes from the response | 171 // Whether this request has started reading any bytes from the response |
| 167 // yet. Will be true after the first (unpaused) call to Read. | 172 // yet. Will be true after the first (unpaused) call to Read. |
| 168 bool has_started_reading; | 173 bool has_started_reading; |
| 169 | 174 |
| 170 // How many bytes have been read while this request has been paused. | 175 // How many bytes have been read while this request has been paused. |
| 171 int paused_read_bytes; | 176 int paused_read_bytes; |
| 172 }; | 177 }; |
| 173 | 178 |
| 174 class Observer { | 179 class Observer { |
| 175 public: | 180 public: |
| 181 virtual ~Observer() { } |
| 176 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, | 182 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, |
| 177 URLRequest* request) = 0; | 183 URLRequest* request) = 0; |
| 178 virtual void OnResponseCompleted( | 184 virtual void OnResponseCompleted( |
| 179 ResourceDispatcherHost* resource_dispatcher, | 185 ResourceDispatcherHost* resource_dispatcher, |
| 180 URLRequest* request) = 0; | 186 URLRequest* request) = 0; |
| 181 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, | 187 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, |
| 182 URLRequest* request, | 188 URLRequest* request, |
| 183 const GURL& new_url) = 0; | 189 const GURL& new_url) = 0; |
| 184 }; | 190 }; |
| 185 | 191 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 357 |
| 352 // Cancels any blocked request for the specified route id. | 358 // Cancels any blocked request for the specified route id. |
| 353 void CancelBlockedRequestsForRoute(int process_id, int route_id); | 359 void CancelBlockedRequestsForRoute(int process_id, int route_id); |
| 354 | 360 |
| 355 // Decrements the pending_data_count for the request and resumes | 361 // Decrements the pending_data_count for the request and resumes |
| 356 // the request if it was paused due to too many pending data | 362 // the request if it was paused due to too many pending data |
| 357 // messages sent. | 363 // messages sent. |
| 358 void DataReceivedACK(int process_id, int request_id); | 364 void DataReceivedACK(int process_id, int request_id); |
| 359 | 365 |
| 360 // Needed for the sync IPC message dispatcher macros. | 366 // Needed for the sync IPC message dispatcher macros. |
| 361 bool Send(IPC::Message* message) { delete message; return false; } | 367 bool Send(IPC::Message* message) { |
| 368 delete message; |
| 369 return false; |
| 370 } |
| 362 | 371 |
| 363 private: | 372 private: |
| 364 FRIEND_TEST(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies); | 373 FRIEND_TEST(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies); |
| 365 FRIEND_TEST(ResourceDispatcherHostTest, | 374 FRIEND_TEST(ResourceDispatcherHostTest, |
| 366 IncrementOutstandingRequestsMemoryCost); | 375 IncrementOutstandingRequestsMemoryCost); |
| 367 FRIEND_TEST(ResourceDispatcherHostTest, | 376 FRIEND_TEST(ResourceDispatcherHostTest, |
| 368 CalculateApproximateMemoryCost); | 377 CalculateApproximateMemoryCost); |
| 369 | 378 |
| 370 class ShutdownTask; | 379 class ShutdownTask; |
| 371 | 380 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // Estimate how much heap space |request| will consume to run. | 426 // Estimate how much heap space |request| will consume to run. |
| 418 static int CalculateApproximateMemoryCost(URLRequest* request); | 427 static int CalculateApproximateMemoryCost(URLRequest* request); |
| 419 | 428 |
| 420 // The list of all requests that we have pending. This list is not really | 429 // The list of all requests that we have pending. This list is not really |
| 421 // optimized, and assumes that we have relatively few requests pending at once | 430 // optimized, and assumes that we have relatively few requests pending at once |
| 422 // since some operations require brute-force searching of the list. | 431 // since some operations require brute-force searching of the list. |
| 423 // | 432 // |
| 424 // It may be enhanced in the future to provide some kind of prioritization | 433 // It may be enhanced in the future to provide some kind of prioritization |
| 425 // mechanism. We should also consider a hashtable or binary tree if it turns | 434 // mechanism. We should also consider a hashtable or binary tree if it turns |
| 426 // out we have a lot of things here. | 435 // out we have a lot of things here. |
| 427 typedef std::map<GlobalRequestID,URLRequest*> PendingRequestList; | 436 typedef std::map<GlobalRequestID, URLRequest*> PendingRequestList; |
| 428 | 437 |
| 429 // Deletes the pending request identified by the iterator passed in. | 438 // Deletes the pending request identified by the iterator passed in. |
| 430 // This function will invalidate the iterator passed in. Callers should | 439 // This function will invalidate the iterator passed in. Callers should |
| 431 // not rely on this iterator being valid on return. | 440 // not rely on this iterator being valid on return. |
| 432 void RemovePendingRequest(const PendingRequestList::iterator& iter); | 441 void RemovePendingRequest(const PendingRequestList::iterator& iter); |
| 433 | 442 |
| 434 // Notify our observers that we started receiving a response for a request. | 443 // Notify our observers that we started receiving a response for a request. |
| 435 void NotifyResponseStarted(URLRequest* request, int process_id); | 444 void NotifyResponseStarted(URLRequest* request, int process_id); |
| 436 | 445 |
| 437 // Notify our observers that a request has been redirected. | 446 // Notify our observers that a request has been redirected. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 int max_outstanding_requests_cost_per_process_; | 548 int max_outstanding_requests_cost_per_process_; |
| 540 | 549 |
| 541 // Used during IPC message dispatching so that the handlers can get a pointer | 550 // Used during IPC message dispatching so that the handlers can get a pointer |
| 542 // to the source of the message. | 551 // to the source of the message. |
| 543 Receiver* receiver_; | 552 Receiver* receiver_; |
| 544 | 553 |
| 545 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); | 554 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); |
| 546 }; | 555 }; |
| 547 | 556 |
| 548 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 557 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| OLD | NEW |