| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 fowards the messages from the | 7 // dispatches them to URLRequests. It then fowards 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 public ChildProcessInfo { | 59 public ChildProcessInfo { |
| 60 public: | 60 public: |
| 61 // Return the URLRequestContext for the given request. | 61 // Return the URLRequestContext for the given request. |
| 62 // If NULL is returned, the default context for the profile is used. | 62 // If NULL is returned, the default context for the profile is used. |
| 63 virtual URLRequestContext* GetRequestContext( | 63 virtual URLRequestContext* GetRequestContext( |
| 64 uint32 request_id, | 64 uint32 request_id, |
| 65 const ViewHostMsg_Resource_Request& request_data) = 0; | 65 const ViewHostMsg_Resource_Request& request_data) = 0; |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 explicit Receiver(ChildProcessInfo::ProcessType type) | 68 explicit Receiver(ChildProcessInfo::ProcessType type) |
| 69 : ChildProcessInfo(type) { } | 69 : ChildProcessInfo(type) {} |
| 70 virtual ~Receiver() { } | 70 virtual ~Receiver() {} |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Holds the data we would like to associate with each request | 73 // Holds the data we would like to associate with each request |
| 74 class ExtraRequestInfo : public URLRequest::UserData { | 74 class ExtraRequestInfo : public URLRequest::UserData { |
| 75 friend class ResourceDispatcherHost; | 75 friend class ResourceDispatcherHost; |
| 76 public: | 76 public: |
| 77 ExtraRequestInfo(ResourceHandler* handler, | 77 ExtraRequestInfo(ResourceHandler* handler, |
| 78 ChildProcessInfo::ProcessType process_type, | 78 ChildProcessInfo::ProcessType process_type, |
| 79 int process_id, | 79 int process_id, |
| 80 int route_id, | 80 int route_id, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // Whether this request has started reading any bytes from the response | 176 // Whether this request has started reading any bytes from the response |
| 177 // yet. Will be true after the first (unpaused) call to Read. | 177 // yet. Will be true after the first (unpaused) call to Read. |
| 178 bool has_started_reading; | 178 bool has_started_reading; |
| 179 | 179 |
| 180 // How many bytes have been read while this request has been paused. | 180 // How many bytes have been read while this request has been paused. |
| 181 int paused_read_bytes; | 181 int paused_read_bytes; |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 class Observer { | 184 class Observer { |
| 185 public: | 185 public: |
| 186 virtual ~Observer() { } | 186 virtual ~Observer() {} |
| 187 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, | 187 virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, |
| 188 URLRequest* request) = 0; | 188 URLRequest* request) = 0; |
| 189 virtual void OnResponseCompleted( | 189 virtual void OnResponseCompleted( |
| 190 ResourceDispatcherHost* resource_dispatcher, | 190 ResourceDispatcherHost* resource_dispatcher, |
| 191 URLRequest* request) = 0; | 191 URLRequest* request) = 0; |
| 192 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, | 192 virtual void OnReceivedRedirect(ResourceDispatcherHost* resource_dispatcher, |
| 193 URLRequest* request, | 193 URLRequest* request, |
| 194 const GURL& new_url) = 0; | 194 const GURL& new_url) = 0; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 // Uniquely identifies a URLRequest. | 197 // Uniquely identifies a URLRequest. |
| 198 struct GlobalRequestID { | 198 struct GlobalRequestID { |
| 199 GlobalRequestID() : process_id(-1), request_id(-1) { | 199 GlobalRequestID() : process_id(-1), request_id(-1) { |
| 200 } | 200 } |
| 201 GlobalRequestID(int process_id, int request_id) | 201 GlobalRequestID(int process_id, int request_id) |
| 202 : process_id(process_id), request_id(request_id) { } | 202 : process_id(process_id), request_id(request_id) { |
| 203 } |
| 203 | 204 |
| 204 int process_id; | 205 int process_id; |
| 205 int request_id; | 206 int request_id; |
| 206 | 207 |
| 207 bool operator<(const GlobalRequestID& other) const { | 208 bool operator<(const GlobalRequestID& other) const { |
| 208 if (process_id == other.process_id) | 209 if (process_id == other.process_id) |
| 209 return request_id < other.request_id; | 210 return request_id < other.request_id; |
| 210 return process_id < other.process_id; | 211 return process_id < other.process_id; |
| 211 } | 212 } |
| 212 }; | 213 }; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 void ResumeRequest(const GlobalRequestID& request_id); | 412 void ResumeRequest(const GlobalRequestID& request_id); |
| 412 | 413 |
| 413 // Reads data from the response using our internal buffer as async IO. | 414 // Reads data from the response using our internal buffer as async IO. |
| 414 // Returns true if data is available immediately, false otherwise. If the | 415 // Returns true if data is available immediately, false otherwise. If the |
| 415 // return value is false, we will receive a OnReadComplete() callback later. | 416 // return value is false, we will receive a OnReadComplete() callback later. |
| 416 bool Read(URLRequest* request, int* bytes_read); | 417 bool Read(URLRequest* request, int* bytes_read); |
| 417 | 418 |
| 418 // Internal function to finish an async IO which has completed. Returns | 419 // Internal function to finish an async IO which has completed. Returns |
| 419 // true if there is more data to read (e.g. we haven't read EOF yet and | 420 // true if there is more data to read (e.g. we haven't read EOF yet and |
| 420 // no errors have occurred). | 421 // no errors have occurred). |
| 421 bool CompleteRead(URLRequest *, int* bytes_read); | 422 bool CompleteRead(URLRequest*, int* bytes_read); |
| 422 | 423 |
| 423 // Internal function to finish handling the ResponseStarted message. Returns | 424 // Internal function to finish handling the ResponseStarted message. Returns |
| 424 // true on success. | 425 // true on success. |
| 425 bool CompleteResponseStarted(URLRequest* request); | 426 bool CompleteResponseStarted(URLRequest* request); |
| 426 | 427 |
| 427 // Cancels the given request if it still exists. We ignore cancels from the | 428 // Cancels the given request if it still exists. We ignore cancels from the |
| 428 // renderer in the event of a download. If |allow_delete| is true and no IO | 429 // renderer in the event of a download. If |allow_delete| is true and no IO |
| 429 // is pending, the request is removed and deleted. | 430 // is pending, the request is removed and deleted. |
| 430 void CancelRequest(int process_id, | 431 void CancelRequest(int process_id, |
| 431 int request_id, | 432 int request_id, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 467 |
| 467 // Notify our observers that a request has been redirected. | 468 // Notify our observers that a request has been redirected. |
| 468 void NotifyReceivedRedirect(URLRequest* request, | 469 void NotifyReceivedRedirect(URLRequest* request, |
| 469 int process_id, | 470 int process_id, |
| 470 const GURL& new_url); | 471 const GURL& new_url); |
| 471 | 472 |
| 472 // Tries to handle the url with an external protocol. If the request is | 473 // Tries to handle the url with an external protocol. If the request is |
| 473 // handled, the function returns true. False otherwise. | 474 // handled, the function returns true. False otherwise. |
| 474 bool HandleExternalProtocol(int request_id, | 475 bool HandleExternalProtocol(int request_id, |
| 475 int process_id, | 476 int process_id, |
| 476 int tab_contents_id, | 477 int route_id, |
| 477 const GURL& url, | 478 const GURL& url, |
| 478 ResourceType::Type resource_type, | 479 ResourceType::Type resource_type, |
| 479 ResourceHandler* handler); | 480 ResourceHandler* handler); |
| 480 | 481 |
| 481 void UpdateLoadStates(); | 482 void UpdateLoadStates(); |
| 482 | 483 |
| 483 void MaybeUpdateUploadProgress(ExtraRequestInfo *info, URLRequest *request); | 484 void MaybeUpdateUploadProgress(ExtraRequestInfo *info, URLRequest *request); |
| 484 | 485 |
| 485 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 486 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 486 void ProcessBlockedRequestsForRoute(int process_id, | 487 void ProcessBlockedRequestsForRoute(int process_id, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // Used during IPC message dispatching so that the handlers can get a pointer | 573 // Used during IPC message dispatching so that the handlers can get a pointer |
| 573 // to the source of the message. | 574 // to the source of the message. |
| 574 Receiver* receiver_; | 575 Receiver* receiver_; |
| 575 | 576 |
| 576 static bool g_is_http_prioritization_enabled; | 577 static bool g_is_http_prioritization_enabled; |
| 577 | 578 |
| 578 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); | 579 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); |
| 579 }; | 580 }; |
| 580 | 581 |
| 581 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 582 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| OLD | NEW |