Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: chrome/browser/net/net_pref_observer.cc

Issue 2546533003: Respect QuicAllowed policy for new streams (Closed)
Patch Set: Reviewers' feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(
mmenke 2017/01/03 18:47:26 Do we really need a class for this? Profile[Impl]
pmarko 2017/01/03 19:30:48 Hm, I don't really have a strong opinion on this.
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_by_policy = true;
50 if (quic_allowed_.IsManaged()) {
51 quic_allowed_by_policy = *quic_allowed_;
52 }
53
54 // If QUIC has already been disabled, don't re-enable it. Currently,
55 // re-enabling QUIC requires a restart. If we want to support re-enabling QUIC
56 // dynamically, we'd have to enable it only if all active profiles allow QUIC.
57 // We'd also need to evaluate command-line switches::kDisableQuic here.
58 if (quic_allowed_by_policy)
59 return;
60
61 NetParamsChange net_params_change;
62 net_params_change.quic_enabled_new = false;
63 update_net_params_callback_.Run(net_params_change);
64
65 // Apply settings for globally owned HttpNetworkSessions.
66 if (g_browser_process->safe_browsing_service()) {
67 g_browser_process->safe_browsing_service()->UpdateNetParams(
68 net_params_change);
69 }
70
71 BrowserThread::PostTask(
72 BrowserThread::IO, FROM_HERE,
73 base::Bind(&NetPrefObserver::ApplySettingsOnIOThread,
74 base::Unretained(this), io_thread, net_params_change));
75 }
76
77 void NetPrefObserver::ApplySettingsOnIOThread(
78 IOThread* io_thread,
79 NetParamsChange net_params_change) {
80 DCHECK_CURRENTLY_ON(BrowserThread::IO);
81
82 io_thread->UpdateNetworkSessionParams(net_params_change.quic_enabled_new);
83 }
84
85 // static
86 void NetPrefObserver::RegisterProfilePrefs(
87 user_prefs::PrefRegistrySyncable* registry) {
88 registry->RegisterBooleanPref(prefs::kQuicAllowed, true);
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698