Index: chrome/browser/net/net_pref_observer.cc |
diff --git a/chrome/browser/net/net_pref_observer.cc b/chrome/browser/net/net_pref_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e833b56e2d08e331290fadd09b147e061bcaa47c |
--- /dev/null |
+++ b/chrome/browser/net/net_pref_observer.cc |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/net/net_pref_observer.h" |
+ |
+#include "base/bind.h" |
+#include "base/command_line.h" |
+#include "base/logging.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/io_thread.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.h" |
+#include "components/network_session_configurator/network_session_configurator.h" |
+#include "components/pref_registry/pref_registry_syncable.h" |
+#include "components/prefs/pref_service.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+#include "net/http/http_network_session.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace { |
+ |
+void SetQuicEnabledOnIOThread(IOThread* io_thread, |
+ bool quic_allowed_by_policy) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ net::HttpNetworkSession::DynamicSharedParams* dynamic_shared_params = |
+ io_thread->globals()->http_network_session_dynamic_shared_params.get(); |
+ |
+ // If QUIC has already been disabled, don't re-enable it. Currently, |
+ // re-enabling QUIC requires a restart. If we want to support re-enabling QUIC |
+ // dynamically, it would either have to be per-profile, or we'd have to |
+ // enable it only if all active profiles allow QUIC. |
+ // We'd also need to evaluated command-line switches::kDisableQuic here. |
Bence
2016/12/20 14:58:07
s/evaluated/evaluate/
pmarko
2016/12/20 18:00:37
Done.
|
+ dynamic_shared_params->enable_quic &= quic_allowed_by_policy; |
+} |
+ |
+} // namespace |
+ |
+NetPrefObserver::NetPrefObserver(PrefService* prefs) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ DCHECK(prefs); |
+ |
+ base::Closure prefs_callback = |
+ base::Bind(&NetPrefObserver::ApplySettings, base::Unretained(this)); |
+ quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback); |
+ |
+ ApplySettings(); |
+} |
+ |
+NetPrefObserver::~NetPrefObserver() { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+} |
+ |
+void NetPrefObserver::ApplySettings() { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ |
+ IOThread* io_thread = g_browser_process->io_thread(); |
+ if (!io_thread) |
+ return; |
+ |
+ bool quic_allowed_by_policy = true; |
+ if (quic_allowed_.IsManaged()) { |
+ quic_allowed_by_policy = *quic_allowed_; |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(SetQuicEnabledOnIOThread, io_thread, quic_allowed_by_policy)); |
+} |
+ |
+// static |
+void NetPrefObserver::RegisterProfilePrefs( |
+ user_prefs::PrefRegistrySyncable* registry) { |
+ registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
+} |