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/time.h" | 25 #include "base/time/time.h" |
26 #include "base/timer/timer.h" | 26 #include "base/timer/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/async_revalidation_driver.h" |
28 #include "content/browser/loader/global_routing_id.h" | 29 #include "content/browser/loader/global_routing_id.h" |
29 #include "content/browser/loader/resource_loader.h" | 30 #include "content/browser/loader/resource_loader.h" |
30 #include "content/browser/loader/resource_loader_delegate.h" | 31 #include "content/browser/loader/resource_loader_delegate.h" |
31 #include "content/browser/loader/resource_scheduler.h" | 32 #include "content/browser/loader/resource_scheduler.h" |
32 #include "content/common/content_export.h" | 33 #include "content/common/content_export.h" |
33 #include "content/common/resource_request_body.h" | 34 #include "content/common/resource_request_body.h" |
34 #include "content/public/browser/child_process_data.h" | 35 #include "content/public/browser/child_process_data.h" |
35 #include "content/public/browser/download_item.h" | 36 #include "content/public/browser/download_item.h" |
36 #include "content/public/browser/download_url_parameters.h" | 37 #include "content/public/browser/download_url_parameters.h" |
37 #include "content/public/browser/global_request_id.h" | 38 #include "content/public/browser/global_request_id.h" |
38 #include "content/public/browser/notification_types.h" | 39 #include "content/public/browser/notification_types.h" |
39 #include "content/public/browser/resource_dispatcher_host.h" | 40 #include "content/public/browser/resource_dispatcher_host.h" |
40 #include "content/public/common/resource_type.h" | 41 #include "content/public/common/resource_type.h" |
41 #include "ipc/ipc_message.h" | 42 #include "ipc/ipc_message.h" |
42 #include "net/base/request_priority.h" | 43 #include "net/base/request_priority.h" |
43 #include "net/cookies/canonical_cookie.h" | 44 #include "net/cookies/canonical_cookie.h" |
44 #include "net/url_request/url_request.h" | 45 #include "net/url_request/url_request.h" |
45 | 46 |
46 class ResourceHandler; | 47 class ResourceHandler; |
47 struct ResourceHostMsg_Request; | 48 struct ResourceHostMsg_Request; |
48 | 49 |
49 namespace base { | 50 namespace base { |
50 class FilePath; | 51 class FilePath; |
51 } | 52 } |
52 | 53 |
53 namespace net { | 54 namespace net { |
| 55 class URLRequestContext; |
54 class URLRequestJobFactory; | 56 class URLRequestJobFactory; |
55 } | 57 } |
56 | 58 |
57 namespace storage { | 59 namespace storage { |
| 60 class BlobStorageContext; |
58 class ShareableFileReference; | 61 class ShareableFileReference; |
59 } | 62 } |
60 | 63 |
61 namespace content { | 64 namespace content { |
62 class AppCacheService; | 65 class AppCacheService; |
63 class NavigationURLLoaderImplCore; | 66 class NavigationURLLoaderImplCore; |
64 class ResourceContext; | 67 class ResourceContext; |
65 class ResourceDispatcherHostDelegate; | 68 class ResourceDispatcherHostDelegate; |
66 class ResourceMessageDelegate; | 69 class ResourceMessageDelegate; |
67 class ResourceMessageFilter; | 70 class ResourceMessageFilter; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 friend class ResourceMessageDelegate; | 300 friend class ResourceMessageDelegate; |
298 | 301 |
299 // Information about status of a ResourceLoader. | 302 // Information about status of a ResourceLoader. |
300 struct LoadInfo { | 303 struct LoadInfo { |
301 GURL url; | 304 GURL url; |
302 net::LoadStateWithParam load_state; | 305 net::LoadStateWithParam load_state; |
303 uint64 upload_position; | 306 uint64 upload_position; |
304 uint64 upload_size; | 307 uint64 upload_size; |
305 }; | 308 }; |
306 | 309 |
| 310 // Request parameters that are not included in ResourceHostMsg_Request. Used |
| 311 // as an argument to ConstructRequest(); |
| 312 struct ExtraRequestParams { |
| 313 ExtraRequestParams(); |
| 314 |
| 315 storage::BlobStorageContext* blob_context; |
| 316 int child_id; |
| 317 bool is_sync_load; |
| 318 bool use_embedded_identity; |
| 319 bool support_async_revalidation; |
| 320 const net::HttpRequestHeaders* extra_headers; |
| 321 }; |
| 322 |
307 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. | 323 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. |
308 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; | 324 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; |
309 | 325 |
| 326 // Map from ResourceContext, HttpCache and url key to AsyncRevalidationDriver |
| 327 // object. |
| 328 typedef std::map<AsyncRevalidationKey, |
| 329 AsyncRevalidationDriver*, |
| 330 AsyncRevalidationKey::LessThan> AsyncRevalidationMap; |
| 331 |
310 // ResourceLoaderDelegate implementation: | 332 // ResourceLoaderDelegate implementation: |
311 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( | 333 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( |
312 ResourceLoader* loader, | 334 ResourceLoader* loader, |
313 net::AuthChallengeInfo* auth_info) override; | 335 net::AuthChallengeInfo* auth_info) override; |
314 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; | 336 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; |
315 void DidStartRequest(ResourceLoader* loader) override; | 337 void DidStartRequest(ResourceLoader* loader) override; |
316 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; | 338 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; |
317 void DidReceiveResponse(ResourceLoader* loader) override; | 339 void DidReceiveResponse(ResourceLoader* loader) override; |
318 void DidFinishLoading(ResourceLoader* loader) override; | 340 void DidFinishLoading(ResourceLoader* loader) override; |
319 | 341 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 int route_id, | 450 int route_id, |
429 int request_id, | 451 int request_id, |
430 const ResourceHostMsg_Request& request_data, | 452 const ResourceHostMsg_Request& request_data, |
431 const linked_ptr<ResourceLoader>& loader); | 453 const linked_ptr<ResourceLoader>& loader); |
432 | 454 |
433 void BeginRequest(int request_id, | 455 void BeginRequest(int request_id, |
434 const ResourceHostMsg_Request& request_data, | 456 const ResourceHostMsg_Request& request_data, |
435 IPC::Message* sync_result, // only valid for sync | 457 IPC::Message* sync_result, // only valid for sync |
436 int route_id); // only valid for async | 458 int route_id); // only valid for async |
437 | 459 |
| 460 scoped_ptr<net::URLRequest> ConstructRequest( |
| 461 net::URLRequestContext* request_context, |
| 462 const ResourceHostMsg_Request& request_data, |
| 463 const ExtraRequestParams& extra_params); |
| 464 |
438 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 465 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
439 // loading. | 466 // loading. |
440 scoped_ptr<ResourceHandler> CreateResourceHandler( | 467 scoped_ptr<ResourceHandler> CreateResourceHandler( |
441 net::URLRequest* request, | 468 net::URLRequest* request, |
442 const ResourceHostMsg_Request& request_data, | 469 const ResourceHostMsg_Request& request_data, |
443 IPC::Message* sync_result, | 470 IPC::Message* sync_result, |
444 int route_id, | 471 int route_id, |
445 int process_type, | 472 int process_type, |
446 int child_id, | 473 int child_id, |
447 ResourceContext* resource_context); | 474 ResourceContext* resource_context); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 // specified |id|. | 527 // specified |id|. |
501 void RegisterResourceMessageDelegate(const GlobalRequestID& id, | 528 void RegisterResourceMessageDelegate(const GlobalRequestID& id, |
502 ResourceMessageDelegate* delegate); | 529 ResourceMessageDelegate* delegate); |
503 void UnregisterResourceMessageDelegate(const GlobalRequestID& id, | 530 void UnregisterResourceMessageDelegate(const GlobalRequestID& id, |
504 ResourceMessageDelegate* delegate); | 531 ResourceMessageDelegate* delegate); |
505 | 532 |
506 int BuildLoadFlagsForRequest(const ResourceHostMsg_Request& request_data, | 533 int BuildLoadFlagsForRequest(const ResourceHostMsg_Request& request_data, |
507 int child_id, | 534 int child_id, |
508 bool is_sync_load); | 535 bool is_sync_load); |
509 | 536 |
| 537 void BeginAsyncRevalidation(net::URLRequest* for_request); |
| 538 void OnAsyncRevalidationComplete(const AsyncRevalidationKey& key); |
| 539 void CancelAsyncRevalidationsForResourceContext( |
| 540 ResourceContext* resource_context); |
| 541 |
510 LoaderMap pending_loaders_; | 542 LoaderMap pending_loaders_; |
511 | 543 |
512 // Collection of temp files downloaded for child processes via | 544 // Collection of temp files downloaded for child processes via |
513 // the download_to_file mechanism. We avoid deleting them until | 545 // the download_to_file mechanism. We avoid deleting them until |
514 // the client no longer needs them. | 546 // the client no longer needs them. |
515 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > | 547 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > |
516 DeletableFilesMap; // key is request id | 548 DeletableFilesMap; // key is request id |
517 typedef std::map<int, DeletableFilesMap> | 549 typedef std::map<int, DeletableFilesMap> |
518 RegisteredTempFiles; // key is child process id | 550 RegisteredTempFiles; // key is child process id |
519 RegisteredTempFiles registered_temp_files_; | 551 RegisteredTempFiles registered_temp_files_; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 base::TimeTicks last_user_gesture_time_; | 610 base::TimeTicks last_user_gesture_time_; |
579 | 611 |
580 // Used during IPC message dispatching so that the handlers can get a pointer | 612 // Used during IPC message dispatching so that the handlers can get a pointer |
581 // to the source of the message. | 613 // to the source of the message. |
582 ResourceMessageFilter* filter_; | 614 ResourceMessageFilter* filter_; |
583 | 615 |
584 ResourceDispatcherHostDelegate* delegate_; | 616 ResourceDispatcherHostDelegate* delegate_; |
585 | 617 |
586 bool allow_cross_origin_auth_prompt_; | 618 bool allow_cross_origin_auth_prompt_; |
587 | 619 |
| 620 // stale-while-revalidate is enabled either via experiment or command-line |
| 621 // flag. |
| 622 bool async_revalidation_enabled_; |
| 623 |
| 624 // Async revalidations that are currently in-flight: either waiting to be |
| 625 // scheduled or active on the network. |
| 626 AsyncRevalidationMap in_progress_async_revalidations_; |
| 627 |
588 // http://crbug.com/90971 - Assists in tracking down use-after-frees on | 628 // http://crbug.com/90971 - Assists in tracking down use-after-frees on |
589 // shutdown. | 629 // shutdown. |
590 std::set<const ResourceContext*> active_resource_contexts_; | 630 std::set<const ResourceContext*> active_resource_contexts_; |
591 | 631 |
592 typedef std::map<GlobalRequestID, | 632 typedef std::map<GlobalRequestID, |
593 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 633 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
594 DelegateMap delegate_map_; | 634 DelegateMap delegate_map_; |
595 | 635 |
596 scoped_ptr<ResourceScheduler> scheduler_; | 636 scoped_ptr<ResourceScheduler> scheduler_; |
597 | 637 |
598 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 638 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
599 }; | 639 }; |
600 | 640 |
601 } // namespace content | 641 } // namespace content |
602 | 642 |
603 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 643 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |