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 @@ ...@@ -8,6 +8,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h" #include "content/public/browser/resource_request_info.h"
#include "googleurl/src/gurl.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -89,15 +90,19 @@ void ResourcePrefetchPredictorObserver::OnRequestStarted( ...@@ -89,15 +90,19 @@ void ResourcePrefetchPredictorObserver::OnRequestStarted(
} }
void ResourcePrefetchPredictorObserver::OnRequestRedirected( void ResourcePrefetchPredictorObserver::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request) { net::URLRequest* request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!ResourcePrefetchPredictor::ShouldRecordRedirect(request)) if (!ResourcePrefetchPredictor::ShouldRecordRedirect(request))
return; return;
ResourcePrefetchPredictor::URLRequestSummary summary; ResourcePrefetchPredictor::URLRequestSummary summary;
if (!SummarizeResponse(request, &summary)) if (!SummarizeResponse(request, &summary))
return; return;
summary.redirect_url = redirect_url;
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
......
...@@ -14,6 +14,8 @@ namespace net { ...@@ -14,6 +14,8 @@ namespace net {
class URLRequest; class URLRequest;
} }
class GURL;
namespace chrome_browser_net { namespace chrome_browser_net {
// Observes resource requests in the ResourceDispatcherHostDelegate and notifies // Observes resource requests in the ResourceDispatcherHostDelegate and notifies
...@@ -33,7 +35,7 @@ class ResourcePrefetchPredictorObserver { ...@@ -33,7 +35,7 @@ class ResourcePrefetchPredictorObserver {
ResourceType::Type resource_type, ResourceType::Type resource_type,
int child_id, int child_id,
int route_id); int route_id);
void OnRequestRedirected(net::URLRequest* request); void OnRequestRedirected(const GURL& redirect_url, net::URLRequest* request);
void OnResponseStarted(net::URLRequest* request); void OnResponseStarted(net::URLRequest* request);
private: private:
......
...@@ -85,11 +85,12 @@ ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary() ...@@ -85,11 +85,12 @@ ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary()
ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary( ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary(
const URLRequestSummary& other) const URLRequestSummary& other)
: navigation_id(other.navigation_id), : navigation_id(other.navigation_id),
resource_url(other.resource_url), resource_url(other.resource_url),
resource_type(other.resource_type), resource_type(other.resource_type),
mime_type(other.mime_type), mime_type(other.mime_type),
was_cached(other.was_cached) { was_cached(other.was_cached),
redirect_url(other.redirect_url) {
} }
ResourcePrefetchPredictor::URLRequestSummary::~URLRequestSummary() { ResourcePrefetchPredictor::URLRequestSummary::~URLRequestSummary() {
...@@ -348,7 +349,20 @@ void ResourcePrefetchPredictor::OnMainFrameRedirect( ...@@ -348,7 +349,20 @@ void ResourcePrefetchPredictor::OnMainFrameRedirect(
const URLRequestSummary& response) { const URLRequestSummary& response) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Remove the older navigation.
inflight_navigations_.erase(response.navigation_id); 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( void ResourcePrefetchPredictor::OnSubresourceResponse(
......
...@@ -99,6 +99,7 @@ class ResourcePrefetchPredictor ...@@ -99,6 +99,7 @@ class ResourcePrefetchPredictor
// Only for responses. // Only for responses.
std::string mime_type; std::string mime_type;
bool was_cached; bool was_cached;
GURL redirect_url; // Empty unless request was redirected to a valid url.
}; };
ResourcePrefetchPredictor(const Config& config, Profile* profile); ResourcePrefetchPredictor(const Config& config, Profile* profile);
......
...@@ -152,9 +152,10 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning( ...@@ -152,9 +152,10 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
throttles); throttles);
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 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( io_data->resource_prefetch_predictor_observer()->OnRequestStarted(
request, resource_type, child_id, route_id); request, resource_type, child_id, route_id);
}
} }
void ChromeResourceDispatcherHostDelegate::DownloadStarting( void ChromeResourceDispatcherHostDelegate::DownloadStarting(
...@@ -360,6 +361,7 @@ void ChromeResourceDispatcherHostDelegate::OnResponseStarted( ...@@ -360,6 +361,7 @@ void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
} }
void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request, net::URLRequest* request,
content::ResourceContext* resource_context, content::ResourceContext* resource_context,
content::ResourceResponse* response) { content::ResourceResponse* response) {
...@@ -376,9 +378,10 @@ void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( ...@@ -376,9 +378,10 @@ void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
#endif #endif
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 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( io_data->resource_prefetch_predictor_observer()->OnRequestRedirected(
request); redirect_url, request);
}
} }
void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized( void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized(
......
...@@ -81,6 +81,7 @@ class ChromeResourceDispatcherHostDelegate ...@@ -81,6 +81,7 @@ class ChromeResourceDispatcherHostDelegate
content::ResourceResponse* response, content::ResourceResponse* response,
IPC::Sender* sender) OVERRIDE; IPC::Sender* sender) OVERRIDE;
virtual void OnRequestRedirected( virtual void OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request, net::URLRequest* request,
content::ResourceContext* resource_context, content::ResourceContext* resource_context,
content::ResourceResponse* response) OVERRIDE; content::ResourceResponse* response) OVERRIDE;
......
...@@ -144,7 +144,8 @@ bool AsyncResourceHandler::OnRequestRedirected(int request_id, ...@@ -144,7 +144,8 @@ bool AsyncResourceHandler::OnRequestRedirected(int request_id,
*defer = did_defer_ = true; *defer = did_defer_ = true;
if (rdh_->delegate()) { if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(request_, filter_->resource_context(), rdh_->delegate()->OnRequestRedirected(new_url, request_,
filter_->resource_context(),
response); response);
} }
......
...@@ -48,7 +48,8 @@ bool SyncResourceHandler::OnRequestRedirected( ...@@ -48,7 +48,8 @@ bool SyncResourceHandler::OnRequestRedirected(
ResourceResponse* response, ResourceResponse* response,
bool* defer) { bool* defer) {
if (rdh_->delegate()) { if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(request_, filter_->resource_context(), rdh_->delegate()->OnRequestRedirected(new_url, request_,
filter_->resource_context(),
response); response);
} }
......
...@@ -75,6 +75,7 @@ void ResourceDispatcherHostDelegate::OnResponseStarted( ...@@ -75,6 +75,7 @@ void ResourceDispatcherHostDelegate::OnResponseStarted(
} }
void ResourceDispatcherHostDelegate::OnRequestRedirected( void ResourceDispatcherHostDelegate::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request, net::URLRequest* request,
ResourceContext* resource_context, ResourceContext* resource_context,
ResourceResponse* response) { ResourceResponse* response) {
......
...@@ -109,6 +109,7 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate { ...@@ -109,6 +109,7 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate {
// Informs the delegate that a request has been redirected. // Informs the delegate that a request has been redirected.
virtual void OnRequestRedirected( virtual void OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request, net::URLRequest* request,
ResourceContext* resource_context, ResourceContext* resource_context,
ResourceResponse* response); 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