| 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 "base/optional.h" |
| 13 #include "chrome/common/prerender_types.h" | 14 #include "chrome/common/prerender_types.h" |
| 14 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
| 15 #include "content/public/browser/resource_throttle.h" | 16 #include "content/public/browser/resource_throttle.h" |
| 16 #include "content/public/common/resource_type.h" | 17 #include "content/public/common/resource_type.h" |
| 18 #include "net/base/request_priority.h" |
| 17 | 19 |
| 18 class GURL; | 20 class GURL; |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 21 class URLRequest; | 23 class URLRequest; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace prerender { | 26 namespace prerender { |
| 25 class PrerenderContents; | 27 class PrerenderContents; |
| 26 class PrerenderThrottleInfo; | 28 class PrerenderThrottleInfo; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 void WillStartRequest(bool* defer) override; | 45 void WillStartRequest(bool* defer) override; |
| 44 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 46 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 45 bool* defer) override; | 47 bool* defer) override; |
| 46 void WillProcessResponse(bool* defer) override; | 48 void WillProcessResponse(bool* defer) override; |
| 47 const char* GetNameForLogging() const override; | 49 const char* GetNameForLogging() const override; |
| 48 | 50 |
| 49 // Called by the PrerenderContents when a prerender becomes visible. | 51 // Called by the PrerenderContents when a prerender becomes visible. |
| 50 // May only be called if currently throttling the resource. | 52 // May only be called if currently throttling the resource. |
| 51 void ResumeHandler(); | 53 void ResumeHandler(); |
| 52 | 54 |
| 55 // Resets the resource priority back to its original value. |
| 56 void ResetResourcePriority(); |
| 57 |
| 53 static void OverridePrerenderContentsForTesting(PrerenderContents* contents); | 58 static void OverridePrerenderContentsForTesting(PrerenderContents* contents); |
| 54 | 59 |
| 55 private: | 60 private: |
| 56 static void WillStartRequestOnUI( | 61 static void WillStartRequestOnUI( |
| 57 const base::WeakPtr<PrerenderResourceThrottle>& throttle, | 62 const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
| 58 const std::string& method, | 63 const std::string& method, |
| 59 content::ResourceType resource_type, | 64 content::ResourceType resource_type, |
| 60 const GURL& url, | 65 const GURL& url, |
| 61 const content::ResourceRequestInfo::WebContentsGetter& | 66 const content::ResourceRequestInfo::WebContentsGetter& |
| 62 web_contents_getter, | 67 web_contents_getter, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 83 static PrerenderContents* PrerenderContentsFromGetter( | 88 static PrerenderContents* PrerenderContentsFromGetter( |
| 84 const content::ResourceRequestInfo::WebContentsGetter& | 89 const content::ResourceRequestInfo::WebContentsGetter& |
| 85 web_contents_getter); | 90 web_contents_getter); |
| 86 | 91 |
| 87 // Sets the prerender mode. Must be called before |ResumeHandler()|. | 92 // Sets the prerender mode. Must be called before |ResumeHandler()|. |
| 88 void SetPrerenderMode(PrerenderMode mode); | 93 void SetPrerenderMode(PrerenderMode mode); |
| 89 | 94 |
| 90 net::URLRequest* request_; | 95 net::URLRequest* request_; |
| 91 int load_flags_; // Load flags to be OR'ed with the existing request flags. | 96 int load_flags_; // Load flags to be OR'ed with the existing request flags. |
| 92 | 97 |
| 98 // The throttle changes most request priorities to IDLE during prerendering. |
| 99 // The priority is reset back to the original priority when prerendering is |
| 100 // finished. |
| 101 base::Optional<net::RequestPriority> original_request_priority_; |
| 102 |
| 93 scoped_refptr<PrerenderThrottleInfo> prerender_throttle_info_; | 103 scoped_refptr<PrerenderThrottleInfo> prerender_throttle_info_; |
| 94 | 104 |
| 95 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle); | 105 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceThrottle); |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 } // namespace prerender | 108 } // namespace prerender |
| 99 | 109 |
| 100 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ | 110 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_THROTTLE_H_ |
| OLD | NEW |