Commit 79f59939 authored by shishir@chromium.org's avatar shishir@chromium.org

Speculative resource prefetching - fixing missing navigations due to server side redirects.

BUG=140335

Review URL: https://chromiumcodereview.appspot.com/10827103

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149727 0039d316-1c4b-4281-b951-d872f2087c98
parent 781a2840
......@@ -8,6 +8,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"
#include "googleurl/src/gurl.h"
#include "net/url_request/url_request.h"
using content::BrowserThread;
......@@ -89,15 +90,19 @@ void ResourcePrefetchPredictorObserver::OnRequestStarted(
}
void ResourcePrefetchPredictorObserver::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!ResourcePrefetchPredictor::ShouldRecordRedirect(request))
return;
ResourcePrefetchPredictor::URLRequestSummary summary;
if (!SummarizeResponse(request, &summary))
return;
summary.redirect_url = redirect_url;
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
......
......@@ -14,6 +14,8 @@ namespace net {
class URLRequest;
}
class GURL;
namespace chrome_browser_net {
// Observes resource requests in the ResourceDispatcherHostDelegate and notifies
......@@ -33,7 +35,7 @@ class ResourcePrefetchPredictorObserver {
ResourceType::Type resource_type,
int child_id,
int route_id);
void OnRequestRedirected(net::URLRequest* request);
void OnRequestRedirected(const GURL& redirect_url, net::URLRequest* request);
void OnResponseStarted(net::URLRequest* request);
private:
......
......@@ -85,11 +85,12 @@ ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary()
ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary(
const URLRequestSummary& other)
: navigation_id(other.navigation_id),
resource_url(other.resource_url),
resource_type(other.resource_type),
mime_type(other.mime_type),
was_cached(other.was_cached) {
: navigation_id(other.navigation_id),
resource_url(other.resource_url),
resource_type(other.resource_type),
mime_type(other.mime_type),
was_cached(other.was_cached),
redirect_url(other.redirect_url) {
}
ResourcePrefetchPredictor::URLRequestSummary::~URLRequestSummary() {
......@@ -348,7 +349,20 @@ void ResourcePrefetchPredictor::OnMainFrameRedirect(
const URLRequestSummary& response) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Remove the older navigation.
inflight_navigations_.erase(response.navigation_id);
// A redirect will not lead to another OnMainFrameRequest call, so record the
// redirect url as a new navigation.
// The redirect url may be empty if the url was invalid.
if (response.redirect_url.is_empty())
return;
NavigationID navigation_id(response.navigation_id);
navigation_id.main_frame_url = response.redirect_url;
inflight_navigations_.insert(std::make_pair(
navigation_id, std::vector<URLRequestSummary>()));
}
void ResourcePrefetchPredictor::OnSubresourceResponse(
......
......@@ -99,6 +99,7 @@ class ResourcePrefetchPredictor
// Only for responses.
std::string mime_type;
bool was_cached;
GURL redirect_url; // Empty unless request was redirected to a valid url.
};
ResourcePrefetchPredictor(const Config& config, Profile* profile);
......
......@@ -152,9 +152,10 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
throttles);
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
if (io_data->resource_prefetch_predictor_observer())
if (io_data->resource_prefetch_predictor_observer()) {
io_data->resource_prefetch_predictor_observer()->OnRequestStarted(
request, resource_type, child_id, route_id);
}
}
void ChromeResourceDispatcherHostDelegate::DownloadStarting(
......@@ -360,6 +361,7 @@ void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
}
void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request,
content::ResourceContext* resource_context,
content::ResourceResponse* response) {
......@@ -376,9 +378,10 @@ void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
#endif
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
if (io_data->resource_prefetch_predictor_observer())
if (io_data->resource_prefetch_predictor_observer()) {
io_data->resource_prefetch_predictor_observer()->OnRequestRedirected(
request);
redirect_url, request);
}
}
void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized(
......
......@@ -81,6 +81,7 @@ class ChromeResourceDispatcherHostDelegate
content::ResourceResponse* response,
IPC::Sender* sender) OVERRIDE;
virtual void OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request,
content::ResourceContext* resource_context,
content::ResourceResponse* response) OVERRIDE;
......
......@@ -144,7 +144,8 @@ bool AsyncResourceHandler::OnRequestRedirected(int request_id,
*defer = did_defer_ = true;
if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(request_, filter_->resource_context(),
rdh_->delegate()->OnRequestRedirected(new_url, request_,
filter_->resource_context(),
response);
}
......
......@@ -48,7 +48,8 @@ bool SyncResourceHandler::OnRequestRedirected(
ResourceResponse* response,
bool* defer) {
if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(request_, filter_->resource_context(),
rdh_->delegate()->OnRequestRedirected(new_url, request_,
filter_->resource_context(),
response);
}
......
......@@ -75,6 +75,7 @@ void ResourceDispatcherHostDelegate::OnResponseStarted(
}
void ResourceDispatcherHostDelegate::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request,
ResourceContext* resource_context,
ResourceResponse* response) {
......
......@@ -109,6 +109,7 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate {
// Informs the delegate that a request has been redirected.
virtual void OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request,
ResourceContext* resource_context,
ResourceResponse* response);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment