OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 namespace net { | 52 namespace net { |
53 class URLRequestJobFactory; | 53 class URLRequestJobFactory; |
54 } // namespace net | 54 } // namespace net |
55 | 55 |
56 namespace webkit_blob { | 56 namespace webkit_blob { |
57 class DeletableFileReference; | 57 class DeletableFileReference; |
58 } | 58 } |
59 | 59 |
60 class ResourceDispatcherHost : public net::URLRequest::Delegate { | 60 class ResourceDispatcherHost : public net::URLRequest::Delegate { |
61 public: | 61 public: |
| 62 class Observer { |
| 63 public: |
| 64 // Called when a request begins. Return false to abort the request. |
| 65 virtual bool ShouldBeginRequest(int child_id, int route_id, |
| 66 const ResourceHostMsg_Request& request_data, |
| 67 const content::ResourceContext& resource_context, |
| 68 const GURL& referrer) = 0; |
| 69 |
| 70 // Called after the load flags have been set when a request begins. Use it |
| 71 // to add or remove load flags. |
| 72 virtual void MutateLoadFlags(int child_id, int route_id, |
| 73 int* load_flags) = 0; |
| 74 protected: |
| 75 Observer() {} |
| 76 virtual ~Observer() {} |
| 77 }; |
| 78 |
62 explicit ResourceDispatcherHost( | 79 explicit ResourceDispatcherHost( |
63 const ResourceQueue::DelegateSet& resource_queue_delegates); | 80 const ResourceQueue::DelegateSet& resource_queue_delegates); |
64 ~ResourceDispatcherHost(); | 81 ~ResourceDispatcherHost(); |
65 | 82 |
66 void Initialize(); | 83 void Initialize(); |
67 | 84 |
68 // Puts the resource dispatcher host in an inactive state (unable to begin | 85 // Puts the resource dispatcher host in an inactive state (unable to begin |
69 // new requests). Cancels all pending requests. | 86 // new requests). Cancels all pending requests. |
70 void Shutdown(); | 87 void Shutdown(); |
71 | 88 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 void UnregisterDownloadedTempFile(int child_id, int request_id); | 254 void UnregisterDownloadedTempFile(int child_id, int request_id); |
238 | 255 |
239 // Needed for the sync IPC message dispatcher macros. | 256 // Needed for the sync IPC message dispatcher macros. |
240 bool Send(IPC::Message* message); | 257 bool Send(IPC::Message* message); |
241 | 258 |
242 // Controls if we launch or squash prefetch requests as they arrive | 259 // Controls if we launch or squash prefetch requests as they arrive |
243 // from renderers. | 260 // from renderers. |
244 static bool is_prefetch_enabled(); | 261 static bool is_prefetch_enabled(); |
245 static void set_is_prefetch_enabled(bool value); | 262 static void set_is_prefetch_enabled(bool value); |
246 | 263 |
| 264 // This does not take ownership of the observer. It is expected that the |
| 265 // observer have a longer lifetime than the ResourceDispatcherHost. |
| 266 void set_observer(Observer* observer) { observer_ = observer; } |
| 267 |
247 private: | 268 private: |
248 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 269 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
249 TestBlockedRequestsProcessDies); | 270 TestBlockedRequestsProcessDies); |
250 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 271 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
251 IncrementOutstandingRequestsMemoryCost); | 272 IncrementOutstandingRequestsMemoryCost); |
252 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 273 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
253 CalculateApproximateMemoryCost); | 274 CalculateApproximateMemoryCost); |
254 | 275 |
255 class ShutdownTask; | 276 class ShutdownTask; |
256 | 277 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // individual requests is given by CalculateApproximateMemoryCost). | 490 // individual requests is given by CalculateApproximateMemoryCost). |
470 // The total number of outstanding requests is roughly: | 491 // The total number of outstanding requests is roughly: |
471 // (max_outstanding_requests_cost_per_process_ / | 492 // (max_outstanding_requests_cost_per_process_ / |
472 // kAvgBytesPerOutstandingRequest) | 493 // kAvgBytesPerOutstandingRequest) |
473 int max_outstanding_requests_cost_per_process_; | 494 int max_outstanding_requests_cost_per_process_; |
474 | 495 |
475 // Used during IPC message dispatching so that the handlers can get a pointer | 496 // Used during IPC message dispatching so that the handlers can get a pointer |
476 // to the source of the message. | 497 // to the source of the message. |
477 ResourceMessageFilter* filter_; | 498 ResourceMessageFilter* filter_; |
478 | 499 |
| 500 Observer* observer_; |
| 501 |
479 static bool is_prefetch_enabled_; | 502 static bool is_prefetch_enabled_; |
480 | 503 |
481 | |
482 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); | 504 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); |
483 }; | 505 }; |
484 | 506 |
485 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 507 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
OLD | NEW |