• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/public/browser/resource_throttle.h"
12 
13 namespace net {
14 class URLRequest;
15 }
16 
17 namespace prerender {
18 
19 class PrerenderTracker;
20 
21 // This class implements policy on resource requests in prerenders.  It cancels
22 // prerenders on certain requests.  It also defers certain requests until after
23 // the prerender is swapped in.
24 //
25 // TODO(davidben): Experiment with deferring network requests that
26 // would otherwise cancel the prerender.
27 class PrerenderResourceThrottle
28     : public content::ResourceThrottle,
29       public base::SupportsWeakPtr<PrerenderResourceThrottle> {
30  public:
31   PrerenderResourceThrottle(net::URLRequest* request,
32                             PrerenderTracker* tracker);
33 
34   // content::ResourceThrottle implementation:
35   virtual void WillStartRequest(bool* defer) OVERRIDE;
36   virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE;
37   virtual const char* GetNameForLogging() const OVERRIDE;
38 
39   // Called by the PrerenderTracker when a prerender becomes visible.
40   // May only be called if currently throttling the resource.
41   void Resume();
42 
43   // Called by the PrerenderTracker when a prerender is destroyed.
44   // May only be called if currently throttling the resource.
45   void Cancel();
46 
47  private:
48   net::URLRequest* request_;
49   PrerenderTracker* tracker_;
50   bool throttled_;
51 
52   DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle);
53 };
54 
55 }  // namespace prerender
56 
57 #endif  // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_
58