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 #ifndef CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/download/download_request_limiter.h" | 11 #include "chrome/browser/download/download_request_limiter.h" |
12 #include "chrome/browser/renderer_host/resource_handler.h" | 12 #include "chrome/browser/renderer_host/resource_handler.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 | 14 |
15 class DownloadResourceHandler; | 15 class DownloadResourceHandler; |
16 class ResourceDispatcherHost; | 16 class ResourceDispatcherHost; |
| 17 |
| 18 namespace net { |
17 class URLRequest; | 19 class URLRequest; |
| 20 } // namespace net |
18 | 21 |
19 // DownloadThrottlingResourceHandler is used to determine if a download should | 22 // DownloadThrottlingResourceHandler is used to determine if a download should |
20 // be allowed. When a DownloadThrottlingResourceHandler is created it pauses the | 23 // be allowed. When a DownloadThrottlingResourceHandler is created it pauses the |
21 // download and asks the DownloadRequestLimiter if the download should be | 24 // download and asks the DownloadRequestLimiter if the download should be |
22 // allowed. The DownloadRequestLimiter notifies us asynchronously as to whether | 25 // allowed. The DownloadRequestLimiter notifies us asynchronously as to whether |
23 // the download is allowed or not. If the download is allowed the request is | 26 // the download is allowed or not. If the download is allowed the request is |
24 // resumed, a DownloadResourceHandler is created and all EventHandler methods | 27 // resumed, a DownloadResourceHandler is created and all EventHandler methods |
25 // are delegated to it. If the download is not allowed the request is canceled. | 28 // are delegated to it. If the download is not allowed the request is canceled. |
26 | 29 |
27 class DownloadThrottlingResourceHandler | 30 class DownloadThrottlingResourceHandler |
28 : public ResourceHandler, | 31 : public ResourceHandler, |
29 public DownloadRequestLimiter::Callback { | 32 public DownloadRequestLimiter::Callback { |
30 public: | 33 public: |
31 DownloadThrottlingResourceHandler(ResourceDispatcherHost* host, | 34 DownloadThrottlingResourceHandler(ResourceDispatcherHost* host, |
32 URLRequest* request, | 35 net::URLRequest* request, |
33 const GURL& url, | 36 const GURL& url, |
34 int render_process_host_id, | 37 int render_process_host_id, |
35 int render_view_id, | 38 int render_view_id, |
36 int request_id, | 39 int request_id, |
37 bool in_complete); | 40 bool in_complete); |
38 | 41 |
39 // ResourceHanlder implementation: | 42 // ResourceHanlder implementation: |
40 virtual bool OnUploadProgress(int request_id, | 43 virtual bool OnUploadProgress(int request_id, |
41 uint64 position, | 44 uint64 position, |
42 uint64 size); | 45 uint64 size); |
(...skipping 13 matching lines...) Expand all Loading... |
56 virtual void CancelDownload(); | 59 virtual void CancelDownload(); |
57 virtual void ContinueDownload(); | 60 virtual void ContinueDownload(); |
58 virtual int GetRequestId(); | 61 virtual int GetRequestId(); |
59 | 62 |
60 private: | 63 private: |
61 virtual ~DownloadThrottlingResourceHandler(); | 64 virtual ~DownloadThrottlingResourceHandler(); |
62 | 65 |
63 void CopyTmpBufferToDownloadHandler(); | 66 void CopyTmpBufferToDownloadHandler(); |
64 | 67 |
65 ResourceDispatcherHost* host_; | 68 ResourceDispatcherHost* host_; |
66 URLRequest* request_; | 69 net::URLRequest* request_; |
67 GURL url_; | 70 GURL url_; |
68 int render_process_host_id_; | 71 int render_process_host_id_; |
69 int render_view_id_; | 72 int render_view_id_; |
70 int request_id_; | 73 int request_id_; |
71 | 74 |
72 // Handles the actual download. This is only created if the download is | 75 // Handles the actual download. This is only created if the download is |
73 // allowed to continue. | 76 // allowed to continue. |
74 scoped_refptr<DownloadResourceHandler> download_handler_; | 77 scoped_refptr<DownloadResourceHandler> download_handler_; |
75 | 78 |
76 // Response supplied to OnResponseStarted. Only non-null if OnResponseStarted | 79 // Response supplied to OnResponseStarted. Only non-null if OnResponseStarted |
77 // is invoked. | 80 // is invoked. |
78 scoped_refptr<ResourceResponse> response_; | 81 scoped_refptr<ResourceResponse> response_; |
79 | 82 |
80 // If we're created by way of BufferedEventHandler we'll get one request for | 83 // If we're created by way of BufferedEventHandler we'll get one request for |
81 // a buffer. This is that buffer. | 84 // a buffer. This is that buffer. |
82 scoped_refptr<net::IOBuffer> tmp_buffer_; | 85 scoped_refptr<net::IOBuffer> tmp_buffer_; |
83 int tmp_buffer_length_; | 86 int tmp_buffer_length_; |
84 | 87 |
85 // If true the next call to OnReadCompleted is ignored. This is used if we're | 88 // If true the next call to OnReadCompleted is ignored. This is used if we're |
86 // paused during a call to OnReadCompleted. Pausing during OnReadCompleted | 89 // paused during a call to OnReadCompleted. Pausing during OnReadCompleted |
87 // results in two calls to OnReadCompleted for the same data. This make sure | 90 // results in two calls to OnReadCompleted for the same data. This make sure |
88 // we ignore one of them. | 91 // we ignore one of them. |
89 bool ignore_on_read_complete_; | 92 bool ignore_on_read_complete_; |
90 | 93 |
91 DISALLOW_COPY_AND_ASSIGN(DownloadThrottlingResourceHandler); | 94 DISALLOW_COPY_AND_ASSIGN(DownloadThrottlingResourceHandler); |
92 }; | 95 }; |
93 | 96 |
94 #endif // CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ | 97 #endif // CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ |
OLD | NEW |