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 // 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 |
11 | 11 |
12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
14 | 14 |
15 #include <map> | 15 #include <map> |
16 #include <set> | 16 #include <set> |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
21 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
22 #include "base/memory/linked_ptr.h" | 22 #include "base/memory/linked_ptr.h" |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
25 #include "base/time.h" | 25 #include "base/time.h" |
26 #include "base/timer.h" | 26 #include "base/timer.h" |
27 #include "content/browser/download/download_resource_handler.h" | 27 #include "content/browser/download/download_resource_handler.h" |
| 28 #include "content/browser/loader/render_view_host_tracker.h" |
28 #include "content/browser/loader/resource_loader.h" | 29 #include "content/browser/loader/resource_loader.h" |
29 #include "content/browser/loader/resource_loader_delegate.h" | 30 #include "content/browser/loader/resource_loader_delegate.h" |
30 #include "content/browser/loader/resource_scheduler.h" | 31 #include "content/browser/loader/resource_scheduler.h" |
31 #include "content/common/content_export.h" | 32 #include "content/common/content_export.h" |
32 #include "content/public/browser/child_process_data.h" | 33 #include "content/public/browser/child_process_data.h" |
33 #include "content/public/browser/download_id.h" | 34 #include "content/public/browser/download_id.h" |
34 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/resource_dispatcher_host.h" | 36 #include "content/public/browser/resource_dispatcher_host.h" |
36 #include "ipc/ipc_message.h" | 37 #include "ipc/ipc_message.h" |
37 #include "net/cookies/canonical_cookie.h" | 38 #include "net/cookies/canonical_cookie.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // unresponsive. | 161 // unresponsive. |
161 void OnSimulateSwapOutACK(const ViewMsg_SwapOut_Params& params); | 162 void OnSimulateSwapOutACK(const ViewMsg_SwapOut_Params& params); |
162 | 163 |
163 // Called when the renderer loads a resource from its internal cache. | 164 // Called when the renderer loads a resource from its internal cache. |
164 void OnDidLoadResourceFromMemoryCache(const GURL& url, | 165 void OnDidLoadResourceFromMemoryCache(const GURL& url, |
165 const std::string& security_info, | 166 const std::string& security_info, |
166 const std::string& http_method, | 167 const std::string& http_method, |
167 const std::string& mime_type, | 168 const std::string& mime_type, |
168 ResourceType::Type resource_type); | 169 ResourceType::Type resource_type); |
169 | 170 |
| 171 // Called when a RenderViewHost is created. |
| 172 void OnRenderViewHostCreated(int child_id, int route_id); |
| 173 |
| 174 // Called when a RenderViewHost is deleted. |
| 175 void OnRenderViewHostDeleted(int child_id, int route_id); |
| 176 |
170 // Force cancels any pending requests for the given process. | 177 // Force cancels any pending requests for the given process. |
171 void CancelRequestsForProcess(int child_id); | 178 void CancelRequestsForProcess(int child_id); |
172 | 179 |
173 // Force cancels any pending requests for the given route id. This method | |
174 // acts like CancelRequestsForProcess when route_id is -1. | |
175 void CancelRequestsForRoute(int child_id, int route_id); | |
176 | |
177 void OnUserGesture(WebContentsImpl* contents); | 180 void OnUserGesture(WebContentsImpl* contents); |
178 | 181 |
179 // Retrieves a net::URLRequest. Must be called from the IO thread. | 182 // Retrieves a net::URLRequest. Must be called from the IO thread. |
180 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); | 183 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); |
181 | 184 |
182 void RemovePendingRequest(int child_id, int request_id); | 185 void RemovePendingRequest(int child_id, int request_id); |
183 | 186 |
184 // Cancels any blocked request for the specified route id. | 187 // Cancels any blocked request for the specified route id. |
185 void CancelBlockedRequestsForRoute(int child_id, int route_id); | 188 void CancelBlockedRequestsForRoute(int child_id, int route_id); |
186 | 189 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // data structures supporting this request (net::URLRequest object, | 286 // data structures supporting this request (net::URLRequest object, |
284 // HttpNetworkTransaction, etc...). | 287 // HttpNetworkTransaction, etc...). |
285 // The value of |cost| is added to the running total, and the resulting | 288 // The value of |cost| is added to the running total, and the resulting |
286 // sum is returned. | 289 // sum is returned. |
287 int IncrementOutstandingRequestsMemoryCost(int cost, | 290 int IncrementOutstandingRequestsMemoryCost(int cost, |
288 int child_id); | 291 int child_id); |
289 | 292 |
290 // Estimate how much heap space |request| will consume to run. | 293 // Estimate how much heap space |request| will consume to run. |
291 static int CalculateApproximateMemoryCost(net::URLRequest* request); | 294 static int CalculateApproximateMemoryCost(net::URLRequest* request); |
292 | 295 |
| 296 // Force cancels any pending requests for the given route id. This method |
| 297 // acts like CancelRequestsForProcess when route_id is -1. |
| 298 void CancelRequestsForRoute(int child_id, int route_id); |
| 299 |
293 // The list of all requests that we have pending. This list is not really | 300 // The list of all requests that we have pending. This list is not really |
294 // optimized, and assumes that we have relatively few requests pending at once | 301 // optimized, and assumes that we have relatively few requests pending at once |
295 // since some operations require brute-force searching of the list. | 302 // since some operations require brute-force searching of the list. |
296 // | 303 // |
297 // It may be enhanced in the future to provide some kind of prioritization | 304 // It may be enhanced in the future to provide some kind of prioritization |
298 // mechanism. We should also consider a hashtable or binary tree if it turns | 305 // mechanism. We should also consider a hashtable or binary tree if it turns |
299 // out we have a lot of things here. | 306 // out we have a lot of things here. |
300 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; | 307 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; |
301 | 308 |
302 // Deletes the pending request identified by the iterator passed in. | 309 // Deletes the pending request identified by the iterator passed in. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // http://crbug.com/90971 - Assists in tracking down use-after-frees on | 437 // http://crbug.com/90971 - Assists in tracking down use-after-frees on |
431 // shutdown. | 438 // shutdown. |
432 std::set<const ResourceContext*> active_resource_contexts_; | 439 std::set<const ResourceContext*> active_resource_contexts_; |
433 | 440 |
434 typedef std::map<GlobalRequestID, | 441 typedef std::map<GlobalRequestID, |
435 ObserverList<ResourceMessageDelegate>*> DelegateMap; | 442 ObserverList<ResourceMessageDelegate>*> DelegateMap; |
436 DelegateMap delegate_map_; | 443 DelegateMap delegate_map_; |
437 | 444 |
438 scoped_ptr<ResourceScheduler> scheduler_; | 445 scoped_ptr<ResourceScheduler> scheduler_; |
439 | 446 |
| 447 RenderViewHostTracker tracker_; // Lives on UI thread. |
| 448 |
440 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 449 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
441 }; | 450 }; |
442 | 451 |
443 } // namespace content | 452 } // namespace content |
444 | 453 |
445 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 454 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |