This source file includes following definitions.
- predictor_
- WitnessURLRequest
#include "chrome/browser/net/connect_interceptor.h"
#include "chrome/browser/net/predictor.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request.h"
namespace chrome_browser_net {
ConnectInterceptor::ConnectInterceptor(Predictor* predictor)
: timed_cache_(base::TimeDelta::FromSeconds(
Predictor::kMaxUnusedSocketLifetimeSecondsWithoutAGet)),
predictor_(predictor) {
DCHECK(predictor);
}
ConnectInterceptor::~ConnectInterceptor() {
}
void ConnectInterceptor::WitnessURLRequest(net::URLRequest* request) {
GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url()));
if (request_scheme_host == GURL::EmptyGURL())
return;
predictor_->LearnAboutInitialNavigation(request_scheme_host);
bool redirected_host = false;
bool is_subresource = !(request->load_flags() & net::LOAD_MAIN_FRAME);
if (request->referrer().empty()) {
if (request->url() != request->original_url()) {
GURL original_scheme_host(request->original_url().GetWithEmptyPath());
if (request_scheme_host != original_scheme_host) {
redirected_host = true;
if (request->original_url().path().length() <= 1 &&
timed_cache_.WasRecentlySeen(original_scheme_host)) {
predictor_->LearnFromNavigation(original_scheme_host,
request_scheme_host);
}
}
}
} else {
GURL referring_scheme_host = GURL(request->referrer()).GetWithEmptyPath();
if (is_subresource && timed_cache_.WasRecentlySeen(referring_scheme_host))
predictor_->LearnFromNavigation(referring_scheme_host,
request_scheme_host);
if (referring_scheme_host == request_scheme_host) {
return;
}
}
timed_cache_.SetRecentlySeen(request_scheme_host);
predictor_->RecordPreconnectNavigationStat(request->url_chain(),
is_subresource);
if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host)
predictor_->PredictFrameSubresources(request_scheme_host,
request->first_party_for_cookies());
return;
}
}