OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/profiles/net_http_session_params_observer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/io_thread.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/pref_registry/pref_registry_syncable.h" |
| 17 #include "components/prefs/pref_service.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 20 using content::BrowserThread; |
| 21 |
| 22 namespace { |
| 23 |
| 24 // Called on IOThread to disable QUIC for globally-owned HttpNetworkSessions |
| 25 // and for the profile (thrpugh |disable_quic_callback|). Note that re-enabling |
| 26 // QUIC dynamically is not supported for simpliciy and requires a browser |
| 27 // restart. |
| 28 void ApplySettingsOnIOThread( |
| 29 bool quic_allowed_for_profile, |
| 30 NetHttpSessionParamsObserver::DisableQuicCallback disable_quic_callback, |
| 31 IOThread* io_thread, |
| 32 safe_browsing::SafeBrowsingService* safe_browsing_service) { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 34 |
| 35 bool quic_allowed_on_io_thread = |
| 36 io_thread->NetworkSessionParams().enable_quic; |
| 37 |
| 38 // We only support disabling QUIC dynamically. As soon as it's been disabled |
| 39 // for IOThread, we are not re-enabling it. |
| 40 bool quic_allowed = quic_allowed_for_profile && quic_allowed_on_io_thread; |
| 41 |
| 42 if (!quic_allowed) { |
| 43 // Disable QUIC for globally-owned objects. |
| 44 io_thread->DisableQuic(); |
| 45 safe_browsing_service->DisableQuicOnIOThread(); |
| 46 |
| 47 // Call profile's disable QUIC callback. |
| 48 disable_quic_callback.Run(); |
| 49 } |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
| 54 NetHttpSessionParamsObserver::NetHttpSessionParamsObserver( |
| 55 PrefService* prefs, |
| 56 DisableQuicCallback disable_quic_callback) |
| 57 : disable_quic_callback_(disable_quic_callback) { |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 59 DCHECK(prefs); |
| 60 |
| 61 base::Closure prefs_callback = base::Bind( |
| 62 &NetHttpSessionParamsObserver::ApplySettings, base::Unretained(this)); |
| 63 quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback); |
| 64 |
| 65 // Apply the initial settings, in case QUIC is disallowed by policy on profile |
| 66 // initialization time. Note that even if this may not affect the profile |
| 67 // which is being initialized directly (as its URLRequestContext will not be |
| 68 // constructed yet), it still applies to globally-owned HttpNetworkSessions |
| 69 // and to IOThread's HttpNetworkSession Params, which will in turn be used as |
| 70 // a base for the new profile's URLRequestContext. |
| 71 ApplySettings(); |
| 72 } |
| 73 |
| 74 NetHttpSessionParamsObserver::~NetHttpSessionParamsObserver() { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 76 } |
| 77 |
| 78 void NetHttpSessionParamsObserver::ApplySettings() { |
| 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 80 |
| 81 bool quic_allowed_for_profile = true; |
| 82 if (quic_allowed_.IsManaged()) |
| 83 quic_allowed_for_profile = *quic_allowed_; |
| 84 |
| 85 // Disabling QUIC for a profile also disables QUIC for globally-owned |
| 86 // HttpNetworkSessions. As a side effect, new Profiles will also have QUIC |
| 87 // disabled (because they inherit IOThread's HttpNetworkSession Params). |
| 88 IOThread* io_thread = g_browser_process->io_thread(); |
| 89 safe_browsing::SafeBrowsingService* safe_browsing_service = |
| 90 g_browser_process->safe_browsing_service(); |
| 91 |
| 92 BrowserThread::PostTask( |
| 93 BrowserThread::IO, FROM_HERE, |
| 94 base::Bind(ApplySettingsOnIOThread, quic_allowed_for_profile, |
| 95 disable_quic_callback_, io_thread, |
| 96 base::Unretained(safe_browsing_service))); |
| 97 } |
| 98 |
| 99 // static |
| 100 void NetHttpSessionParamsObserver::RegisterProfilePrefs( |
| 101 user_prefs::PrefRegistrySyncable* registry) { |
| 102 registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
| 103 } |
OLD | NEW |