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_
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 #include "content/public/common/resource_type.h"
19 class PrerenderContents
;
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.
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
> {
31 explicit PrerenderResourceThrottle(net::URLRequest
* request
);
33 // content::ResourceThrottle implementation:
34 void WillStartRequest(bool* defer
) override
;
35 void WillRedirectRequest(const net::RedirectInfo
& redirect_info
,
36 bool* defer
) override
;
37 const char* GetNameForLogging() const override
;
39 // Called by the PrerenderContents when a prerender becomes visible.
40 // May only be called if currently throttling the resource.
43 static void OverridePrerenderContentsForTesting(PrerenderContents
* contents
);
46 // Helper method to cancel the request. May only be called if currently
47 // throttling the resource.
50 static void WillStartRequestOnUI(
51 const base::WeakPtr
<PrerenderResourceThrottle
>& throttle
,
52 const std::string
& method
,
53 content::ResourceType resource_type
,
54 int render_process_id
,
58 static void WillRedirectRequestOnUI(
59 const base::WeakPtr
<PrerenderResourceThrottle
>& throttle
,
60 const std::string
& follow_only_when_prerender_shown_header
,
61 content::ResourceType resource_type
,
63 int render_process_id
,
67 // Helper to return the PrerenderContents given a render frame id. May return
69 static PrerenderContents
* PrerenderContentsFromRenderFrame(
70 int render_process_id
, int render_frame_id
);
72 net::URLRequest
* request_
;
74 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle
);
77 } // namespace prerender
79 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_