OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/common/prerender_types.h" | 13 #include "chrome/common/prerender_types.h" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
15 #include "content/public/browser/resource_throttle.h" | 15 #include "content/public/browser/resource_throttle.h" |
16 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
17 #include "net/base/request_priority.h" | |
17 | 18 |
18 class GURL; | 19 class GURL; |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 class URLRequest; | 22 class URLRequest; |
22 } | 23 } |
23 | 24 |
24 namespace prerender { | 25 namespace prerender { |
25 class PrerenderContents; | 26 class PrerenderContents; |
26 class PrerenderThrottleInfo; | 27 class PrerenderThrottleInfo; |
(...skipping 16 matching lines...) Expand all Loading... | |
43 void WillStartRequest(bool* defer) override; | 44 void WillStartRequest(bool* defer) override; |
44 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 45 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
45 bool* defer) override; | 46 bool* defer) override; |
46 void WillProcessResponse(bool* defer) override; | 47 void WillProcessResponse(bool* defer) override; |
47 const char* GetNameForLogging() const override; | 48 const char* GetNameForLogging() const override; |
48 | 49 |
49 // Called by the PrerenderContents when a prerender becomes visible. | 50 // Called by the PrerenderContents when a prerender becomes visible. |
50 // May only be called if currently throttling the resource. | 51 // May only be called if currently throttling the resource. |
51 void ResumeHandler(); | 52 void ResumeHandler(); |
52 | 53 |
54 // Resets the resource priority back to its original value. | |
55 void ResetResourcePriority(); | |
56 | |
53 static void OverridePrerenderContentsForTesting(PrerenderContents* contents); | 57 static void OverridePrerenderContentsForTesting(PrerenderContents* contents); |
54 | 58 |
55 private: | 59 private: |
56 static void WillStartRequestOnUI( | 60 static void WillStartRequestOnUI( |
57 const base::WeakPtr<PrerenderResourceThrottle>& throttle, | 61 const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
58 const std::string& method, | 62 const std::string& method, |
59 content::ResourceType resource_type, | 63 content::ResourceType resource_type, |
60 const GURL& url, | 64 const GURL& url, |
61 const content::ResourceRequestInfo::WebContentsGetter& | 65 const content::ResourceRequestInfo::WebContentsGetter& |
62 web_contents_getter, | 66 web_contents_getter, |
(...skipping 18 matching lines...) Expand all Loading... | |
81 // Helper to return the PrerenderContents given a WebContentsGetter. May | 85 // Helper to return the PrerenderContents given a WebContentsGetter. May |
82 // return nullptr if it's gone. | 86 // return nullptr if it's gone. |
83 static PrerenderContents* PrerenderContentsFromGetter( | 87 static PrerenderContents* PrerenderContentsFromGetter( |
84 const content::ResourceRequestInfo::WebContentsGetter& | 88 const content::ResourceRequestInfo::WebContentsGetter& |
85 web_contents_getter); | 89 web_contents_getter); |
86 | 90 |
87 // Sets the prerender mode. Must be called before |ResumeHandler()|. | 91 // Sets the prerender mode. Must be called before |ResumeHandler()|. |
88 void SetPrerenderMode(PrerenderMode mode); | 92 void SetPrerenderMode(PrerenderMode mode); |
89 | 93 |
90 net::URLRequest* request_; | 94 net::URLRequest* request_; |
91 int load_flags_; // Load flags to be OR'ed with the existing request flags. | 95 int load_flags_; // Load flags to be OR'ed with the existing request flags. |
Charlie Harrison
2017/04/12 12:37:26
nit: newline below.
droger
2017/04/12 13:20:54
Done.
| |
96 // The throttle changes most request priorities to IDLE during prerendering. | |
97 // The priority is reset back to the original priority when prerendering is | |
98 // finished, unless the original priority is IDLE. | |
99 net::RequestPriority original_request_priority_; | |
92 | 100 |
93 scoped_refptr<PrerenderThrottleInfo> prerender_throttle_info_; | 101 scoped_refptr<PrerenderThrottleInfo> prerender_throttle_info_; |
94 | 102 |
95 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle); | 103 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle); |
96 }; | 104 }; |
97 | 105 |
98 } // namespace prerender | 106 } // namespace prerender |
99 | 107 |
100 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ | 108 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ |
OLD | NEW |