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> |
(...skipping 13 matching lines...) Expand all Loading... |
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/values.h" | 30 #include "base/values.h" |
31 #include "chrome/browser/io_thread.h" | 31 #include "chrome/browser/io_thread.h" |
32 #include "chrome/browser/prefs/session_startup_pref.h" | 32 #include "chrome/browser/prefs/session_startup_pref.h" |
33 #include "chrome/browser/profiles/profile_io_data.h" | 33 #include "chrome/browser/profiles/profile_io_data.h" |
| 34 #include "chrome/common/chrome_features.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" |
40 #include "content/public/browser/resource_hints.h" | 41 #include "content/public/browser/resource_hints.h" |
41 #include "net/base/address_list.h" | 42 #include "net/base/address_list.h" |
42 #include "net/base/completion_callback.h" | 43 #include "net/base/completion_callback.h" |
43 #include "net/base/host_port_pair.h" | 44 #include "net/base/host_port_pair.h" |
44 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
45 #include "net/http/transport_security_state.h" | 46 #include "net/http/transport_security_state.h" |
46 #include "net/log/net_log_with_source.h" | 47 #include "net/log/net_log_with_source.h" |
47 #include "net/proxy/proxy_info.h" | 48 #include "net/proxy/proxy_info.h" |
48 #include "net/proxy/proxy_service.h" | 49 #include "net/proxy/proxy_service.h" |
49 #include "net/ssl/ssl_config_service.h" | 50 #include "net/ssl/ssl_config_service.h" |
50 #include "net/url_request/url_request_context.h" | 51 #include "net/url_request/url_request_context.h" |
51 #include "net/url_request/url_request_context_getter.h" | 52 #include "net/url_request/url_request_context_getter.h" |
52 | 53 |
53 using base::TimeDelta; | 54 using base::TimeDelta; |
54 using content::BrowserThread; | 55 using content::BrowserThread; |
55 | 56 |
56 namespace chrome_browser_net { | 57 namespace chrome_browser_net { |
57 | 58 |
58 namespace { | |
59 | |
60 const base::Feature kNetworkPrediction{"NetworkPrediction", | |
61 base::FEATURE_ENABLED_BY_DEFAULT}; | |
62 | |
63 } // namespace | |
64 | |
65 // static | 59 // static |
66 const int Predictor::kPredictorReferrerVersion = 2; | 60 const int Predictor::kPredictorReferrerVersion = 2; |
67 const double Predictor::kPreconnectWorthyExpectedValue = 0.8; | 61 const double Predictor::kPreconnectWorthyExpectedValue = 0.8; |
68 const double Predictor::kDNSPreresolutionWorthyExpectedValue = 0.1; | 62 const double Predictor::kDNSPreresolutionWorthyExpectedValue = 0.1; |
69 const double Predictor::kDiscardableExpectedValue = 0.05; | 63 const double Predictor::kDiscardableExpectedValue = 0.05; |
70 const size_t Predictor::kMaxSpeculativeParallelResolves = 3; | 64 const size_t Predictor::kMaxSpeculativeParallelResolves = 3; |
71 const int Predictor::kMaxUnusedSocketLifetimeSecondsWithoutAGet = 10; | 65 const int Predictor::kMaxUnusedSocketLifetimeSecondsWithoutAGet = 10; |
72 | 66 |
73 // This number was obtained by the Net.Predictor.MRUIndex histogram on Canary | 67 // This number was obtained by the Net.Predictor.MRUIndex histogram on Canary |
74 // and Dev channel (M53). The database size was initialized to 1000, and the | 68 // and Dev channel (M53). The database size was initialized to 1000, and the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
122 } | 116 } |
123 | 117 |
124 Predictor::~Predictor() { | 118 Predictor::~Predictor() { |
125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 119 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
126 DCHECK(shutdown_); | 120 DCHECK(shutdown_); |
127 } | 121 } |
128 | 122 |
129 // static | 123 // static |
130 Predictor* Predictor::CreatePredictor(bool simple_shutdown) { | 124 Predictor* Predictor::CreatePredictor(bool simple_shutdown) { |
131 bool predictor_enabled = base::FeatureList::IsEnabled(kNetworkPrediction); | 125 bool predictor_enabled = |
| 126 base::FeatureList::IsEnabled(features::kNetworkPrediction); |
132 if (simple_shutdown) | 127 if (simple_shutdown) |
133 return new SimplePredictor(predictor_enabled); | 128 return new SimplePredictor(predictor_enabled); |
134 return new Predictor(predictor_enabled); | 129 return new Predictor(predictor_enabled); |
135 } | 130 } |
136 | 131 |
137 void Predictor::RegisterProfilePrefs( | 132 void Predictor::RegisterProfilePrefs( |
138 user_prefs::PrefRegistrySyncable* registry) { | 133 user_prefs::PrefRegistrySyncable* registry) { |
139 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList, | 134 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList, |
140 PrefRegistry::LOSSY_PREF); | 135 PrefRegistry::LOSSY_PREF); |
141 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList, | 136 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList, |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 } | 1192 } |
1198 | 1193 |
1199 void SimplePredictor::ShutdownOnUIThread() { | 1194 void SimplePredictor::ShutdownOnUIThread() { |
1200 SetShutdown(true); | 1195 SetShutdown(true); |
1201 } | 1196 } |
1202 | 1197 |
1203 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1198 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
1204 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1199 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
1205 | 1200 |
1206 } // namespace chrome_browser_net | 1201 } // namespace chrome_browser_net |
OLD | NEW |