| 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "chrome/browser/download/download_request_limiter.h" | 9 #include "chrome/browser/download/download_request_limiter.h" |
| 10 #include "content/public/browser/resource_throttle.h" | 10 #include "content/public/browser/resource_throttle.h" |
| 11 | 11 |
| 12 class GURL; | 12 class GURL; |
| 13 | 13 |
| 14 // DownloadResourceThrottle is used to determine if a download should be | 14 // DownloadResourceThrottle is used to determine if a download should be |
| 15 // allowed. When a DownloadResourceThrottle is created it pauses the download | 15 // allowed. When a DownloadResourceThrottle is created it pauses the download |
| 16 // and asks the DownloadRequestLimiter if the download should be allowed. The | 16 // and asks the DownloadRequestLimiter if the download should be allowed. The |
| 17 // DownloadRequestLimiter notifies us asynchronously as to whether the download | 17 // DownloadRequestLimiter notifies us asynchronously as to whether the download |
| 18 // is allowed or not. If the download is allowed the request is resumed. If | 18 // is allowed or not. If the download is allowed the request is resumed. If |
| 19 // the download is not allowed the request is canceled. | 19 // the download is not allowed the request is canceled. |
| 20 | 20 |
| 21 class DownloadResourceThrottle | 21 class DownloadResourceThrottle |
| 22 : public content::ResourceThrottle, | 22 : public content::ResourceThrottle, |
| 23 public base::SupportsWeakPtr<DownloadResourceThrottle> { | 23 public base::SupportsWeakPtr<DownloadResourceThrottle> { |
| 24 public: | 24 public: |
| 25 // Information passed between callbacks to check whether download can proceed. | 25 // Information passed between callbacks to check whether download can proceed. |
| 26 struct DownloadRequestInfo { | 26 struct DownloadRequestInfo { |
| 27 DownloadRequestInfo( | 27 DownloadRequestInfo( |
| 28 scoped_refptr<DownloadRequestLimiter> limiter, | 28 scoped_refptr<DownloadRequestLimiter> limiter, |
| 29 int render_process_id, | 29 const content::ResourceRequestInfo::WebContentsGetter& |
| 30 int render_view_id, | 30 web_contents_getter, |
| 31 const GURL& url, | 31 const GURL& url, |
| 32 const std::string& request_method, | 32 const std::string& request_method, |
| 33 const DownloadRequestLimiter::Callback& continue_callback); | 33 const DownloadRequestLimiter::Callback& continue_callback); |
| 34 ~DownloadRequestInfo(); | 34 ~DownloadRequestInfo(); |
| 35 | 35 |
| 36 scoped_refptr<DownloadRequestLimiter> limiter; | 36 scoped_refptr<DownloadRequestLimiter> limiter; |
| 37 int render_process_id; | 37 content::ResourceRequestInfo::WebContentsGetter web_contents_getter; |
| 38 int render_view_id; | |
| 39 GURL url; | 38 GURL url; |
| 40 std::string request_method; | 39 std::string request_method; |
| 41 DownloadRequestLimiter::Callback continue_callback; | 40 DownloadRequestLimiter::Callback continue_callback; |
| 42 private: | 41 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfo); | 42 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfo); |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 DownloadResourceThrottle(scoped_refptr<DownloadRequestLimiter> limiter, | 45 DownloadResourceThrottle( |
| 47 int render_process_id, | 46 scoped_refptr<DownloadRequestLimiter> limiter, |
| 48 int render_view_id, | 47 const content::ResourceRequestInfo::WebContentsGetter& |
| 49 const GURL& url, | 48 web_contents_getter, |
| 50 const std::string& request_method); | 49 const GURL& url, |
| 50 const std::string& request_method); |
| 51 | 51 |
| 52 // content::ResourceThrottle implementation: | 52 // content::ResourceThrottle implementation: |
| 53 void WillStartRequest(bool* defer) override; | 53 void WillStartRequest(bool* defer) override; |
| 54 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 54 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 55 bool* defer) override; | 55 bool* defer) override; |
| 56 void WillProcessResponse(bool* defer) override; | 56 void WillProcessResponse(bool* defer) override; |
| 57 const char* GetNameForLogging() const override; | 57 const char* GetNameForLogging() const override; |
| 58 | 58 |
| 59 void ContinueDownload(bool allow); | 59 void ContinueDownload(bool allow); |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 ~DownloadResourceThrottle() override; | 62 ~DownloadResourceThrottle() override; |
| 63 | 63 |
| 64 void WillDownload(bool* defer); | 64 void WillDownload(bool* defer); |
| 65 | 65 |
| 66 // Set to true when we are querying the DownloadRequestLimiter. | 66 // Set to true when we are querying the DownloadRequestLimiter. |
| 67 bool querying_limiter_; | 67 bool querying_limiter_; |
| 68 | 68 |
| 69 // Set to true when we know that the request is allowed to start. | 69 // Set to true when we know that the request is allowed to start. |
| 70 bool request_allowed_; | 70 bool request_allowed_; |
| 71 | 71 |
| 72 // Set to true when we have deferred the request. | 72 // Set to true when we have deferred the request. |
| 73 bool request_deferred_; | 73 bool request_deferred_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle); | 75 DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ | 78 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ |
| OLD | NEW |