OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/net_pref_observer.h" | 5 #include "chrome/browser/net/net_pref_observer.h" |
6 | 6 |
7 #include "base/task.h" | 7 #include "base/task.h" |
8 #include "chrome/browser/net/predictor_api.h" | 8 #include "chrome/browser/browser_process.h" |
willchan no longer on Chromium
2011/08/10 16:10:35
What's this for?
rpetterson
2011/08/12 03:12:36
No longer necessary. Removed.
| |
9 #include "chrome/browser/net/predictor.h" | |
9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 11 #include "chrome/browser/prerender/prerender_manager.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | |
willchan no longer on Chromium
2011/08/10 16:10:35
What's this for?
rpetterson
2011/08/12 03:12:36
No longer necessary. Removed.
| |
12 #include "chrome/browser/trials/http_throttling_trial.h" | 14 #include "chrome/browser/trials/http_throttling_trial.h" |
13 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
15 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
16 #include "content/common/notification_details.h" | 18 #include "content/common/notification_details.h" |
17 #include "net/http/http_stream_factory.h" | 19 #include "net/http/http_stream_factory.h" |
18 #include "net/url_request/url_request_throttler_manager.h" | 20 #include "net/url_request/url_request_throttler_manager.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // Function (for NewRunnableFunction) to call the set_enforce_throttling | 24 // Function (for NewRunnableFunction) to call the set_enforce_throttling |
23 // member on the URLRequestThrottlerManager singleton. | 25 // member on the URLRequestThrottlerManager singleton. |
24 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { | 26 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { |
25 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( | 27 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( |
26 enforce); | 28 enforce); |
27 } | 29 } |
28 | 30 |
29 } | 31 } |
30 | 32 |
31 NetPrefObserver::NetPrefObserver(PrefService* prefs, | 33 NetPrefObserver::NetPrefObserver(PrefService* prefs, |
32 prerender::PrerenderManager* prerender_manager) | 34 prerender::PrerenderManager* prerender_manager, |
33 : prerender_manager_(prerender_manager) { | 35 chrome_browser_net::Predictor* predictor) |
36 : prerender_manager_(prerender_manager), | |
37 predictor_(predictor) { | |
willchan no longer on Chromium
2011/08/10 16:10:35
Is NetPrefObserver only used in ProfileImpl which
rpetterson
2011/08/12 03:12:36
NetPrefObserver::RegisterPrefs is called from brow
| |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 DCHECK(prefs); | 39 DCHECK(prefs); |
36 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, | 40 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, |
37 this); | 41 this); |
38 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); | 42 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); |
39 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); | 43 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); |
40 | 44 |
41 ApplySettings(NULL); | 45 ApplySettings(NULL); |
42 } | 46 } |
43 | 47 |
44 NetPrefObserver::~NetPrefObserver() { | 48 NetPrefObserver::~NetPrefObserver() { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
46 } | 50 } |
47 | 51 |
48 void NetPrefObserver::Observe(int type, | 52 void NetPrefObserver::Observe(int type, |
49 const NotificationSource& source, | 53 const NotificationSource& source, |
50 const NotificationDetails& details) { | 54 const NotificationDetails& details) { |
51 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); | 55 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); |
52 | 56 |
53 std::string* pref_name = Details<std::string>(details).ptr(); | 57 std::string* pref_name = Details<std::string>(details).ptr(); |
54 ApplySettings(pref_name); | 58 ApplySettings(pref_name); |
55 } | 59 } |
56 | 60 |
57 void NetPrefObserver::ApplySettings(const std::string* pref_name) { | 61 void NetPrefObserver::ApplySettings(const std::string* pref_name) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
59 | 63 |
60 chrome_browser_net::EnablePredictor(*network_prediction_enabled_); | 64 if (predictor_) |
65 predictor_->EnablePredictor(*network_prediction_enabled_); | |
61 if (prerender_manager_) | 66 if (prerender_manager_) |
62 prerender_manager_->set_enabled(*network_prediction_enabled_); | 67 prerender_manager_->set_enabled(*network_prediction_enabled_); |
63 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); | 68 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); |
64 | 69 |
65 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { | 70 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { |
66 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
67 BrowserThread::IO, FROM_HERE, | 72 BrowserThread::IO, FROM_HERE, |
68 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, | 73 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, |
69 *http_throttling_enabled_)); | 74 *http_throttling_enabled_)); |
70 } | 75 } |
(...skipping 11 matching lines...) Expand all Loading... | |
82 false, | 87 false, |
83 PrefService::UNSYNCABLE_PREF); | 88 PrefService::UNSYNCABLE_PREF); |
84 prefs->RegisterBooleanPref(prefs::kHttpThrottlingMayExperiment, | 89 prefs->RegisterBooleanPref(prefs::kHttpThrottlingMayExperiment, |
85 true, | 90 true, |
86 PrefService::UNSYNCABLE_PREF); | 91 PrefService::UNSYNCABLE_PREF); |
87 | 92 |
88 // This is the earliest point at which we can set up the trial, as | 93 // This is the earliest point at which we can set up the trial, as |
89 // it relies on prefs for parameterization. | 94 // it relies on prefs for parameterization. |
90 CreateHttpThrottlingTrial(prefs); | 95 CreateHttpThrottlingTrial(prefs); |
91 } | 96 } |
OLD | NEW |