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

Side by Side Diff: chrome/browser/net/connect_interceptor.cc

Issue 2337233006: CL for src perf tryjob to run page_cycler_v2.intl_ko_th_vi benchmark on all-android platform(s)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « chrome/browser/net/connect_interceptor.h ('k') | chrome/browser/net/predictor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/net/connect_interceptor.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/base/load_flags.h"
11 #include "net/url_request/url_request.h"
12
13 namespace chrome_browser_net {
14
15 ConnectInterceptor::ConnectInterceptor(Predictor* predictor)
16 : timed_cache_(base::TimeDelta::FromSeconds(
17 Predictor::kMaxUnusedSocketLifetimeSecondsWithoutAGet)),
18 predictor_(predictor) {
19 DCHECK(predictor);
20 }
21
22 ConnectInterceptor::~ConnectInterceptor() {
23 }
24
25 void ConnectInterceptor::WitnessURLRequest(net::URLRequest* request) {
26 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url()));
27 if (request_scheme_host == GURL::EmptyGURL())
28 return;
29
30 const content::ResourceRequestInfo* info =
31 content::ResourceRequestInfo::ForRequest(request);
32 bool is_main_frame = false;
33 bool is_sub_frame = false;
34 // TODO(mmenke): Should the predictor really be fed requests without a
35 // ResourceRequestInfo?
36 if (info) {
37 content::ResourceType resource_type = info->GetResourceType();
38 is_main_frame = (resource_type == content::RESOURCE_TYPE_MAIN_FRAME);
39 is_sub_frame = (resource_type == content::RESOURCE_TYPE_SUB_FRAME);
40 }
41
42 // Learn what URLs are likely to be needed during next startup.
43 printf("learning about: %s\n", request_scheme_host.spec().c_str());
44 predictor_->LearnAboutInitialNavigation(request_scheme_host);
45
46 bool redirected_host = false;
47 if (request->referrer().empty()) {
48 if (request->url() != request->original_url()) {
49 // This request was completed with a redirect.
50 GURL original_scheme_host(request->original_url().GetWithEmptyPath());
51 if (request_scheme_host != original_scheme_host) {
52 redirected_host = true;
53 // Don't learn from redirects that take path as an argument, but do
54 // learn from short-hand typing entries, such as "cnn.com" redirects to
55 // "www.cnn.com". We can't just check for has_path(), as a mere "/"
56 // will count as a path, so we check that the path is at most a "/"
57 // (1 character long) to decide the redirect is "definitive" and has no
58 // significant path.
59 // TODO(jar): It may be ok to learn from all redirects, as the adaptive
60 // system will not respond until several identical redirects have taken
61 // place. Hence a use of a path (that changes) wouldn't really be
62 // learned from anyway.
63 if (request->original_url().path().length() <= 1 &&
64 timed_cache_.WasRecentlySeen(original_scheme_host)) {
65 // TODO(jar): These definite redirects could be learned much faster.
66 predictor_->LearnFromNavigation(original_scheme_host,
67 request_scheme_host);
68 }
69 }
70 }
71 } else {
72 GURL referring_scheme_host = GURL(request->referrer()).GetWithEmptyPath();
73 // Learn about our referring URL, for use in the future.
74 if (!is_main_frame && timed_cache_.WasRecentlySeen(referring_scheme_host)) {
75 predictor_->LearnFromNavigation(referring_scheme_host,
76 request_scheme_host);
77 }
78 if (referring_scheme_host == request_scheme_host) {
79 // We've already made any/all predictions when we navigated to the
80 // referring host, so we can bail out here.
81 // We don't update the RecentlySeen() time because any preconnections
82 // need to be made at the first navigation (i.e., when referer was loaded)
83 // and wouldn't have waited for this current request navigation.
84 return;
85 }
86 }
87 timed_cache_.SetRecentlySeen(request_scheme_host);
88
89 // Subresources for main frames usually get predicted when we detected the
90 // main frame request - way back in RenderViewHost::Navigate. So only handle
91 // predictions now for subresources or for redirected hosts.
92 if (is_sub_frame || redirected_host) {
93 predictor_->PredictFrameSubresources(request_scheme_host,
94 request->first_party_for_cookies());
95 }
96 return;
97 }
98
99 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/connect_interceptor.h ('k') | chrome/browser/net/predictor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698