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

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: Created 4 years, 8 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 "content/public/browser/resource_request_info.h"
8 #include "net/url_request/redirect_info.h"
9
10 PredictorResourceThrottle::PredictorResourceThrottle(
11 net::URLRequest* request,
12 chrome_browser_net::Predictor* predictor)
13 : request_(request), predictor_(predictor) {}
14
15 PredictorResourceThrottle::~PredictorResourceThrottle() {}
16
17 void PredictorResourceThrottle::WillStartRequest(bool* defer) {
mmenke 2016/04/07 22:12:49 Know this is just the old code, with the redirect
Charlie Harrison 2016/05/23 14:16:20 Yeah sure no problem.
18 GURL request_scheme_host(
mmenke 2016/04/07 22:12:49 include gurl.h
Charlie Harrison 2016/05/23 14:16:20 Done.
19 chrome_browser_net::Predictor::CanonicalizeUrl(request_->url()));
20 if (request_scheme_host.is_empty())
21 return;
22 //
mmenke 2016/04/07 22:12:49 nit: Remove empty comment line - may make sense t
Charlie Harrison 2016/05/23 14:16:20 Done.
23 // Learn what URLs are likely to be needed during next startup.
24 predictor_->LearnAboutInitialNavigation(request_scheme_host);
25
26 const content::ResourceRequestInfo* info =
27 content::ResourceRequestInfo::ForRequest(request_);
28 DCHECK(info);
29 content::ResourceType resource_type = info->GetResourceType();
mmenke 2016/04/07 22:12:49 include content/public/common/resource_type.h
Charlie Harrison 2016/05/23 14:16:20 Done.
30 bool is_main_frame = (resource_type == content::RESOURCE_TYPE_MAIN_FRAME);
mmenke 2016/04/07 22:12:49 nit: Can just get rid of this bool, and inline th
Charlie Harrison 2016/05/23 14:16:20 Done.
31
32 if (!request_->referrer().empty()) {
33 GURL referring_scheme_host = GURL(request_->referrer()).GetWithEmptyPath();
34 // Learn about our referring URL, for use in the future.
35 if (!is_main_frame &&
36 predictor_->timed_cache()->WasRecentlySeen(referring_scheme_host)) {
37 predictor_->LearnFromNavigation(referring_scheme_host,
38 request_scheme_host);
39 }
40 if (referring_scheme_host == request_scheme_host) {
41 // We've already made any/all predictions when we navigated to the
42 // referring host, so we can bail out here.
43 // We don't update the RecentlySeen() time because any preconnections
44 // need to be made at the first navigation (i.e., when referer was loaded)
45 // and wouldn't have waited for this current request navigation.
46 return;
47 }
48 }
49
50 // Subresources for main frames usually get predicted when we detected the
51 // main frame request - way back in RenderViewHost::Navigate. So only handle
52 // predictions now for subframes.
53 if (resource_type == content::RESOURCE_TYPE_SUB_FRAME) {
54 predictor_->PredictFrameSubresources(request_scheme_host,
55 request_->first_party_for_cookies());
56 }
57 predictor_->timed_cache()->SetRecentlySeen(request_scheme_host);
58 }
59
60 void PredictorResourceThrottle::WillRedirectRequest(
61 const net::RedirectInfo& redirect_info,
62 bool* defer) {
63 GURL new_scheme_host(
64 chrome_browser_net::Predictor::CanonicalizeUrl(redirect_info.new_url));
65 GURL original_scheme_host(request_->original_url().GetWithEmptyPath());
66 if (new_scheme_host == original_scheme_host || new_scheme_host.is_empty()) {
67 return;
68 }
69 // Don't learn from redirects that take path as an argument, but do
70 // learn from short-hand typing entries, such as "cnn.com" redirects to
71 // "www.cnn.com". We can't just check for has_path(), as a mere "/"
72 // will count as a path, so we check that the path is at most a "/"
73 // (1 character long) to decide the redirect is "definitive" and has no
74 // significant path.
75 // TODO(jar): It may be ok to learn from all redirects, as the adaptive
76 // system will not respond until several identical redirects have taken
77 // place. Hence a use of a path (that changes) wouldn't really be
78 // learned from anyway.
79 if (request_->original_url().path().length() <= 1 &&
80 predictor_->timed_cache()->WasRecentlySeen(original_scheme_host)) {
81 // TODO(jar): These definite redirects could be learned much faster.
82 predictor_->LearnFromNavigation(original_scheme_host, new_scheme_host);
83 }
84 predictor_->timed_cache()->SetRecentlySeen(new_scheme_host);
mmenke 2016/04/07 22:12:49 Note that all of this code changes behavior, since
Charlie Harrison 2016/04/07 22:20:41 Can you explain why the previous behavior does not
mmenke 2016/04/07 22:39:59 Looks like you're right. Notice the "Only notify
85 }
86
87 const char* PredictorResourceThrottle::GetNameForLogging() const {
88 return "PredictorResourceThrottle";
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698