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

Unified Diff: chrome/browser/net/net_pref_observer.cc

Issue 2546533003: Respect QuicAllowed policy for new streams (Closed)
Patch Set: Fixed accesses to iothread globals from UI thread Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/net_pref_observer.cc
diff --git a/chrome/browser/net/net_pref_observer.cc b/chrome/browser/net/net_pref_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bfd3f26d66a12ea7bdd92f67b4d46b22ff9d89ad
--- /dev/null
+++ b/chrome/browser/net/net_pref_observer.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/net_pref_observer.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/io_thread.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"
+
Bence 2016/12/02 18:53:25 Please remove this empty line. (Did you remember
pmarko 2016/12/08 17:01:59 Done.
+#include "net/http/http_network_session.h"
+
+using content::BrowserThread;
+
+namespace {
+
+void SetQuicAllowedOnIOThread(IOThread* io_thread, bool quic_allowed) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ net::HttpNetworkSession::SharedParams* shared_params =
Bence 2016/12/02 18:53:25 Move this line two spaces to the left please.
pmarko 2016/12/08 17:01:59 Done.
+ io_thread->globals()->http_network_session_shared_params.get();
+
+ shared_params->enable_quic_for_new_streams = quic_allowed;
Bence 2016/12/02 18:53:25 Move this line two spaces to the left please.
pmarko 2016/12/08 17:01:59 Done.
+}
+
+} // namespace
+
+NetPrefObserver::NetPrefObserver(PrefService* prefs) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(prefs);
+
+ base::Closure prefs_callback = base::Bind(&NetPrefObserver::ApplySettings,
Bence 2016/12/02 18:53:25 Please run git cl format to reformat this line.
pmarko 2016/12/08 17:01:59 Done.
+ base::Unretained(this));
+ quic_allowed_.Init(prefs::kQuicAllowed, prefs, prefs_callback);
+
+ ApplySettings();
+}
+
+NetPrefObserver::~NetPrefObserver() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+}
+
+void NetPrefObserver::ApplySettings() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ IOThread* io_thread = g_browser_process->io_thread();
+ if (io_thread) {
Bence 2016/12/02 18:53:25 Maybe do early return instead? if (!io_thread) {
pmarko 2016/12/08 17:01:59 Good idea, thanks! Done.
+ bool quic_allowed = true;
+ if (quic_allowed_.IsManaged()) {
+ quic_allowed = *quic_allowed_;
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
Bence 2016/12/02 18:53:25 Merge with previous line.
pmarko 2016/12/08 17:01:59 Done.
+ base::Bind(SetQuicAllowedOnIOThread, io_thread, quic_allowed));
+ }
+}
+
+// static
+void NetPrefObserver::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(prefs::kQuicAllowed, true);
+}

Powered by Google App Engine
This is Rietveld 408576698