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

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

Issue 3127008: Preliminary work on resuming downloads whose connections have expired.
Patch Set: Waiting to send download automation error message until after other downloads are canceled. Created 10 years, 3 months 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
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
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 #pragma once 14 #pragma once
15 15
16 #include <map> 16 #include <map>
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/observer_list.h" 22 #include "base/observer_list.h"
23 #include "base/scoped_ptr.h" 23 #include "base/scoped_ptr.h"
24 #include "base/timer.h" 24 #include "base/timer.h"
25 #include "chrome/common/child_process_info.h" 25 #include "chrome/common/child_process_info.h"
26 #include "chrome/browser/renderer_host/global_request_id.h"
26 #include "chrome/browser/renderer_host/resource_queue.h" 27 #include "chrome/browser/renderer_host/resource_queue.h"
27 #include "ipc/ipc_message.h" 28 #include "ipc/ipc_message.h"
28 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
29 #include "webkit/glue/resource_type.h" 30 #include "webkit/glue/resource_type.h"
30 31
31 class CrossSiteResourceHandler; 32 class CrossSiteResourceHandler;
32 class DownloadFileManager; 33 class DownloadFileManager;
33 class DownloadRequestLimiter; 34 class DownloadRequestLimiter;
34 class LoginHandler; 35 class LoginHandler;
35 class PluginService; 36 class PluginService;
36 class ResourceDispatcherHostRequestInfo; 37 class ResourceDispatcherHostRequestInfo;
37 class ResourceHandler; 38 class ResourceHandler;
38 class SafeBrowsingService; 39 class SafeBrowsingService;
39 class SaveFileManager; 40 class SaveFileManager;
40 class SocketStreamDispatcherHost; 41 class SocketStreamDispatcherHost;
41 class SSLClientAuthHandler; 42 class SSLClientAuthHandler;
42 class UserScriptListener; 43 class UserScriptListener;
43 class URLRequestContext; 44 class URLRequestContext;
44 class WebKitThread; 45 class WebKitThread;
46 struct DownloadCreateInfo;
45 struct DownloadSaveInfo; 47 struct DownloadSaveInfo;
46 struct GlobalRequestID;
47 struct ViewHostMsg_Resource_Request; 48 struct ViewHostMsg_Resource_Request;
48 struct ViewMsg_ClosePage_Params; 49 struct ViewMsg_ClosePage_Params;
49 50
50 class ResourceDispatcherHost : public URLRequest::Delegate { 51 class ResourceDispatcherHost : public URLRequest::Delegate {
51 public: 52 public:
52 // Implemented by the client of ResourceDispatcherHost to receive messages in 53 // Implemented by the client of ResourceDispatcherHost to receive messages in
53 // response to a resource load. The messages are intended to be forwarded to 54 // response to a resource load. The messages are intended to be forwarded to
54 // the ResourceDispatcher in the child process via an IPC channel that the 55 // the ResourceDispatcher in the child process via an IPC channel that the
55 // client manages. 56 // client manages.
56 // 57 //
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 bool* message_was_ok); 105 bool* message_was_ok);
105 106
106 // Initiates a download from the browser process (as opposed to a resource 107 // Initiates a download from the browser process (as opposed to a resource
107 // request from the renderer or another child process). 108 // request from the renderer or another child process).
108 void BeginDownload(const GURL& url, 109 void BeginDownload(const GURL& url,
109 const GURL& referrer, 110 const GURL& referrer,
110 const DownloadSaveInfo& save_info, 111 const DownloadSaveInfo& save_info,
111 bool prompt_for_save_location, 112 bool prompt_for_save_location,
112 int process_unique_id, 113 int process_unique_id,
113 int route_id, 114 int route_id,
114 URLRequestContext* request_context); 115 URLRequestContext* request_context,
116 uint64 start_offset);
115 117
116 // Initiates a save file from the browser process (as opposed to a resource 118 // Initiates a save file from the browser process (as opposed to a resource
117 // request from the renderer or another child process). 119 // request from the renderer or another child process).
118 void BeginSaveFile(const GURL& url, 120 void BeginSaveFile(const GURL& url,
119 const GURL& referrer, 121 const GURL& referrer,
120 int process_unique_id, 122 int process_unique_id,
121 int route_id, 123 int route_id,
122 URLRequestContext* request_context); 124 URLRequestContext* request_context);
123 125
124 // Cancels the given request if it still exists. We ignore cancels from the 126 // Cancels the given request if it still exists. We ignore cancels from the
(...skipping 18 matching lines...) Expand all
143 void StartDeferredRequest(int process_unique_id, int request_id); 145 void StartDeferredRequest(int process_unique_id, int request_id);
144 146
145 // Returns true if it's ok to send the data. If there are already too many 147 // Returns true if it's ok to send the data. If there are already too many
146 // data messages pending, it pauses the request and returns false. In this 148 // data messages pending, it pauses the request and returns false. In this
147 // case the caller should not send the data. 149 // case the caller should not send the data.
148 bool WillSendData(int process_unique_id, int request_id); 150 bool WillSendData(int process_unique_id, int request_id);
149 151
150 // Pauses or resumes network activity for a particular request. 152 // Pauses or resumes network activity for a particular request.
151 void PauseRequest(int process_unique_id, int request_id, bool pause); 153 void PauseRequest(int process_unique_id, int request_id, bool pause);
152 154
155 // Restarts network activity for a particular request.
156 void RestartRequest(int process_unique_id,
157 int request_id,
158 DownloadCreateInfo* info);
159
153 // Returns the number of pending requests. This is designed for the unittests 160 // Returns the number of pending requests. This is designed for the unittests
154 int pending_requests() const { 161 int pending_request_count() const {
155 return static_cast<int>(pending_requests_.size()); 162 return static_cast<int>(pending_requests_.size());
156 } 163 }
157 164
165 int interrupted_request_count() const {
166 return static_cast<int>(interrupted_requests_.size());
167 }
168
158 // Intended for unit-tests only. Returns the memory cost of all the 169 // Intended for unit-tests only. Returns the memory cost of all the
159 // outstanding requests (pending and blocked) for |process_unique_id|. 170 // outstanding requests (pending and blocked) for |process_unique_id|.
160 int GetOutstandingRequestsMemoryCost(int process_unique_id) const; 171 int GetOutstandingRequestsMemoryCost(int process_unique_id) const;
161 172
162 // Intended for unit-tests only. Overrides the outstanding requests bound. 173 // Intended for unit-tests only. Overrides the outstanding requests bound.
163 void set_max_outstanding_requests_cost_per_process(int limit) { 174 void set_max_outstanding_requests_cost_per_process(int limit) {
164 max_outstanding_requests_cost_per_process_ = limit; 175 max_outstanding_requests_cost_per_process_ = limit;
165 } 176 }
166 177
167 // The average private bytes increase of the browser for each new pending 178 // The average private bytes increase of the browser for each new pending
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Removes an observer. 250 // Removes an observer.
240 void RemoveObserver(Observer* obs); 251 void RemoveObserver(Observer* obs);
241 252
242 // Retrieves a URLRequest. Must be called from the IO thread. 253 // Retrieves a URLRequest. Must be called from the IO thread.
243 URLRequest* GetURLRequest(const GlobalRequestID& request_id) const; 254 URLRequest* GetURLRequest(const GlobalRequestID& request_id) const;
244 255
245 // Notifies our observers that a request has been cancelled. 256 // Notifies our observers that a request has been cancelled.
246 void NotifyResponseCompleted(URLRequest* request, int process_unique_id); 257 void NotifyResponseCompleted(URLRequest* request, int process_unique_id);
247 258
248 void RemovePendingRequest(int process_unique_id, int request_id); 259 void RemovePendingRequest(int process_unique_id, int request_id);
260 void RemoveInterruptedRequest(int process_unique_id, int request_id);
261 void MovePendingRequestToInterrupted(int process_unique_id, int request_id);
262 void MoveInterruptedRequestToPending(int process_unique_id, int request_id);
249 263
250 // Causes all new requests for the route identified by 264 // Causes all new requests for the route identified by
251 // |process_unique_id| and |route_id| to be blocked (not being 265 // |process_unique_id| and |route_id| to be blocked (not being
252 // started) until ResumeBlockedRequestsForRoute or 266 // started) until ResumeBlockedRequestsForRoute or
253 // CancelBlockedRequestsForRoute is called. 267 // CancelBlockedRequestsForRoute is called.
254 void BlockRequestsForRoute(int process_unique_id, int route_id); 268 void BlockRequestsForRoute(int process_unique_id, int route_id);
255 269
256 // Resumes any blocked request for the specified route id. 270 // Resumes any blocked request for the specified route id.
257 void ResumeBlockedRequestsForRoute(int process_unique_id, int route_id); 271 void ResumeBlockedRequestsForRoute(int process_unique_id, int route_id);
258 272
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 309
296 // A shutdown helper that runs on the IO thread. 310 // A shutdown helper that runs on the IO thread.
297 void OnShutdown(); 311 void OnShutdown();
298 312
299 // Returns true if the request is paused. 313 // Returns true if the request is paused.
300 bool PauseRequestIfNeeded(ResourceDispatcherHostRequestInfo* info); 314 bool PauseRequestIfNeeded(ResourceDispatcherHostRequestInfo* info);
301 315
302 // Resumes the given request by calling OnResponseStarted or OnReadCompleted. 316 // Resumes the given request by calling OnResponseStarted or OnReadCompleted.
303 void ResumeRequest(const GlobalRequestID& request_id); 317 void ResumeRequest(const GlobalRequestID& request_id);
304 318
319 // Restarts the given request's download operation.
320 static void RestartDownload(ResourceDispatcherHost* rdh,
321 const GlobalRequestID& request_id,
322 DownloadCreateInfo* info);
323
305 // Internal function to start reading for the first time. 324 // Internal function to start reading for the first time.
306 void StartReading(URLRequest* request); 325 void StartReading(URLRequest* request);
307 326
308 // Reads data from the response using our internal buffer as async IO. 327 // Reads data from the response using our internal buffer as async IO.
309 // Returns true if data is available immediately, false otherwise. If the 328 // Returns true if data is available immediately, false otherwise. If the
310 // return value is false, we will receive a OnReadComplete() callback later. 329 // return value is false, we will receive a OnReadComplete() callback later.
311 bool Read(URLRequest* request, int* bytes_read); 330 bool Read(URLRequest* request, int* bytes_read);
312 331
313 // Internal function to finish an async IO which has completed. Returns 332 // Internal function to finish an async IO which has completed. Returns
314 // true if there is more data to read (e.g. we haven't read EOF yet and 333 // true if there is more data to read (e.g. we haven't read EOF yet and
(...skipping 29 matching lines...) Expand all
344 363
345 // The list of all requests that we have pending. This list is not really 364 // The list of all requests that we have pending. This list is not really
346 // optimized, and assumes that we have relatively few requests pending at once 365 // optimized, and assumes that we have relatively few requests pending at once
347 // since some operations require brute-force searching of the list. 366 // since some operations require brute-force searching of the list.
348 // 367 //
349 // It may be enhanced in the future to provide some kind of prioritization 368 // It may be enhanced in the future to provide some kind of prioritization
350 // mechanism. We should also consider a hashtable or binary tree if it turns 369 // mechanism. We should also consider a hashtable or binary tree if it turns
351 // out we have a lot of things here. 370 // out we have a lot of things here.
352 typedef std::map<GlobalRequestID, URLRequest*> PendingRequestList; 371 typedef std::map<GlobalRequestID, URLRequest*> PendingRequestList;
353 372
373 // Accumulates matching requests from the given list.
374 std::vector<GlobalRequestID> GetMatchingRequests(
375 int process_unique_id,
376 int route_id,
377 const PendingRequestList& requests);
378
354 // Deletes the pending request identified by the iterator passed in. 379 // Deletes the pending request identified by the iterator passed in.
355 // This function will invalidate the iterator passed in. Callers should 380 // This function will invalidate the iterator passed in. Callers should
356 // not rely on this iterator being valid on return. 381 // not rely on this iterator being valid on return.
357 void RemovePendingRequest(const PendingRequestList::iterator& iter); 382 void RemoveRequestFromMap(const PendingRequestList::iterator& iter);
358 383
359 // Notify our observers that we started receiving a response for a request. 384 // Notify our observers that we started receiving a response for a request.
360 void NotifyResponseStarted(URLRequest* request, int process_unique_id); 385 void NotifyResponseStarted(URLRequest* request, int process_unique_id);
361 386
362 // Notify our observers that a request has been redirected. 387 // Notify our observers that a request has been redirected.
363 void NotifyReceivedRedirect(URLRequest* request, 388 void NotifyReceivedRedirect(URLRequest* request,
364 int process_unique_id, 389 int process_unique_id,
365 const GURL& new_url); 390 const GURL& new_url);
366 391
367 // Tries to handle the url with an external protocol. If the request is 392 // Tries to handle the url with an external protocol. If the request is
(...skipping 29 matching lines...) Expand all
397 IPC::Message* sync_result, // only valid for sync 422 IPC::Message* sync_result, // only valid for sync
398 int route_id); // only valid for async 423 int route_id); // only valid for async
399 void OnDataReceivedACK(int request_id); 424 void OnDataReceivedACK(int request_id);
400 void OnUploadProgressACK(int request_id); 425 void OnUploadProgressACK(int request_id);
401 void OnCancelRequest(int request_id); 426 void OnCancelRequest(int request_id);
402 void OnFollowRedirect(int request_id, 427 void OnFollowRedirect(int request_id,
403 bool has_new_first_party_for_cookies, 428 bool has_new_first_party_for_cookies,
404 const GURL& new_first_party_for_cookies); 429 const GURL& new_first_party_for_cookies);
405 430
406 ResourceHandler* CreateSafeBrowsingResourceHandler( 431 ResourceHandler* CreateSafeBrowsingResourceHandler(
407 ResourceHandler* handler, int child_id, int route_id, 432 ResourceHandler* handler, int process_unique_id, int route_id,
408 ResourceType::Type resource_type); 433 ResourceType::Type resource_type);
409 434
410 // Creates ResourceDispatcherHostRequestInfo for a browser-initiated request 435 // Creates ResourceDispatcherHostRequestInfo for a browser-initiated request
411 // (a download or a page save). |download| should be true if the request 436 // (a download or a page save). |download| should be true if the request
412 // is a file download. 437 // is a file download.
413 ResourceDispatcherHostRequestInfo* CreateRequestInfoForBrowserRequest( 438 ResourceDispatcherHostRequestInfo* CreateRequestInfoForBrowserRequest(
414 ResourceHandler* handler, int child_id, int route_id, bool download); 439 ResourceHandler* handler,
440 int process_unique_id,
441 int route_id,
442 bool download);
415 443
416 // Returns true if |request| is in |pending_requests_|. 444 // Returns true if |request| is in |pending_requests_| or
445 // |interrupted_requests_|.
417 bool IsValidRequest(URLRequest* request); 446 bool IsValidRequest(URLRequest* request);
418 447
448 // Returns true if |request| is in |interrupted_requests_|.
449 bool IsInterruptedRequest(URLRequest* request);
450
419 // Returns true if the message passed in is a resource related message. 451 // Returns true if the message passed in is a resource related message.
420 static bool IsResourceDispatcherHostMessage(const IPC::Message&); 452 static bool IsResourceDispatcherHostMessage(const IPC::Message&);
421 453
422 // Sets replace_extension_localization_templates on all text/css requests that 454 // Sets replace_extension_localization_templates on all text/css requests that
423 // have "chrome-extension://" scheme. 455 // have "chrome-extension://" scheme.
424 static void ApplyExtensionLocalizationFilter( 456 static void ApplyExtensionLocalizationFilter(
425 const GURL& url, 457 const GURL& url,
426 const ResourceType::Type& resource_type, 458 const ResourceType::Type& resource_type,
427 ResourceDispatcherHostRequestInfo* request_info); 459 ResourceDispatcherHostRequestInfo* request_info);
428 460
429 // Determine request priority based on how critical this resource typically 461 // Determine request priority based on how critical this resource typically
430 // is to user-perceived page load performance. 462 // is to user-perceived page load performance.
431 static net::RequestPriority DetermineRequestPriority(ResourceType::Type type); 463 static net::RequestPriority DetermineRequestPriority(ResourceType::Type type);
432 464
433 PendingRequestList pending_requests_; 465 PendingRequestList pending_requests_;
434 466
467 // This list contains all the interrupted requests.
468 PendingRequestList interrupted_requests_;
469
435 // A timer that periodically calls UpdateLoadStates while pending_requests_ 470 // A timer that periodically calls UpdateLoadStates while pending_requests_
436 // is not empty. 471 // is not empty.
437 base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_; 472 base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_;
438 473
439 // Handles the resource requests from the moment we want to start them. 474 // Handles the resource requests from the moment we want to start them.
440 ResourceQueue resource_queue_; 475 ResourceQueue resource_queue_;
441 476
442 // We own the download file writing thread and manager 477 // We own the download file writing thread and manager
443 scoped_refptr<DownloadFileManager> download_file_manager_; 478 scoped_refptr<DownloadFileManager> download_file_manager_;
444 479
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // Used during IPC message dispatching so that the handlers can get a pointer 532 // Used during IPC message dispatching so that the handlers can get a pointer
498 // to the source of the message. 533 // to the source of the message.
499 Receiver* receiver_; 534 Receiver* receiver_;
500 535
501 static bool is_prefetch_enabled_; 536 static bool is_prefetch_enabled_;
502 537
503 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); 538 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost);
504 }; 539 };
505 540
506 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ 541 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698