| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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> | 16 #include <string> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 22 #include "base/process.h" | 22 #include "base/process.h" |
| 23 #include "base/timer.h" | 23 #include "base/timer.h" |
| 24 #include "chrome/common/child_process_info.h" | 24 #include "chrome/common/child_process_info.h" |
| 25 #include "chrome/browser/privacy_blacklist/blocked_response.h" | 25 #include "chrome/browser/privacy_blacklist/blocked_response.h" |
| 26 #include "chrome/browser/renderer_host/resource_queue.h" |
| 26 #include "ipc/ipc_message.h" | 27 #include "ipc/ipc_message.h" |
| 27 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 28 #include "webkit/glue/resource_type.h" | 29 #include "webkit/glue/resource_type.h" |
| 29 | 30 |
| 30 class CrossSiteResourceHandler; | 31 class CrossSiteResourceHandler; |
| 31 class DownloadFileManager; | 32 class DownloadFileManager; |
| 32 class DownloadRequestManager; | 33 class DownloadRequestManager; |
| 33 class LoginHandler; | 34 class LoginHandler; |
| 34 class PluginService; | 35 class PluginService; |
| 35 class ResourceDispatcherHostRequestInfo; | 36 class ResourceDispatcherHostRequestInfo; |
| 36 class ResourceHandler; | 37 class ResourceHandler; |
| 37 class SafeBrowsingService; | 38 class SafeBrowsingService; |
| 38 class SaveFileManager; | 39 class SaveFileManager; |
| 39 class SocketStreamDispatcherHost; | 40 class SocketStreamDispatcherHost; |
| 40 class SSLClientAuthHandler; | 41 class SSLClientAuthHandler; |
| 41 class UserScriptListener; | 42 class UserScriptListener; |
| 42 class URLRequestContext; | 43 class URLRequestContext; |
| 43 class WebKitThread; | 44 class WebKitThread; |
| 45 struct GlobalRequestID; |
| 44 struct ViewHostMsg_Resource_Request; | 46 struct ViewHostMsg_Resource_Request; |
| 45 struct ViewMsg_ClosePage_Params; | 47 struct ViewMsg_ClosePage_Params; |
| 46 | 48 |
| 47 class ResourceDispatcherHost : public URLRequest::Delegate { | 49 class ResourceDispatcherHost : public URLRequest::Delegate { |
| 48 public: | 50 public: |
| 49 // Implemented by the client of ResourceDispatcherHost to receive messages in | 51 // Implemented by the client of ResourceDispatcherHost to receive messages in |
| 50 // response to a resource load. The messages are intended to be forwarded to | 52 // response to a resource load. The messages are intended to be forwarded to |
| 51 // the ResourceDispatcher in the child process via an IPC channel that the | 53 // the ResourceDispatcher in the child process via an IPC channel that the |
| 52 // client manages. | 54 // client manages. |
| 53 // | 55 // |
| (...skipping 25 matching lines...) Expand all Loading... |
| 79 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, | 81 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, |
| 80 URLRequest* request) = 0; | 82 URLRequest* request) = 0; |
| 81 virtual void OnResponseCompleted( | 83 virtual void OnResponseCompleted( |
| 82 ResourceDispatcherHost* resource_dispatcher, | 84 ResourceDispatcherHost* resource_dispatcher, |
| 83 URLRequest* request) = 0; | 85 URLRequest* request) = 0; |
| 84 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, | 86 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, |
| 85 URLRequest* request, | 87 URLRequest* request, |
| 86 const GURL& new_url) = 0; | 88 const GURL& new_url) = 0; |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 // Uniquely identifies a URLRequest. | |
| 90 struct GlobalRequestID { | |
| 91 GlobalRequestID() : child_id(-1), request_id(-1) { | |
| 92 } | |
| 93 GlobalRequestID(int child_id, int request_id) | |
| 94 : child_id(child_id), | |
| 95 request_id(request_id) { | |
| 96 } | |
| 97 | |
| 98 int child_id; | |
| 99 int request_id; | |
| 100 | |
| 101 bool operator<(const GlobalRequestID& other) const { | |
| 102 if (child_id == other.child_id) | |
| 103 return request_id < other.request_id; | |
| 104 return child_id < other.child_id; | |
| 105 } | |
| 106 }; | |
| 107 | |
| 108 ResourceDispatcherHost(); | 91 ResourceDispatcherHost(); |
| 109 ~ResourceDispatcherHost(); | 92 ~ResourceDispatcherHost(); |
| 110 | 93 |
| 111 void Initialize(); | 94 void Initialize(); |
| 112 | 95 |
| 113 // Puts the resource dispatcher host in an inactive state (unable to begin | 96 // Puts the resource dispatcher host in an inactive state (unable to begin |
| 114 // new requests). Cancels all pending requests. | 97 // new requests). Cancels all pending requests. |
| 115 void Shutdown(); | 98 void Shutdown(); |
| 116 | 99 |
| 117 // Returns true if the message was a resource message that was processed. | 100 // Returns true if the message was a resource message that was processed. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 225 |
| 243 // Adds an observer. The observer will be called on the IO thread. To | 226 // Adds an observer. The observer will be called on the IO thread. To |
| 244 // observe resource events on the UI thread, subscribe to the | 227 // observe resource events on the UI thread, subscribe to the |
| 245 // NOTIFY_RESOURCE_* notifications of the notification service. | 228 // NOTIFY_RESOURCE_* notifications of the notification service. |
| 246 void AddObserver(Observer* obs); | 229 void AddObserver(Observer* obs); |
| 247 | 230 |
| 248 // Removes an observer. | 231 // Removes an observer. |
| 249 void RemoveObserver(Observer* obs); | 232 void RemoveObserver(Observer* obs); |
| 250 | 233 |
| 251 // Retrieves a URLRequest. Must be called from the IO thread. | 234 // Retrieves a URLRequest. Must be called from the IO thread. |
| 252 URLRequest* GetURLRequest(GlobalRequestID request_id) const; | 235 URLRequest* GetURLRequest(const GlobalRequestID& request_id) const; |
| 253 | 236 |
| 254 // Notifies our observers that a request has been cancelled. | 237 // Notifies our observers that a request has been cancelled. |
| 255 void NotifyResponseCompleted(URLRequest* request, int process_unique_id); | 238 void NotifyResponseCompleted(URLRequest* request, int process_unique_id); |
| 256 | 239 |
| 257 void RemovePendingRequest(int process_unique_id, int request_id); | 240 void RemovePendingRequest(int process_unique_id, int request_id); |
| 258 | 241 |
| 259 // Causes all new requests for the route identified by | 242 // Causes all new requests for the route identified by |
| 260 // |process_unique_id| and |route_id| to be blocked (not being | 243 // |process_unique_id| and |route_id| to be blocked (not being |
| 261 // started) until ResumeBlockedRequestsForRoute or | 244 // started) until ResumeBlockedRequestsForRoute or |
| 262 // CancelBlockedRequestsForRoute is called. | 245 // CancelBlockedRequestsForRoute is called. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 390 |
| 408 // Returns true if the message passed in is a resource related message. | 391 // Returns true if the message passed in is a resource related message. |
| 409 static bool IsResourceDispatcherHostMessage(const IPC::Message&); | 392 static bool IsResourceDispatcherHostMessage(const IPC::Message&); |
| 410 | 393 |
| 411 PendingRequestList pending_requests_; | 394 PendingRequestList pending_requests_; |
| 412 | 395 |
| 413 // A timer that periodically calls UpdateLoadStates while pending_requests_ | 396 // A timer that periodically calls UpdateLoadStates while pending_requests_ |
| 414 // is not empty. | 397 // is not empty. |
| 415 base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_; | 398 base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_; |
| 416 | 399 |
| 400 // Handles the resource requests from the moment we want to start them. |
| 401 ResourceQueue resource_queue_; |
| 402 |
| 417 // We own the download file writing thread and manager | 403 // We own the download file writing thread and manager |
| 418 scoped_refptr<DownloadFileManager> download_file_manager_; | 404 scoped_refptr<DownloadFileManager> download_file_manager_; |
| 419 | 405 |
| 420 // Determines whether a download is allowed. | 406 // Determines whether a download is allowed. |
| 421 scoped_refptr<DownloadRequestManager> download_request_manager_; | 407 scoped_refptr<DownloadRequestManager> download_request_manager_; |
| 422 | 408 |
| 423 // We own the save file manager. | 409 // We own the save file manager. |
| 424 scoped_refptr<SaveFileManager> save_file_manager_; | 410 scoped_refptr<SaveFileManager> save_file_manager_; |
| 425 | 411 |
| 426 scoped_refptr<UserScriptListener> user_script_listener_; | 412 scoped_refptr<UserScriptListener> user_script_listener_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // to the source of the message. | 459 // to the source of the message. |
| 474 Receiver* receiver_; | 460 Receiver* receiver_; |
| 475 | 461 |
| 476 // Keeps track of elements blocked by the Privacy Blacklist. | 462 // Keeps track of elements blocked by the Privacy Blacklist. |
| 477 chrome::BlockedResponse blocked_; | 463 chrome::BlockedResponse blocked_; |
| 478 | 464 |
| 479 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); | 465 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); |
| 480 }; | 466 }; |
| 481 | 467 |
| 482 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 468 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| OLD | NEW |