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.
5 #include "chrome/browser/net/net_pref_observer.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/net/predictor.h"
10 #include "chrome/browser/prerender/prerender_manager.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/user_prefs/pref_registry_syncable.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "net/http/http_stream_factory.h"
16 using content::BrowserThread
;
18 NetPrefObserver::NetPrefObserver(PrefService
* prefs
,
19 prerender::PrerenderManager
* prerender_manager
,
20 chrome_browser_net::Predictor
* predictor
)
21 : prerender_manager_(prerender_manager
),
22 predictor_(predictor
) {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
27 base::Closure prefs_callback
= base::Bind(&NetPrefObserver::ApplySettings
,
28 base::Unretained(this));
29 network_prediction_enabled_
.Init(prefs::kNetworkPredictionEnabled
, prefs
,
31 spdy_disabled_
.Init(prefs::kDisableSpdy
, prefs
, prefs_callback
);
36 NetPrefObserver::~NetPrefObserver() {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
40 void NetPrefObserver::ApplySettings() {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
43 predictor_
->EnablePredictor(*network_prediction_enabled_
);
44 if (prerender_manager_
)
45 prerender_manager_
->set_enabled(*network_prediction_enabled_
);
46 if (spdy_disabled_
.IsManaged())
47 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_
);
51 void NetPrefObserver::RegisterProfilePrefs(
52 user_prefs::PrefRegistrySyncable
* registry
) {
53 registry
->RegisterBooleanPref(
54 prefs::kNetworkPredictionEnabled
,
56 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
57 registry
->RegisterBooleanPref(
60 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);