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 DisableQuicOnIOThread( |
| 29 NetHttpSessionParamsObserver::DisableQuicCallback disable_quic_callback, |
| 30 IOThread* io_thread, |
| 31 safe_browsing::SafeBrowsingService* safe_browsing_service) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 33 |
| 34 // Disable QUIC for globally-owned objects. |
| 35 io_thread->DisableQuic(); |
| 36 safe_browsing_service->DisableQuicOnIOThread(); |
| 37 |
| 38 // Call profile's disable QUIC callback. |
| 39 disable_quic_callback.Run(); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 44 NetHttpSessionParamsObserver::NetHttpSessionParamsObserver( |
| 45 PrefService* prefs, |
| 46 DisableQuicCallback disable_quic_callback) |
| 47 : disable_quic_callback_(disable_quic_callback) { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 49 DCHECK(prefs); |
| 50 |
| 51 base::Closure prefs_callback = base::Bind( |
| 52 &NetHttpSessionParamsObserver::ApplySettings, base::Unretained(this)); |
| 53 quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback); |
| 54 |
| 55 // Apply the initial settings, in case QUIC is disallowed by policy on profile |
| 56 // initialization time. Note that even if this may not affect the profile |
| 57 // which is being initialized directly (as its URLRequestContext will not be |
| 58 // constructed yet), it still applies to globally-owned HttpNetworkSessions |
| 59 // and to IOThread's HttpNetworkSession Params, which will in turn be used as |
| 60 // a base for the new profile's URLRequestContext. |
| 61 ApplySettings(); |
| 62 } |
| 63 |
| 64 NetHttpSessionParamsObserver::~NetHttpSessionParamsObserver() { |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 66 } |
| 67 |
| 68 void NetHttpSessionParamsObserver::ApplySettings() { |
| 69 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 70 |
| 71 bool quic_allowed_for_profile = true; |
| 72 if (quic_allowed_.IsManaged()) |
| 73 quic_allowed_for_profile = *quic_allowed_; |
| 74 |
| 75 // We only support disabling QUIC. |
| 76 if (quic_allowed_for_profile) |
| 77 return; |
| 78 |
| 79 // Disabling QUIC for a profile also disables QUIC for globally-owned |
| 80 // HttpNetworkSessions. As a side effect, new Profiles will also have QUIC |
| 81 // disabled (because they inherit IOThread's HttpNetworkSession Params). |
| 82 IOThread* io_thread = g_browser_process->io_thread(); |
| 83 safe_browsing::SafeBrowsingService* safe_browsing_service = |
| 84 g_browser_process->safe_browsing_service(); |
| 85 |
| 86 BrowserThread::PostTask( |
| 87 BrowserThread::IO, FROM_HERE, |
| 88 base::Bind(&DisableQuicOnIOThread, disable_quic_callback_, io_thread, |
| 89 base::Unretained(safe_browsing_service))); |
| 90 } |
| 91 |
| 92 // static |
| 93 void NetHttpSessionParamsObserver::RegisterProfilePrefs( |
| 94 user_prefs::PrefRegistrySyncable* registry) { |
| 95 registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
| 96 } |
OLD | NEW |