| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/prediction_options.h" | 5 #include "chrome/browser/net/prediction_options.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" |
| 8 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 10 #include "components/pref_registry/pref_registry_syncable.h" | 13 #include "components/pref_registry/pref_registry_syncable.h" |
| 11 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 12 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 14 | 17 |
| 15 namespace chrome_browser_net { | 18 namespace chrome_browser_net { |
| 16 | 19 |
| 20 const char kPreconnectOnly[] = "PreconnectOnly"; |
| 21 const char kStartServiceWorkerAndPreconnect[] = |
| 22 "StartServiceWorkerAndPreconnect"; |
| 23 const char kStartServiceWorkerAndDeferPreconnect[] = |
| 24 "StartServiceWorkerAndDeferPreconnect"; |
| 25 const char kStartServiceWorkerOnly[] = "StartServiceWorkerOnly"; |
| 26 |
| 17 namespace { | 27 namespace { |
| 18 | 28 |
| 19 // Since looking up preferences and current network connection are presumably | 29 // Since looking up preferences and current network connection are presumably |
| 20 // both cheap, we do not cache them here. | 30 // both cheap, we do not cache them here. |
| 21 NetworkPredictionStatus CanPrefetchAndPrerender( | 31 NetworkPredictionStatus CanPrefetchAndPrerender( |
| 22 int network_prediction_options) { | 32 int network_prediction_options) { |
| 23 switch (network_prediction_options) { | 33 switch (network_prediction_options) { |
| 24 case NETWORK_PREDICTION_ALWAYS: | 34 case NETWORK_PREDICTION_ALWAYS: |
| 25 case NETWORK_PREDICTION_WIFI_ONLY: | 35 case NETWORK_PREDICTION_WIFI_ONLY: |
| 26 if (net::NetworkChangeNotifier::IsConnectionCellular( | 36 if (net::NetworkChangeNotifier::IsConnectionCellular( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 profile_io_data->network_prediction_options()->GetValue()); | 83 profile_io_data->network_prediction_options()->GetValue()); |
| 74 } | 84 } |
| 75 | 85 |
| 76 bool CanPreresolveAndPreconnectUI(PrefService* prefs) { | 86 bool CanPreresolveAndPreconnectUI(PrefService* prefs) { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 78 DCHECK(prefs); | 88 DCHECK(prefs); |
| 79 return CanPreresolveAndPreconnect( | 89 return CanPreresolveAndPreconnect( |
| 80 prefs->GetInteger(prefs::kNetworkPredictionOptions)); | 90 prefs->GetInteger(prefs::kNetworkPredictionOptions)); |
| 81 } | 91 } |
| 82 | 92 |
| 93 NetworkPredictionOptionsForServiceWorker |
| 94 GetNetworkPredictionOptionsForServiceWorker() { |
| 95 const base::CommandLine& command_line = |
| 96 *base::CommandLine::ForCurrentProcess(); |
| 97 std::string options = command_line.GetSwitchValueASCII( |
| 98 switches::kNetworkPredictionOptionsForServiceWorker); |
| 99 if (options.empty()) { |
| 100 options = base::FieldTrialList::FindFullName( |
| 101 "NetworkPredictionOptionsForServiceWorker"); |
| 102 } |
| 103 |
| 104 if (options == kPreconnectOnly) { |
| 105 return NetworkPredictionOptionsForServiceWorker::PRECONNECT_ONLY; |
| 106 } else if (options == kStartServiceWorkerAndPreconnect) { |
| 107 return NetworkPredictionOptionsForServiceWorker:: |
| 108 START_SERVICE_WORKER_AND_PRECONNECT; |
| 109 } else if (options == kStartServiceWorkerAndDeferPreconnect) { |
| 110 return NetworkPredictionOptionsForServiceWorker:: |
| 111 START_SERVICE_WORKER_AND_DEFER_PRECONNECT; |
| 112 } else if (options == kStartServiceWorkerOnly) { |
| 113 return NetworkPredictionOptionsForServiceWorker::START_SERVICE_WORKER_ONLY; |
| 114 } else { |
| 115 return NetworkPredictionOptionsForServiceWorker::PRECONNECT_ONLY; |
| 116 } |
| 117 } |
| 118 |
| 83 } // namespace chrome_browser_net | 119 } // namespace chrome_browser_net |
| OLD | NEW |