Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_resource_throttle.h
blobf8a2c25501933b820a027707d5eed88f90a1003c
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 <string>
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"
15 class GURL;
17 namespace net {
18 class URLRequest;
21 namespace prerender {
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> {
33 public:
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.
44 void Resume();
46 static void OverridePrerenderContentsForTesting(PrerenderContents* contents);
48 private:
49 // Helper method to cancel the request. May only be called if currently
50 // throttling the resource.
51 void Cancel();
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,
58 int render_frame_id,
59 const GURL& url);
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,
65 bool async,
66 int render_process_id,
67 int render_frame_id,
68 const GURL& new_url);
70 // Helper to return the PrerenderContents given a render frame id. May return
71 // NULL if it's gone.
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_