diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 14:12:33 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 14:12:33 +0000 |
commit | 0877d8b7ab3e70000023a608a7d214f17f22a8b0 (patch) | |
tree | 57e1619685ce888c1b6916baf85f83bc9dba4546 | |
parent | 46821242173a097387516ad48ac12fa173a5828d (diff) | |
download | chromium_src-0877d8b7ab3e70000023a608a7d214f17f22a8b0.zip chromium_src-0877d8b7ab3e70000023a608a7d214f17f22a8b0.tar.gz chromium_src-0877d8b7ab3e70000023a608a7d214f17f22a8b0.tar.bz2 |
Remove prerendering from net and content.
This is mostly a refactoring change. The main difference is that some histograms are removed, but these proved to not provide much interesting information.
BUG=92214
TBR=erikkay@chromium.org
Review URL: http://codereview.chromium.org/7669023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97457 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_url_request_user_data.cc | 32 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_url_request_user_data.h | 34 | ||||
-rw-r--r-- | chrome/browser/renderer_host/safe_browsing_resource_handler.cc | 24 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | content/browser/renderer_host/resource_dispatcher_host.cc | 128 | ||||
-rw-r--r-- | content/browser/renderer_host/resource_dispatcher_host.h | 5 | ||||
-rw-r--r-- | net/base/load_flags_list.h | 10 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 21 |
9 files changed, 157 insertions, 114 deletions
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc index 04c53ed..b5ecf43 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -15,6 +15,7 @@ #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_tracker.h" #include "chrome/browser/profiles/profile_io_data.h" +#include "chrome/browser/renderer_host/chrome_url_request_user_data.h" #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/ui/autologin_infobar_delegate.h" @@ -135,8 +136,12 @@ ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning( bool is_subresource, int child_id, int route_id) { - if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) - request->set_load_flags(request->load_flags() | net::LOAD_PRERENDERING); + ChromeURLRequestUserData* user_data = + ChromeURLRequestUserData::Create(request); + if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) { + user_data->set_is_prerender(true); + request->set_priority(net::IDLE); + } #if defined(ENABLE_SAFE_BROWSING) // Insert safe browsing at the front of the chain, so it gets to decide @@ -211,7 +216,8 @@ bool ChromeResourceDispatcherHostDelegate::AcceptSSLClientCertificateRequest( if (request->load_flags() & net::LOAD_PREFETCH) return false; - if (request->load_flags() & net::LOAD_PRERENDERING) { + ChromeURLRequestUserData* user_data = ChromeURLRequestUserData::Get(request); + if (user_data && user_data->is_prerender()) { int child_id, route_id; if (ResourceDispatcherHost::RenderViewForRequest( request, &child_id, &route_id)) { @@ -229,7 +235,8 @@ bool ChromeResourceDispatcherHostDelegate::AcceptSSLClientCertificateRequest( bool ChromeResourceDispatcherHostDelegate::AcceptAuthRequest( net::URLRequest* request, net::AuthChallengeInfo* auth_info) { - if (!(request->load_flags() & net::LOAD_PRERENDERING)) + ChromeURLRequestUserData* user_data = ChromeURLRequestUserData::Get(request); + if (!user_data || !user_data->is_prerender()) return true; int child_id, route_id; diff --git a/chrome/browser/renderer_host/chrome_url_request_user_data.cc b/chrome/browser/renderer_host/chrome_url_request_user_data.cc new file mode 100644 index 0000000..aeabcd1 --- /dev/null +++ b/chrome/browser/renderer_host/chrome_url_request_user_data.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/chrome_url_request_user_data.h" + +namespace { + +const char* const kKeyName = "chrome_url_request_user_data"; + +} // namespace + +ChromeURLRequestUserData::ChromeURLRequestUserData() + : is_prerender_(false) { +} + +// static +ChromeURLRequestUserData* ChromeURLRequestUserData::Get( + const net::URLRequest* request) { + DCHECK(request); + return static_cast<ChromeURLRequestUserData*>(request->GetUserData(kKeyName)); +} + +// static +ChromeURLRequestUserData* ChromeURLRequestUserData::Create( + net::URLRequest* request) { + DCHECK(request); + DCHECK(!Get(request)); + ChromeURLRequestUserData* user_data = new ChromeURLRequestUserData(); + request->SetUserData(kKeyName, user_data); + return user_data; +} diff --git a/chrome/browser/renderer_host/chrome_url_request_user_data.h b/chrome/browser/renderer_host/chrome_url_request_user_data.h new file mode 100644 index 0000000..4f356ea --- /dev/null +++ b/chrome/browser/renderer_host/chrome_url_request_user_data.h @@ -0,0 +1,34 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_URL_REQUEST_USER_DATA_H_ +#define CHROME_BROWSER_RENDERER_HOST_CHROME_URL_REQUEST_USER_DATA_H_ +#pragma once + +#include "net/url_request/url_request.h" + +class ChromeURLRequestUserData : public net::URLRequest::UserData { + public: + bool is_prerender() const { return is_prerender_; } + void set_is_prerender(bool is_prerender) { is_prerender_ = is_prerender; } + + // Creates a new ChromeURLRequestUserData instance and attaches it + // to |request|. |request| must not have an existing ChromeURLRequestUserData + // instance attached to it, and must be non-NULL. The returned instance + // is owned by |request|. + static ChromeURLRequestUserData* Create(net::URLRequest* request); + + // Gets the ChromeURLRequestUserData instance attached to |request|, or + // returns NULL if one is not attached. |request| must be non-NULL. + static ChromeURLRequestUserData* Get(const net::URLRequest* request); + + private: + ChromeURLRequestUserData(); + + bool is_prerender_; + + DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestUserData); +}; + +#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_URL_REQUEST_USER_DATA_H_ diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc index 2cacfdd..043b6e0 100644 --- a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc +++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc @@ -8,6 +8,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/prerender/prerender_final_status.h" #include "chrome/browser/prerender/prerender_tracker.h" +#include "chrome/browser/renderer_host/chrome_url_request_user_data.h" #include "content/browser/renderer_host/global_request_id.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/renderer_host/resource_message_filter.h" @@ -184,15 +185,20 @@ void SafeBrowsingResourceHandler::OnBrowseUrlCheckResult( // them. rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, false); should_show_blocking_page = false; - } else if (request->load_flags() & net::LOAD_PRERENDERING) { - prerender::PrerenderTracker* prerender_tracker = g_browser_process-> - prerender_tracker(); - if (prerender_tracker->TryCancelOnIOThread(render_process_host_id_, - render_view_id_, - prerender::FINAL_STATUS_SAFE_BROWSING)) { - rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, - false); - should_show_blocking_page = false; + } else { + ChromeURLRequestUserData* user_data = + ChromeURLRequestUserData::Get(request); + if (user_data && user_data->is_prerender()) { + prerender::PrerenderTracker* prerender_tracker = g_browser_process-> + prerender_tracker(); + if (prerender_tracker->TryCancelOnIOThread( + render_process_host_id_, + render_view_id_, + prerender::FINAL_STATUS_SAFE_BROWSING)) { + rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, + false); + should_show_blocking_page = false; + } } } if (should_show_blocking_page) { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2f9764d..ca15603 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1871,6 +1871,8 @@ 'browser/renderer_host/chrome_render_view_host_observer.h', 'browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc', 'browser/renderer_host/chrome_resource_dispatcher_host_delegate.h', + 'browser/renderer_host/chrome_url_request_user_data.cc', + 'browser/renderer_host/chrome_url_request_user_data.h', 'browser/renderer_host/gtk_im_context_wrapper.cc', 'browser/renderer_host/gtk_im_context_wrapper.h', 'browser/renderer_host/gtk_key_bindings_handler.cc', diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc index d2caf27..248c34d 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.cc +++ b/content/browser/renderer_host/resource_dispatcher_host.cc @@ -233,6 +233,65 @@ void RemoveDownloadFileFromChildSecurityPolicy(int child_id, #pragma warning(default: 4748) #endif +net::RequestPriority DetermineRequestPriority(ResourceType::Type type) { + // Determine request priority based on how critical this resource typically + // is to user-perceived page load performance. Important considerations are: + // * Can this resource block the download of other resources. + // * Can this resource block the rendering of the page. + // * How useful is the page to the user if this resource is not loaded yet. + + switch (type) { + // Main frames are the highest priority because they can block nearly every + // type of other resource and there is no useful display without them. + // Sub frames are a close second, however it is a common pattern to wrap + // ads in an iframe or even in multiple nested iframes. It is worth + // investigating if there is a better priority for them. + case ResourceType::MAIN_FRAME: + case ResourceType::SUB_FRAME: + return net::HIGHEST; + + // Stylesheets and scripts can block rendering and loading of other + // resources. Fonts can block text from rendering. + case ResourceType::STYLESHEET: + case ResourceType::SCRIPT: + case ResourceType::FONT_RESOURCE: + return net::MEDIUM; + + // Sub resources, objects and media are lower priority than potentially + // blocking stylesheets, scripts and fonts, but are higher priority than + // images because if they exist they are probably more central to the page + // focus than images on the page. + case ResourceType::SUB_RESOURCE: + case ResourceType::OBJECT: + case ResourceType::MEDIA: + case ResourceType::WORKER: + case ResourceType::SHARED_WORKER: + case ResourceType::XHR: + return net::LOW; + + // Images are the "lowest" priority because they typically do not block + // downloads or rendering and most pages have some useful content without + // them. + case ResourceType::IMAGE: + // Favicons aren't required for rendering the current page, but + // are user visible. + case ResourceType::FAVICON: + return net::LOWEST; + + // Prefetches and prerenders are at a lower priority than even + // LOWEST, since they are not even required for rendering of the + // current page. + case ResourceType::PREFETCH: + case ResourceType::PRERENDER: + return net::IDLE; + + default: + // When new resource types are added, their priority must be considered. + NOTREACHED(); + return net::LOW; + } +} + } // namespace ResourceDispatcherHost::ResourceDispatcherHost( @@ -479,8 +538,7 @@ void ResourceDispatcherHost::BeginRequest( request->set_load_flags(load_flags); request->set_context( filter_->GetURLRequestContext(request_data.resource_type)); - request->set_priority(DetermineRequestPriority(request_data.resource_type, - load_flags)); + request->set_priority(DetermineRequestPriority(request_data.resource_type)); // Set upload data. uint64 upload_size = 0; @@ -2041,72 +2099,6 @@ bool ResourceDispatcherHost::IsValidRequest(net::URLRequest* request) { } // static -net::RequestPriority ResourceDispatcherHost::DetermineRequestPriority( - ResourceType::Type type, - int load_flags) { - // Determine request priority based on how critical this resource typically - // is to user-perceived page load performance. Important considerations are: - // * Can this resource block the download of other resources. - // * Can this resource block the rendering of the page. - // * How useful is the page to the user if this resource is not loaded yet. - - // Prerender-motivated requests should be made at IDLE. - if (load_flags & net::LOAD_PRERENDERING) - return net::IDLE; - - switch (type) { - // Main frames are the highest priority because they can block nearly every - // type of other resource and there is no useful display without them. - // Sub frames are a close second, however it is a common pattern to wrap - // ads in an iframe or even in multiple nested iframes. It is worth - // investigating if there is a better priority for them. - case ResourceType::MAIN_FRAME: - case ResourceType::SUB_FRAME: - return net::HIGHEST; - - // Stylesheets and scripts can block rendering and loading of other - // resources. Fonts can block text from rendering. - case ResourceType::STYLESHEET: - case ResourceType::SCRIPT: - case ResourceType::FONT_RESOURCE: - return net::MEDIUM; - - // Sub resources, objects and media are lower priority than potentially - // blocking stylesheets, scripts and fonts, but are higher priority than - // images because if they exist they are probably more central to the page - // focus than images on the page. - case ResourceType::SUB_RESOURCE: - case ResourceType::OBJECT: - case ResourceType::MEDIA: - case ResourceType::WORKER: - case ResourceType::SHARED_WORKER: - case ResourceType::XHR: - return net::LOW; - - // Images are the "lowest" priority because they typically do not block - // downloads or rendering and most pages have some useful content without - // them. - case ResourceType::IMAGE: - // Favicons aren't required for rendering the current page, but - // are user visible. - case ResourceType::FAVICON: - return net::LOWEST; - - // Prefetches and prerenders are at a lower priority than even - // LOWEST, since they are not even required for rendering of the - // current page. - case ResourceType::PREFETCH: - case ResourceType::PRERENDER: - return net::IDLE; - - default: - // When new resource types are added, their priority must be considered. - NOTREACHED(); - return net::LOW; - } -} - -// static bool ResourceDispatcherHost::is_prefetch_enabled() { return is_prefetch_enabled_; } diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h index 8de0129..5014a2d 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.h +++ b/content/browser/renderer_host/resource_dispatcher_host.h @@ -414,11 +414,6 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate { // Returns true if |request| is in |pending_requests_|. bool IsValidRequest(net::URLRequest* request); - // Determine request priority based on how critical this resource typically - // is to user-perceived page load performance. - static net::RequestPriority DetermineRequestPriority(ResourceType::Type type, - int load_flags); - // Sends the given notification on the UI thread. The RenderViewHost's // controller is used as the source. template <class T> diff --git a/net/base/load_flags_list.h b/net/base/load_flags_list.h index aeaca85..635ce79 100644 --- a/net/base/load_flags_list.h +++ b/net/base/load_flags_list.h @@ -102,19 +102,15 @@ LOAD_FLAG(REPORT_RAW_HEADERS, 1 << 22) // and is (in theory) not intended for the current frame. LOAD_FLAG(PREFETCH, 1 << 23) -// Indicates that this load was requested by a page that is currently -// prerendering. -LOAD_FLAG(PRERENDERING, 1 << 24) - // Indicates that this is a load that ignores limits and should complete // immediately. -LOAD_FLAG(IGNORE_LIMITS, 1 << 25) +LOAD_FLAG(IGNORE_LIMITS, 1 << 24) // Suppress login prompts for this request. Cached credentials or // default credentials may still be used for authentication. -LOAD_FLAG(DO_NOT_PROMPT_FOR_LOGIN, 1 << 26) +LOAD_FLAG(DO_NOT_PROMPT_FOR_LOGIN, 1 << 25) // Indicates that the operation is somewhat likely to be due to an // explicit user action. This can be used as a hint to treat the // request with higher priority. -LOAD_FLAG(MAYBE_USER_GESTURE, 1 << 27) +LOAD_FLAG(MAYBE_USER_GESTURE, 1 << 26) diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index b852622..af26db5 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -1260,27 +1260,6 @@ void URLRequestHttpJob::RecordTimer() { "Prefetch"), to_start); } - - const bool is_prerender = !!(request_info_.load_flags & LOAD_PRERENDERING); - if (is_prerender) { - UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpTimeToFirstByte_Prerender", - to_start); - if (use_prefetch_histogram) { - UMA_HISTOGRAM_MEDIUM_TIMES( - base::FieldTrial::MakeName("Net.HttpTimeToFirstByte_Prerender", - "Prefetch"), - to_start); - } - } else { - UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpTimeToFirstByte_NonPrerender", - to_start); - if (use_prefetch_histogram) { - UMA_HISTOGRAM_MEDIUM_TIMES( - base::FieldTrial::MakeName("Net.HttpTimeToFirstByte_NonPrerender", - "Prefetch"), - to_start); - } - } } void URLRequestHttpJob::ResetTimer() { |