OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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/net/net_pref_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 #include "net/http/http_network_session.h" |
| 21 |
| 22 using content::BrowserThread; |
| 23 |
| 24 NetPrefObserver::NetPrefObserver( |
| 25 PrefService* prefs, |
| 26 UpdateNetParamsCallback update_net_params_callback) |
| 27 : update_net_params_callback_(update_net_params_callback) { |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 29 DCHECK(prefs); |
| 30 |
| 31 base::Closure prefs_callback = |
| 32 base::Bind(&NetPrefObserver::ApplySettings, base::Unretained(this)); |
| 33 quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback); |
| 34 |
| 35 ApplySettings(); |
| 36 } |
| 37 |
| 38 NetPrefObserver::~NetPrefObserver() { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 } |
| 41 |
| 42 void NetPrefObserver::ApplySettings() { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 44 |
| 45 IOThread* io_thread = g_browser_process->io_thread(); |
| 46 if (!io_thread) |
| 47 return; |
| 48 |
| 49 bool quic_allowed_for_profile = true; |
| 50 if (quic_allowed_.IsManaged()) |
| 51 quic_allowed_for_profile = *quic_allowed_; |
| 52 |
| 53 BrowserThread::PostTask( |
| 54 BrowserThread::IO, FROM_HERE, |
| 55 base::Bind(&NetPrefObserver::ApplySettingsOnIOThread, |
| 56 base::Unretained(this), io_thread, |
| 57 base::Unretained(g_browser_process->safe_browsing_service()), |
| 58 quic_allowed_for_profile)); |
| 59 } |
| 60 |
| 61 void NetPrefObserver::ApplySettingsOnIOThread( |
| 62 IOThread* io_thread, |
| 63 safe_browsing::SafeBrowsingService* safe_browsing_service, |
| 64 bool quic_allowed_for_profile) { |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 66 |
| 67 // Never re-enable QUIC if it was disallowed on startup, e.g. due to command |
| 68 // line flags. |
| 69 bool quic_allowed_on_startup = io_thread->NetworkSessionParams().enable_quic; |
| 70 if (!quic_allowed_on_startup) |
| 71 return; |
| 72 |
| 73 net::HttpNetworkSession::ParamsUpdate params_update; |
| 74 params_update.enable_quic_new = quic_allowed_for_profile; |
| 75 |
| 76 // Make the profile adhere to its current setting by invoking its callback. |
| 77 update_net_params_callback_.Run(params_update); |
| 78 |
| 79 // Globally-owned HttpNetworkSessions should only be updated if QUIC is being |
| 80 // turned off. This "kill switch"-like behavior prevents multiple Profiles |
| 81 // fighting over QUIC enablement for global HttpNetworkSessions. |
| 82 if (!quic_allowed_for_profile) { |
| 83 io_thread->UpdateNetworkSessionParams(params_update); |
| 84 |
| 85 safe_browsing_service->UpdateNetParamsOnIOThread(params_update); |
| 86 } |
| 87 } |
| 88 |
| 89 // static |
| 90 void NetPrefObserver::RegisterProfilePrefs( |
| 91 user_prefs::PrefRegistrySyncable* registry) { |
| 92 registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
| 93 } |
OLD | NEW |