Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(880)

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host.h

Issue 5874002: Create a ResourceMessageFilter to filter resource related IPCs. This gets ri... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 forwards the messages from the 7 // dispatches them to URLRequests. It then forwards 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
(...skipping 17 matching lines...) Expand all
28 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
29 #include "webkit/glue/resource_type.h" 29 #include "webkit/glue/resource_type.h"
30 30
31 class CrossSiteResourceHandler; 31 class CrossSiteResourceHandler;
32 class DownloadFileManager; 32 class DownloadFileManager;
33 class DownloadRequestLimiter; 33 class DownloadRequestLimiter;
34 class LoginHandler; 34 class LoginHandler;
35 class PluginService; 35 class PluginService;
36 class ResourceDispatcherHostRequestInfo; 36 class ResourceDispatcherHostRequestInfo;
37 class ResourceHandler; 37 class ResourceHandler;
38 class ResourceMessageFilter;
38 class SafeBrowsingService; 39 class SafeBrowsingService;
39 class SaveFileManager; 40 class SaveFileManager;
40 class SSLClientAuthHandler; 41 class SSLClientAuthHandler;
41 class UserScriptListener; 42 class UserScriptListener;
42 class URLRequestContext; 43 class URLRequestContext;
43 class WebKitThread; 44 class WebKitThread;
44 struct DownloadSaveInfo; 45 struct DownloadSaveInfo;
45 struct GlobalRequestID; 46 struct GlobalRequestID;
46 struct ViewHostMsg_Resource_Request; 47 struct ViewHostMsg_Resource_Request;
47 struct ViewMsg_ClosePage_Params; 48 struct ViewMsg_ClosePage_Params;
48 49
49 namespace webkit_blob { 50 namespace webkit_blob {
50 class DeletableFileReference; 51 class DeletableFileReference;
51 } 52 }
52 53
53 class ResourceDispatcherHost : public net::URLRequest::Delegate { 54 class ResourceDispatcherHost : public net::URLRequest::Delegate {
54 public: 55 public:
55 // Implemented by the client of ResourceDispatcherHost to receive messages in
56 // response to a resource load. The messages are intended to be forwarded to
57 // the ResourceDispatcher in the child process via an IPC channel that the
58 // client manages.
59 //
60 // NOTE: This class unfortunately cannot be named 'Delegate' because that
61 // conflicts with the name of ResourceDispatcherHost's base class.
62 //
63 // If the receiver is unable to send a given message (i.e., if Send returns
64 // false), then the ResourceDispatcherHost assumes the receiver has failed,
65 // and the given request will be dropped. (This happens, for example, when a
66 // renderer crashes and the channel dies).
67 class Receiver : public IPC::Message::Sender,
68 public ChildProcessInfo {
69 public:
70 // Returns the URLRequestContext for the given request.
71 // If NULL is returned, the default context for the profile is used.
72 virtual URLRequestContext* GetRequestContext(
73 uint32 request_id,
74 const ViewHostMsg_Resource_Request& request_data) = 0;
75
76 protected:
77 explicit Receiver(ChildProcessInfo::ProcessType type, int child_id);
78 virtual ~Receiver();
79 };
80
81 class Observer { 56 class Observer {
82 public: 57 public:
83 virtual ~Observer() {} 58 virtual ~Observer() {}
84 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, 59 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher,
85 net::URLRequest* request) = 0; 60 net::URLRequest* request) = 0;
86 virtual void OnResponseCompleted( 61 virtual void OnResponseCompleted(
87 ResourceDispatcherHost* resource_dispatcher, 62 ResourceDispatcherHost* resource_dispatcher,
88 net::URLRequest* request) = 0; 63 net::URLRequest* request) = 0;
89 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, 64 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher,
90 net::URLRequest* request, 65 net::URLRequest* request,
91 const GURL& new_url) = 0; 66 const GURL& new_url) = 0;
92 }; 67 };
93 68
94 ResourceDispatcherHost(); 69 ResourceDispatcherHost();
95 ~ResourceDispatcherHost(); 70 ~ResourceDispatcherHost();
96 71
97 void Initialize(); 72 void Initialize();
98 73
99 // Puts the resource dispatcher host in an inactive state (unable to begin 74 // Puts the resource dispatcher host in an inactive state (unable to begin
100 // new requests). Cancels all pending requests. 75 // new requests). Cancels all pending requests.
101 void Shutdown(); 76 void Shutdown();
102 77
103 // Returns true if the message was a resource message that was processed. 78 // Returns true if the message was a resource message that was processed.
104 // If it was, message_was_ok will be false iff the message was corrupt. 79 // If it was, message_was_ok will be false iff the message was corrupt.
105 bool OnMessageReceived(const IPC::Message& message, 80 bool OnMessageReceived(const IPC::Message& message,
106 Receiver* receiver, 81 ResourceMessageFilter* filter,
107 bool* message_was_ok); 82 bool* message_was_ok);
108 83
109 // Initiates a download from the browser process (as opposed to a resource 84 // Initiates a download from the browser process (as opposed to a resource
110 // request from the renderer or another child process). 85 // request from the renderer or another child process).
111 void BeginDownload(const GURL& url, 86 void BeginDownload(const GURL& url,
112 const GURL& referrer, 87 const GURL& referrer,
113 const DownloadSaveInfo& save_info, 88 const DownloadSaveInfo& save_info,
114 bool prompt_for_save_location, 89 bool prompt_for_save_location,
115 int process_unique_id, 90 int process_unique_id,
116 int route_id, 91 int route_id,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // Decrements the pending_data_count for the request and resumes 244 // Decrements the pending_data_count for the request and resumes
270 // the request if it was paused due to too many pending data 245 // the request if it was paused due to too many pending data
271 // messages sent. 246 // messages sent.
272 void DataReceivedACK(int process_unique_id, int request_id); 247 void DataReceivedACK(int process_unique_id, int request_id);
273 248
274 // Maintains a collection of temp files created in support of 249 // Maintains a collection of temp files created in support of
275 // the download_to_file capability. Used to grant access to the 250 // the download_to_file capability. Used to grant access to the
276 // child process and to defer deletion of the file until it's 251 // child process and to defer deletion of the file until it's
277 // no longer needed. 252 // no longer needed.
278 void RegisterDownloadedTempFile( 253 void RegisterDownloadedTempFile(
279 int receiver_id, int request_id, 254 int child_id, int request_id,
280 webkit_blob::DeletableFileReference* reference); 255 webkit_blob::DeletableFileReference* reference);
281 void UnregisterDownloadedTempFile(int receiver_id, int request_id); 256 void UnregisterDownloadedTempFile(int child_id, int request_id);
282 257
283 // Needed for the sync IPC message dispatcher macros. 258 // Needed for the sync IPC message dispatcher macros.
284 bool Send(IPC::Message* message); 259 bool Send(IPC::Message* message);
285 260
286 // Controls if we launch or squash prefetch requests as they arrive 261 // Controls if we launch or squash prefetch requests as they arrive
287 // from renderers. 262 // from renderers.
288 static bool is_prefetch_enabled(); 263 static bool is_prefetch_enabled();
289 static void set_is_prefetch_enabled(bool value); 264 static void set_is_prefetch_enabled(bool value);
290 265
291 private: 266 private:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void OnDataReceivedACK(int request_id); 390 void OnDataReceivedACK(int request_id);
416 void OnDataDownloadedACK(int request_id); 391 void OnDataDownloadedACK(int request_id);
417 void OnUploadProgressACK(int request_id); 392 void OnUploadProgressACK(int request_id);
418 void OnCancelRequest(int request_id); 393 void OnCancelRequest(int request_id);
419 void OnFollowRedirect(int request_id, 394 void OnFollowRedirect(int request_id,
420 bool has_new_first_party_for_cookies, 395 bool has_new_first_party_for_cookies,
421 const GURL& new_first_party_for_cookies); 396 const GURL& new_first_party_for_cookies);
422 void OnReleaseDownloadedFile(int request_id); 397 void OnReleaseDownloadedFile(int request_id);
423 398
424 ResourceHandler* CreateSafeBrowsingResourceHandler( 399 ResourceHandler* CreateSafeBrowsingResourceHandler(
425 ResourceHandler* handler, int child_id, int route_id, 400 ResourceHandler* handler, int route_id, ResourceType::Type resource_type);
426 ResourceType::Type resource_type);
427 401
428 // Creates ResourceDispatcherHostRequestInfo for a browser-initiated request 402 // Creates ResourceDispatcherHostRequestInfo for a browser-initiated request
429 // (a download or a page save). |download| should be true if the request 403 // (a download or a page save). |download| should be true if the request
430 // is a file download. 404 // is a file download.
431 ResourceDispatcherHostRequestInfo* CreateRequestInfoForBrowserRequest( 405 ResourceDispatcherHostRequestInfo* CreateRequestInfoForBrowserRequest(
432 ResourceHandler* handler, int child_id, int route_id, bool download); 406 ResourceHandler* handler, int child_id, int route_id, bool download);
433 407
434 // Returns true if |request| is in |pending_requests_|. 408 // Returns true if |request| is in |pending_requests_|.
435 bool IsValidRequest(net::URLRequest* request); 409 bool IsValidRequest(net::URLRequest* request);
436 410
437 // Returns true if the message passed in is a resource related message.
438 static bool IsResourceDispatcherHostMessage(const IPC::Message&);
439
440 // Sets replace_extension_localization_templates on all text/css requests that 411 // Sets replace_extension_localization_templates on all text/css requests that
441 // have "chrome-extension://" scheme. 412 // have "chrome-extension://" scheme.
442 static void ApplyExtensionLocalizationFilter( 413 static void ApplyExtensionLocalizationFilter(
443 const GURL& url, 414 const GURL& url,
444 const ResourceType::Type& resource_type, 415 const ResourceType::Type& resource_type,
445 ResourceDispatcherHostRequestInfo* request_info); 416 ResourceDispatcherHostRequestInfo* request_info);
446 417
447 // Determine request priority based on how critical this resource typically 418 // Determine request priority based on how critical this resource typically
448 // is to user-perceived page load performance. 419 // is to user-perceived page load performance.
449 static net::RequestPriority DetermineRequestPriority(ResourceType::Type type); 420 static net::RequestPriority DetermineRequestPriority(ResourceType::Type type);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // many outstanding requests can be issued per child process host. 485 // many outstanding requests can be issued per child process host.
515 // The constraint is expressed in terms of bytes (where the cost of 486 // The constraint is expressed in terms of bytes (where the cost of
516 // individual requests is given by CalculateApproximateMemoryCost). 487 // individual requests is given by CalculateApproximateMemoryCost).
517 // The total number of outstanding requests is roughly: 488 // The total number of outstanding requests is roughly:
518 // (max_outstanding_requests_cost_per_process_ / 489 // (max_outstanding_requests_cost_per_process_ /
519 // kAvgBytesPerOutstandingRequest) 490 // kAvgBytesPerOutstandingRequest)
520 int max_outstanding_requests_cost_per_process_; 491 int max_outstanding_requests_cost_per_process_;
521 492
522 // Used during IPC message dispatching so that the handlers can get a pointer 493 // Used during IPC message dispatching so that the handlers can get a pointer
523 // to the source of the message. 494 // to the source of the message.
524 Receiver* receiver_; 495 ResourceMessageFilter* filter_;
525 496
526 static bool is_prefetch_enabled_; 497 static bool is_prefetch_enabled_;
527 498
528 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); 499 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost);
529 }; 500 };
530 501
531 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ 502 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698