Home | History | Annotate | Download | only in download
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_
      6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_
      7 
      8 #include "base/memory/weak_ptr.h"
      9 #include "chrome/browser/download/download_request_limiter.h"
     10 #include "content/public/browser/resource_throttle.h"
     11 
     12 class GURL;
     13 
     14 // DownloadResourceThrottle is used to determine if a download should be
     15 // allowed. When a DownloadResourceThrottle is created it pauses the download
     16 // and asks the DownloadRequestLimiter if the download should be allowed. The
     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
     19 // the download is not allowed the request is canceled.
     20 
     21 class DownloadResourceThrottle
     22     : public content::ResourceThrottle,
     23       public base::SupportsWeakPtr<DownloadResourceThrottle> {
     24  public:
     25   DownloadResourceThrottle(DownloadRequestLimiter* limiter,
     26                            int render_process_id,
     27                            int render_view_id,
     28                            int request_id,
     29                            const std::string& request_method);
     30 
     31   // content::ResourceThrottle implementation:
     32   virtual void WillStartRequest(bool* defer) OVERRIDE;
     33   virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE;
     34   virtual void WillProcessResponse(bool* defer) OVERRIDE;
     35 
     36  private:
     37   virtual ~DownloadResourceThrottle();
     38 
     39   void WillDownload(bool* defer);
     40   void ContinueDownload(bool allow);
     41 
     42   // Set to true when we are querying the DownloadRequestLimiter.
     43   bool querying_limiter_;
     44 
     45   // Set to true when we know that the request is allowed to start.
     46   bool request_allowed_;
     47 
     48   // Set to true when we have deferred the request.
     49   bool request_deferred_;
     50 
     51   DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle);
     52 };
     53 
     54 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_
     55