Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: chrome/browser/renderer_host/predictor_resource_throttle.cc

Issue 1857383002: Refactor net predictor to use ResourceThrottles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more comment changes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_host/predictor_resource_throttle.h"
6
7 #include "chrome/browser/net/predictor.h"
8 #include "content/public/browser/resource_request_info.h"
9 #include "content/public/common/resource_type.h"
10 #include "net/url_request/redirect_info.h"
11 #include "net/url_request/url_request.h"
12 #include "url/gurl.h"
13
14 PredictorResourceThrottle::PredictorResourceThrottle(
15 net::URLRequest* request,
16 chrome_browser_net::Predictor* predictor)
17 : request_(request), predictor_(predictor) {}
18
19 PredictorResourceThrottle::~PredictorResourceThrottle() {}
20
21 // Hooks into URLRequests starting to initiate predictions based on subframe
22 // requests, and to learn referrer relationships.
23 void PredictorResourceThrottle::WillStartRequest(bool* defer) {
24 GURL request_scheme_host(
25 chrome_browser_net::Predictor::CanonicalizeUrl(request_->url()));
26 if (request_scheme_host.is_empty())
27 return;
28
29 // Learn what URLs are likely to be needed during next startup.
30 predictor_->LearnAboutInitialNavigation(request_scheme_host);
31
32 const content::ResourceRequestInfo* info =
33 content::ResourceRequestInfo::ForRequest(request_);
34 DCHECK(info);
35 content::ResourceType resource_type = info->GetResourceType();
36 const GURL& referring_scheme_host =
37 GURL(request_->referrer()).GetWithEmptyPath();
38
39 // Learn about our referring URL, for use in the future. Only learn
40 // subresource relationships.
41 if (!referring_scheme_host.is_empty() &&
42 resource_type != content::RESOURCE_TYPE_MAIN_FRAME &&
43 predictor_->timed_cache()->WasRecentlySeen(referring_scheme_host)) {
44 predictor_->LearnFromNavigation(referring_scheme_host, request_scheme_host);
45 }
46
47 // We've already made any/all predictions when we navigated to the referring
48 // host, so we can bail out here. We don't update the RecentlySeen() time
49 // because the timed cache is already populated (with the correct timeout)
50 // based on the initial navigation.
51 if (referring_scheme_host == request_scheme_host)
52 return;
53
54 predictor_->timed_cache()->SetRecentlySeen(request_scheme_host);
55
56 // Subresources for main frames usually get predicted when we detected the
mmenke 2016/05/23 18:50:22 Verb tenses are awkward here ("detected" is past t
Charlie Harrison 2016/05/23 21:13:32 I think the tab helper was originally designed as
57 // main frame request - way back in RenderViewHost::Navigate. So only handle
58 // predsctions now for subframes.
59 predictor_->timed_cache()->SetRecentlySeen(request_scheme_host);
60 if (resource_type == content::RESOURCE_TYPE_SUB_FRAME) {
61 predictor_->PredictFrameSubresources(request_scheme_host,
62 request_->first_party_for_cookies());
63 }
64 }
65
66 // Hook into redirect notifications to learn and initiate predictions based on
mmenke 2016/05/23 18:50:22 "Hooks", "initiates", like the comment for the met
Charlie Harrison 2016/05/23 21:13:32 Done.
67 // the redirected url.
68 void PredictorResourceThrottle::WillRedirectRequest(
69 const net::RedirectInfo& redirect_info,
70 bool* defer) {
71 GURL new_scheme_host(
72 chrome_browser_net::Predictor::CanonicalizeUrl(redirect_info.new_url));
73 GURL original_scheme_host(request_->original_url().GetWithEmptyPath());
74 if (new_scheme_host == original_scheme_host || new_scheme_host.is_empty())
75 return;
76 // Don't learn from redirects that take path as an argument, but do
77 // learn from short-hand typing entries, such as "cnn.com" redirects to
78 // "www.cnn.com". We can't just check for has_path(), as a mere "/"
79 // will count as a path, so we check that the path is at most a "/"
80 // (1 character long) to decide the redirect is "definitive" and has no
81 // significant path.
82 // TODO(jar): It may be ok to learn from all redirects, as the adaptive
83 // system will not respond until several identical redirects have taken
84 // place. Hence a use of a path (that changes) wouldn't really be
85 // learned from anyway.
86 if (request_->original_url().path().length() <= 1 &&
87 predictor_->timed_cache()->WasRecentlySeen(original_scheme_host)) {
88 // TODO(jar): These definite redirects could be learned much faster.
89 predictor_->LearnFromNavigation(original_scheme_host, new_scheme_host);
90 }
91 predictor_->timed_cache()->SetRecentlySeen(new_scheme_host);
92 predictor_->PredictFrameSubresources(
93 new_scheme_host, redirect_info.new_first_party_for_cookies);
mmenke 2016/05/23 18:50:22 I don't think this should be called on non-main-fr
Charlie Harrison 2016/05/23 21:13:32 Wow you're right, even though this is the current
94 }
95
96 const char* PredictorResourceThrottle::GetNameForLogging() const {
97 return "PredictorResourceThrottle";
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698