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/net/predictor.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
15 #include "content/common/notification_details.h" | 15 #include "content/common/notification_details.h" |
16 #include "net/http/http_stream_factory.h" | 16 #include "net/http/http_stream_factory.h" |
17 #include "net/url_request/url_request_throttler_manager.h" | 17 #include "net/url_request/url_request_throttler_manager.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Function (for NewRunnableFunction) to call the set_enforce_throttling | 21 // Function (for NewRunnableFunction) to call the set_enforce_throttling |
22 // member on the URLRequestThrottlerManager singleton. | 22 // member on the URLRequestThrottlerManager singleton. |
23 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { | 23 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { |
24 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( | 24 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( |
25 enforce); | 25 enforce); |
26 } | 26 } |
27 | 27 |
28 } | 28 } |
29 | 29 |
30 NetPrefObserver::NetPrefObserver(PrefService* prefs, | 30 NetPrefObserver::NetPrefObserver(PrefService* prefs, |
31 prerender::PrerenderManager* prerender_manager) | 31 prerender::PrerenderManager* prerender_manager, |
32 : prerender_manager_(prerender_manager) { | 32 chrome_browser_net::Predictor* predictor) |
| 33 : prerender_manager_(prerender_manager), |
| 34 predictor_(predictor) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 DCHECK(prefs); | 36 DCHECK(prefs); |
| 37 DCHECK(predictor); |
| 38 |
35 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, | 39 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, |
36 this); | 40 this); |
37 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); | 41 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); |
38 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); | 42 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); |
39 | 43 |
40 ApplySettings(NULL); | 44 ApplySettings(NULL); |
41 } | 45 } |
42 | 46 |
43 NetPrefObserver::~NetPrefObserver() { | 47 NetPrefObserver::~NetPrefObserver() { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 } | 49 } |
46 | 50 |
47 void NetPrefObserver::Observe(int type, | 51 void NetPrefObserver::Observe(int type, |
48 const NotificationSource& source, | 52 const NotificationSource& source, |
49 const NotificationDetails& details) { | 53 const NotificationDetails& details) { |
50 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); | 54 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); |
51 | 55 |
52 std::string* pref_name = Details<std::string>(details).ptr(); | 56 std::string* pref_name = Details<std::string>(details).ptr(); |
53 ApplySettings(pref_name); | 57 ApplySettings(pref_name); |
54 } | 58 } |
55 | 59 |
56 void NetPrefObserver::ApplySettings(const std::string* pref_name) { | 60 void NetPrefObserver::ApplySettings(const std::string* pref_name) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 62 |
59 chrome_browser_net::EnablePredictor(*network_prediction_enabled_); | 63 predictor_->EnablePredictor(*network_prediction_enabled_); |
60 if (prerender_manager_) | 64 if (prerender_manager_) |
61 prerender_manager_->set_enabled(*network_prediction_enabled_); | 65 prerender_manager_->set_enabled(*network_prediction_enabled_); |
62 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); | 66 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); |
63 | 67 |
64 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { | 68 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { |
65 BrowserThread::PostTask( | 69 BrowserThread::PostTask( |
66 BrowserThread::IO, FROM_HERE, | 70 BrowserThread::IO, FROM_HERE, |
67 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, | 71 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, |
68 *http_throttling_enabled_)); | 72 *http_throttling_enabled_)); |
69 } | 73 } |
(...skipping 17 matching lines...) Expand all Loading... |
87 true, | 91 true, |
88 PrefService::UNSYNCABLE_PREF); | 92 PrefService::UNSYNCABLE_PREF); |
89 | 93 |
90 // For users who created their profile while throttling was off by | 94 // For users who created their profile while throttling was off by |
91 // default, but have never explicitly turned it on or off, we turn | 95 // default, but have never explicitly turned it on or off, we turn |
92 // it on which is the new default. | 96 // it on which is the new default. |
93 if (prefs->GetBoolean(prefs::kHttpThrottlingMayExperiment)) { | 97 if (prefs->GetBoolean(prefs::kHttpThrottlingMayExperiment)) { |
94 prefs->SetBoolean(prefs::kHttpThrottlingEnabled, true); | 98 prefs->SetBoolean(prefs::kHttpThrottlingEnabled, true); |
95 } | 99 } |
96 } | 100 } |
OLD | NEW |