| 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 DownloadResourceThrottle(DownloadRequestLimiter* limiter, | 25 DownloadResourceThrottle(scoped_refptr<DownloadRequestLimiter> limiter, |
| 26 int render_process_id, | 26 int render_process_id, |
| 27 int render_view_id, | 27 int render_view_id, |
| 28 const GURL& url, | 28 const GURL& url, |
| 29 const std::string& request_method); | 29 const std::string& request_method); |
| 30 | 30 |
| 31 // content::ResourceThrottle implementation: | 31 // content::ResourceThrottle implementation: |
| 32 void WillStartRequest(bool* defer) override; | 32 void WillStartRequest(bool* defer) override; |
| 33 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 33 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 34 bool* defer) override; | 34 bool* defer) override; |
| 35 void WillProcessResponse(bool* defer) override; | 35 void WillProcessResponse(bool* defer) override; |
| 36 const char* GetNameForLogging() const override; | 36 const char* GetNameForLogging() const override; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 ~DownloadResourceThrottle() override; | 39 ~DownloadResourceThrottle() override; |
| 40 | 40 |
| 41 void FileAccessPermissionGranted( |
| 42 scoped_refptr<DownloadRequestLimiter> limiter, |
| 43 int render_process_id, |
| 44 int render_view_id, |
| 45 const GURL& url, |
| 46 const std::string& request_method, |
| 47 bool granted); |
| 41 void WillDownload(bool* defer); | 48 void WillDownload(bool* defer); |
| 42 void ContinueDownload(bool allow); | 49 void ContinueDownload(bool allow); |
| 43 | 50 |
| 44 // Set to true when we are querying the DownloadRequestLimiter. | 51 // Set to true when we are querying the DownloadRequestLimiter. |
| 45 bool querying_limiter_; | 52 bool querying_limiter_; |
| 46 | 53 |
| 47 // Set to true when we know that the request is allowed to start. | 54 // Set to true when we know that the request is allowed to start. |
| 48 bool request_allowed_; | 55 bool request_allowed_; |
| 49 | 56 |
| 50 // Set to true when we have deferred the request. | 57 // Set to true when we have deferred the request. |
| 51 bool request_deferred_; | 58 bool request_deferred_; |
| 52 | 59 |
| 53 DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle); | 60 DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle); |
| 54 }; | 61 }; |
| 55 | 62 |
| 56 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ | 63 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ |
| OLD | NEW |