| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/connect_interceptor.h" | 5 #include "chrome/browser/net/connect_interceptor.h" |
| 6 | 6 |
| 7 #include "chrome/browser/net/predictor.h" | 7 #include "chrome/browser/net/predictor.h" |
| 8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
| 9 #include "net/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 void ConnectInterceptor::WitnessURLRequest(net::URLRequest* request) { | 23 void ConnectInterceptor::WitnessURLRequest(net::URLRequest* request) { |
| 24 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url())); | 24 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url())); |
| 25 if (request_scheme_host == GURL::EmptyGURL()) | 25 if (request_scheme_host == GURL::EmptyGURL()) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 // Learn what URLs are likely to be needed during next startup. | 28 // Learn what URLs are likely to be needed during next startup. |
| 29 predictor_->LearnAboutInitialNavigation(request_scheme_host); | 29 predictor_->LearnAboutInitialNavigation(request_scheme_host); |
| 30 | 30 |
| 31 bool redirected_host = false; | 31 bool redirected_host = false; |
| 32 bool is_subresource = !(request->load_flags() & net::LOAD_MAIN_FRAME); |
| 32 if (request->referrer().empty()) { | 33 if (request->referrer().empty()) { |
| 33 if (request->url() != request->original_url()) { | 34 if (request->url() != request->original_url()) { |
| 34 // This request was completed with a redirect. | 35 // This request was completed with a redirect. |
| 35 GURL original_scheme_host(request->original_url().GetWithEmptyPath()); | 36 GURL original_scheme_host(request->original_url().GetWithEmptyPath()); |
| 36 if (request_scheme_host != original_scheme_host) { | 37 if (request_scheme_host != original_scheme_host) { |
| 37 redirected_host = true; | 38 redirected_host = true; |
| 38 // Don't learn from redirects that take path as an argument, but do | 39 // Don't learn from redirects that take path as an argument, but do |
| 39 // learn from short-hand typing entries, such as "cnn.com" redirects to | 40 // learn from short-hand typing entries, such as "cnn.com" redirects to |
| 40 // "www.cnn.com". We can't just check for has_path(), as a mere "/" | 41 // "www.cnn.com". We can't just check for has_path(), as a mere "/" |
| 41 // will count as a path, so we check that the path is at most a "/" | 42 // will count as a path, so we check that the path is at most a "/" |
| 42 // (1 character long) to decide the redirect is "definitive" and has no | 43 // (1 character long) to decide the redirect is "definitive" and has no |
| 43 // significant path. | 44 // significant path. |
| 44 // TODO(jar): It may be ok to learn from all redirects, as the adaptive | 45 // TODO(jar): It may be ok to learn from all redirects, as the adaptive |
| 45 // system will not respond until several identical redirects have taken | 46 // system will not respond until several identical redirects have taken |
| 46 // place. Hence a use of a path (that changes) wouldn't really be | 47 // place. Hence a use of a path (that changes) wouldn't really be |
| 47 // learned from anyway. | 48 // learned from anyway. |
| 48 if (request->original_url().path().length() <= 1 && | 49 if (request->original_url().path().length() <= 1 && |
| 49 timed_cache_.WasRecentlySeen(original_scheme_host)) { | 50 timed_cache_.WasRecentlySeen(original_scheme_host)) { |
| 50 // TODO(jar): These definite redirects could be learned much faster. | 51 // TODO(jar): These definite redirects could be learned much faster. |
| 51 predictor_->LearnFromNavigation(original_scheme_host, | 52 predictor_->LearnFromNavigation(original_scheme_host, |
| 52 request_scheme_host); | 53 request_scheme_host); |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 } else { | 57 } else { |
| 57 GURL referring_scheme_host = GURL(request->referrer()).GetWithEmptyPath(); | 58 GURL referring_scheme_host = GURL(request->referrer()).GetWithEmptyPath(); |
| 58 bool is_subresource = !(request->load_flags() & net::LOAD_MAIN_FRAME); | |
| 59 // Learn about our referring URL, for use in the future. | 59 // Learn about our referring URL, for use in the future. |
| 60 if (is_subresource && timed_cache_.WasRecentlySeen(referring_scheme_host)) | 60 if (is_subresource && timed_cache_.WasRecentlySeen(referring_scheme_host)) |
| 61 predictor_->LearnFromNavigation(referring_scheme_host, | 61 predictor_->LearnFromNavigation(referring_scheme_host, |
| 62 request_scheme_host); | 62 request_scheme_host); |
| 63 if (referring_scheme_host == request_scheme_host) { | 63 if (referring_scheme_host == request_scheme_host) { |
| 64 // We've already made any/all predictions when we navigated to the | 64 // We've already made any/all predictions when we navigated to the |
| 65 // referring host, so we can bail out here. | 65 // referring host, so we can bail out here. |
| 66 // We don't update the RecentlySeen() time because any preconnections | 66 // We don't update the RecentlySeen() time because any preconnections |
| 67 // need to be made at the first navigation (i.e., when referer was loaded) | 67 // need to be made at the first navigation (i.e., when referer was loaded) |
| 68 // and wouldn't have waited for this current request navigation. | 68 // and wouldn't have waited for this current request navigation. |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 timed_cache_.SetRecentlySeen(request_scheme_host); | 72 timed_cache_.SetRecentlySeen(request_scheme_host); |
| 73 | 73 |
| 74 predictor_->RecordPreconnectNavigationStats(request_scheme_host); | 74 predictor_->RecordPreconnectNavigationStat(request->url_chain(), |
| 75 is_subresource); |
| 75 | 76 |
| 76 // Subresources for main frames usually get predicted when we detected the | 77 // Subresources for main frames usually get predicted when we detected the |
| 77 // main frame request - way back in RenderViewHost::Navigate. So only handle | 78 // main frame request - way back in RenderViewHost::Navigate. So only handle |
| 78 // predictions now for subresources or for redirected hosts. | 79 // predictions now for subresources or for redirected hosts. |
| 79 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host) | 80 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host) |
| 80 predictor_->PredictFrameSubresources(request_scheme_host, | 81 predictor_->PredictFrameSubresources(request_scheme_host, |
| 81 request->first_party_for_cookies()); | 82 request->first_party_for_cookies()); |
| 82 return; | 83 return; |
| 83 } | 84 } |
| 84 | 85 |
| 85 } // namespace chrome_browser_net | 86 } // namespace chrome_browser_net |
| OLD | NEW |