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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/resource_throttle.h"
13 #include "content/public/common/resource_type.h"
22 class PrerenderContents
;
24 // This class implements policy on resource requests in prerenders. It cancels
25 // prerenders on certain requests. It also defers certain requests until after
26 // the prerender is swapped in.
28 // TODO(davidben): Experiment with deferring network requests that
29 // would otherwise cancel the prerender.
30 class PrerenderResourceThrottle
31 : public content::ResourceThrottle
,
32 public base::SupportsWeakPtr
<PrerenderResourceThrottle
> {
34 explicit PrerenderResourceThrottle(net::URLRequest
* request
);
36 // content::ResourceThrottle implementation:
37 void WillStartRequest(bool* defer
) override
;
38 void WillRedirectRequest(const net::RedirectInfo
& redirect_info
,
39 bool* defer
) override
;
40 const char* GetNameForLogging() const override
;
42 // Called by the PrerenderContents when a prerender becomes visible.
43 // May only be called if currently throttling the resource.
46 static void OverridePrerenderContentsForTesting(PrerenderContents
* contents
);
49 // Helper method to cancel the request. May only be called if currently
50 // throttling the resource.
53 static void WillStartRequestOnUI(
54 const base::WeakPtr
<PrerenderResourceThrottle
>& throttle
,
55 const std::string
& method
,
56 content::ResourceType resource_type
,
57 int render_process_id
,
61 static void WillRedirectRequestOnUI(
62 const base::WeakPtr
<PrerenderResourceThrottle
>& throttle
,
63 const std::string
& follow_only_when_prerender_shown_header
,
64 content::ResourceType resource_type
,
66 int render_process_id
,
70 // Helper to return the PrerenderContents given a render frame id. May return
72 static PrerenderContents
* PrerenderContentsFromRenderFrame(
73 int render_process_id
, int render_frame_id
);
75 net::URLRequest
* request_
;
77 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle
);
80 } // namespace prerender
82 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_