| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <sstream> | 11 #include <sstream> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/containers/mru_cache.h" | 17 #include "base/containers/mru_cache.h" |
| 18 #include "base/feature_list.h" | 18 #include "base/feature_list.h" |
| 19 #include "base/location.h" | 19 #include "base/location.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 27 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "base/trace_event/trace_event.h" |
| 30 #include "base/values.h" | 31 #include "base/values.h" |
| 31 #include "chrome/browser/io_thread.h" | 32 #include "chrome/browser/io_thread.h" |
| 32 #include "chrome/browser/prefs/session_startup_pref.h" | 33 #include "chrome/browser/prefs/session_startup_pref.h" |
| 33 #include "chrome/browser/profiles/profile_io_data.h" | 34 #include "chrome/browser/profiles/profile_io_data.h" |
| 34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 36 #include "components/pref_registry/pref_registry_syncable.h" | 37 #include "components/pref_registry/pref_registry_syncable.h" |
| 37 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
| 38 #include "components/prefs/scoped_user_pref_update.h" | 39 #include "components/prefs/scoped_user_pref_update.h" |
| 39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 // TODO(csharrison): The observer should only be notified after the null check | 754 // TODO(csharrison): The observer should only be notified after the null check |
| 754 // for the ProfileIOData. The predictor tests should be fixed to allow for | 755 // for the ProfileIOData. The predictor tests should be fixed to allow for |
| 755 // this, as they currently expect a callback with no getter. | 756 // this, as they currently expect a callback with no getter. |
| 756 if (observer_) { | 757 if (observer_) { |
| 757 observer_->OnPreconnectUrl( | 758 observer_->OnPreconnectUrl( |
| 758 url, first_party_for_cookies, motivation, count); | 759 url, first_party_for_cookies, motivation, count); |
| 759 } | 760 } |
| 760 | 761 |
| 761 if (!profile_io_data_) | 762 if (!profile_io_data_) |
| 762 return; | 763 return; |
| 763 | 764 TRACE_EVENT2("net", "Predictor::PreconnectUrlOnIOThread", "url", |
| 765 original_url.spec(), "motivation", static_cast<int>(motivation)); |
| 764 // Translate the motivation from UrlRequest motivations to HttpRequest | 766 // Translate the motivation from UrlRequest motivations to HttpRequest |
| 765 // motivations. | 767 // motivations. |
| 766 net::HttpRequestInfo::RequestMotivation request_motivation = | 768 net::HttpRequestInfo::RequestMotivation request_motivation = |
| 767 net::HttpRequestInfo::NORMAL_MOTIVATION; | 769 net::HttpRequestInfo::NORMAL_MOTIVATION; |
| 768 switch (motivation) { | 770 switch (motivation) { |
| 769 case UrlInfo::OMNIBOX_MOTIVATED: | 771 case UrlInfo::OMNIBOX_MOTIVATED: |
| 770 request_motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED; | 772 request_motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED; |
| 771 break; | 773 break; |
| 772 case UrlInfo::LEARNED_REFERAL_MOTIVATED: | 774 case UrlInfo::LEARNED_REFERAL_MOTIVATED: |
| 773 request_motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED; | 775 request_motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 834 |
| 833 enum SubresourceValue { | 835 enum SubresourceValue { |
| 834 PRECONNECTION, | 836 PRECONNECTION, |
| 835 PRERESOLUTION, | 837 PRERESOLUTION, |
| 836 TOO_NEW, | 838 TOO_NEW, |
| 837 SUBRESOURCE_VALUE_MAX | 839 SUBRESOURCE_VALUE_MAX |
| 838 }; | 840 }; |
| 839 | 841 |
| 840 void Predictor::PrepareFrameSubresources(const GURL& original_url, | 842 void Predictor::PrepareFrameSubresources(const GURL& original_url, |
| 841 const GURL& first_party_for_cookies) { | 843 const GURL& first_party_for_cookies) { |
| 844 TRACE_EVENT1("net", "Predictor::PrepareFrameSubresources", "url", |
| 845 original_url.spec()); |
| 842 // Apply HSTS redirect early so it is taken into account when looking up | 846 // Apply HSTS redirect early so it is taken into account when looking up |
| 843 // subresources. | 847 // subresources. |
| 844 GURL url = GetHSTSRedirectOnIOThread(original_url); | 848 GURL url = GetHSTSRedirectOnIOThread(original_url); |
| 845 | 849 |
| 846 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 850 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 847 DCHECK_EQ(url.GetWithEmptyPath(), url); | 851 DCHECK_EQ(url.GetWithEmptyPath(), url); |
| 848 DCHECK(PredictorEnabled()); | 852 DCHECK(PredictorEnabled()); |
| 849 // Peek here, and Get after logging the index into the MRU. | 853 // Peek here, and Get after logging the index into the MRU. |
| 850 Referrers::iterator it = referrers_.Get(url); | 854 Referrers::iterator it = referrers_.Get(url); |
| 851 if (referrers_.end() == it) { | 855 if (referrers_.end() == it) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 } | 1204 } |
| 1201 | 1205 |
| 1202 void SimplePredictor::ShutdownOnUIThread() { | 1206 void SimplePredictor::ShutdownOnUIThread() { |
| 1203 SetShutdown(true); | 1207 SetShutdown(true); |
| 1204 } | 1208 } |
| 1205 | 1209 |
| 1206 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1210 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
| 1207 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1211 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
| 1208 | 1212 |
| 1209 } // namespace chrome_browser_net | 1213 } // namespace chrome_browser_net |
| OLD | NEW |