Chromium Code Reviews| Index: chrome/browser/profiles/net_http_session_params_observer.cc |
| diff --git a/chrome/browser/profiles/net_http_session_params_observer.cc b/chrome/browser/profiles/net_http_session_params_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea4100a9a1d5daefcbc0866340a94a71770895d4 |
| --- /dev/null |
| +++ b/chrome/browser/profiles/net_http_session_params_observer.cc |
| @@ -0,0 +1,99 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
mmenke
2017/01/09 16:46:04
2017, new files should not use the (c).
pmarko
2017/01/09 19:53:12
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/profiles/net_http_session_params_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" |
|
mmenke
2017/01/09 16:46:04
Not needed - included in header
pmarko
2017/01/09 19:53:12
Done.
|
| + |
| +using content::BrowserThread; |
| + |
| +namespace { |
| + |
| +void ApplySettingsOnIOThread( |
| + net::HttpNetworkSession::ParamsUpdate params_update, |
| + NetHttpSessionParamsObserver::UpdateNetParamsCallback callback, |
| + IOThread* io_thread, |
| + bool quic_allowed_for_profile) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + // Never re-enable QUIC if it was disallowed on startup, e.g. due to command |
| + // line flags. |
| + bool quic_allowed_on_startup = io_thread->NetworkSessionParams().enable_quic; |
|
mmenke
2017/01/09 16:46:04
This isn't actually whether quic was allowed on st
pmarko
2017/01/09 19:53:12
You're right about that. See my answer on the comm
|
| + if (!quic_allowed_on_startup) |
|
mmenke
2017/01/09 16:46:04
This is weird - if quic_allowed_on_startup is fals
pmarko
2017/01/09 19:53:12
You're right, we should always send out an update,
|
| + return; |
|
mmenke
2017/01/09 16:46:04
Hrm...Sorry I missed this when making my earlier s
pmarko
2017/01/09 19:53:12
Oh you're right, I also missed that. Probably that
|
| + |
| + // Make the profile adhere to its current setting by invoking its callback. |
| + callback.Run(params_update); |
| + |
| + // Globally-owned HttpNetworkSessions should only be updated if QUIC is being |
| + // turned off. This "kill switch"-like behavior prevents multiple Profiles |
| + // fighting over QUIC enablement for global HttpNetworkSessions. |
| + if (!quic_allowed_for_profile) |
| + io_thread->UpdateNetworkSessionParams(params_update); |
|
mmenke
2017/01/09 16:46:04
I wonder if we could simplify this method to somet
pmarko
2017/01/09 19:53:12
As discussed, simplified to sending out DisableQui
|
| +} |
| + |
| +} // namespace |
| + |
| +NetHttpSessionParamsObserver::NetHttpSessionParamsObserver( |
| + 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( |
| + &NetHttpSessionParamsObserver::ApplySettings, base::Unretained(this)); |
| + quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback); |
| + |
| + ApplySettings(); |
| +} |
| + |
| +NetHttpSessionParamsObserver::~NetHttpSessionParamsObserver() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| +} |
| + |
| +void NetHttpSessionParamsObserver::ApplySettings() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + IOThread* io_thread = g_browser_process->io_thread(); |
| + if (!io_thread) |
| + return; |
| + |
| + bool quic_allowed_for_profile = true; |
| + if (quic_allowed_.IsManaged()) |
| + quic_allowed_for_profile = *quic_allowed_; |
| + |
| + net::HttpNetworkSession::ParamsUpdate params_update; |
|
mmenke
2017/01/09 16:46:04
We're not setting params_update.quic_allowed. Hav
mmenke
2017/01/09 17:42:47
Oops, missed that we are, but we're just setting i
pmarko
2017/01/09 19:53:12
Actually, it is setting params_update.enable_quic_
pmarko
2017/01/09 19:53:12
As discussed, removing ParamsUpdate and just calli
|
| + params_update.enable_quic_new = quic_allowed_for_profile; |
| + |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(ApplySettingsOnIOThread, params_update, |
| + update_net_params_callback_, io_thread, |
| + quic_allowed_for_profile)); |
| + |
| + // Globally-owned HttpNetworkSessions should only be updated if QUIC is being |
| + // turned off. This "kill switch"-like behavior prevents multiple Profiles |
| + // fighting over QUIC enablement for global HttpNetworkSessions. |
| + if (!quic_allowed_for_profile && g_browser_process->safe_browsing_service()) |
| + g_browser_process->safe_browsing_service()->UpdateNetParams(params_update); |
| +} |
| + |
| +// static |
| +void NetHttpSessionParamsObserver::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterBooleanPref(prefs::kQuicAllowed, true); |
| +} |