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..7e92befd32dd51ce3fe4c4d8f4f26e8837379490 |
--- /dev/null |
+++ b/chrome/browser/net/net_pref_observer.cc |
@@ -0,0 +1,89 @@ |
+// 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/browser/profiles/profile_manager.h" |
+#include "chrome/browser/safe_browsing/safe_browsing_service.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.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; |
+ |
+NetPrefObserver::NetPrefObserver( |
+ PrefService* prefs, |
+ UpdateNetParamsCallback update_net_params_callback) |
+ : update_net_params_callback_(update_net_params_callback) { |
+ 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_; |
+ } |
+ |
+ // 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, we'd have to enable it only if all active profiles allow QUIC. |
+ // We'd also need to evaluate command-line switches::kDisableQuic here. |
+ if (quic_allowed_by_policy) |
+ return; |
+ |
+ NetParamsChange net_params_change; |
+ net_params_change.quic_enabled_new = false; |
+ update_net_params_callback_.Run(net_params_change); |
+ |
+ // Apply settings for globally owned HttpNetworkSessions |
Bence
2016/12/26 18:47:56
Please end this sentence with a period.
pmarko
2017/01/02 10:33:55
Done.
|
+ if (g_browser_process->safe_browsing_service()) { |
+ g_browser_process->safe_browsing_service()->UpdateNetParams( |
+ net_params_change); |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&NetPrefObserver::ApplySettingsOnIOThread, |
+ base::Unretained(this), io_thread, net_params_change)); |
+} |
+ |
+void NetPrefObserver::ApplySettingsOnIOThread( |
+ IOThread* io_thread, |
+ NetParamsChange net_params_change) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ io_thread->UpdateNetworkSessionParams(net_params_change.quic_enabled_new); |
+} |
+ |
+// static |
+void NetPrefObserver::RegisterProfilePrefs( |
+ user_prefs::PrefRegistrySyncable* registry) { |
+ registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
+} |