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.h" | 8 #include "chrome/browser/net/predictor_api.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/browser/trials/http_throttling_trial.h" | 12 #include "chrome/browser/trials/http_throttling_trial.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
16 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
17 #include "net/http/http_stream_factory.h" | 17 #include "net/http/http_stream_factory.h" |
18 #include "net/url_request/url_request_throttler_manager.h" | 18 #include "net/url_request/url_request_throttler_manager.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Function (for NewRunnableFunction) to call the set_enforce_throttling | 22 // Function (for NewRunnableFunction) to call the set_enforce_throttling |
23 // member on the URLRequestThrottlerManager singleton. | 23 // member on the URLRequestThrottlerManager singleton. |
24 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { | 24 void SetEnforceThrottlingOnThrottlerManager(bool enforce) { |
25 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( | 25 net::URLRequestThrottlerManager::GetInstance()->set_enforce_throttling( |
26 enforce); | 26 enforce); |
27 } | 27 } |
28 | 28 |
29 } | 29 } |
30 | 30 |
31 NetPrefObserver::NetPrefObserver(PrefService* prefs, | 31 NetPrefObserver::NetPrefObserver(PrefService* prefs, |
32 prerender::PrerenderManager* prerender_manager, | 32 prerender::PrerenderManager* prerender_manager) |
33 chrome_browser_net::Predictor* predictor) | 33 : prerender_manager_(prerender_manager) { |
34 : prerender_manager_(prerender_manager), | |
35 predictor_(predictor) { | |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
37 DCHECK(prefs); | 35 DCHECK(prefs); |
38 DCHECK(predictor); | |
39 | |
40 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, | 36 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, prefs, |
41 this); | 37 this); |
42 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); | 38 spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); |
43 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); | 39 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); |
44 | 40 |
45 ApplySettings(NULL); | 41 ApplySettings(NULL); |
46 } | 42 } |
47 | 43 |
48 NetPrefObserver::~NetPrefObserver() { | 44 NetPrefObserver::~NetPrefObserver() { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
50 } | 46 } |
51 | 47 |
52 void NetPrefObserver::Observe(int type, | 48 void NetPrefObserver::Observe(int type, |
53 const NotificationSource& source, | 49 const NotificationSource& source, |
54 const NotificationDetails& details) { | 50 const NotificationDetails& details) { |
55 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); | 51 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); |
56 | 52 |
57 std::string* pref_name = Details<std::string>(details).ptr(); | 53 std::string* pref_name = Details<std::string>(details).ptr(); |
58 ApplySettings(pref_name); | 54 ApplySettings(pref_name); |
59 } | 55 } |
60 | 56 |
61 void NetPrefObserver::ApplySettings(const std::string* pref_name) { | 57 void NetPrefObserver::ApplySettings(const std::string* pref_name) { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
63 | 59 |
64 predictor_->EnablePredictor(*network_prediction_enabled_); | 60 chrome_browser_net::EnablePredictor(*network_prediction_enabled_); |
65 if (prerender_manager_) | 61 if (prerender_manager_) |
66 prerender_manager_->set_enabled(*network_prediction_enabled_); | 62 prerender_manager_->set_enabled(*network_prediction_enabled_); |
67 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); | 63 net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); |
68 | 64 |
69 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { | 65 if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { |
70 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
71 BrowserThread::IO, FROM_HERE, | 67 BrowserThread::IO, FROM_HERE, |
72 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, | 68 NewRunnableFunction(SetEnforceThrottlingOnThrottlerManager, |
73 *http_throttling_enabled_)); | 69 *http_throttling_enabled_)); |
74 } | 70 } |
(...skipping 11 matching lines...) Expand all Loading... |
86 false, | 82 false, |
87 PrefService::UNSYNCABLE_PREF); | 83 PrefService::UNSYNCABLE_PREF); |
88 prefs->RegisterBooleanPref(prefs::kHttpThrottlingMayExperiment, | 84 prefs->RegisterBooleanPref(prefs::kHttpThrottlingMayExperiment, |
89 true, | 85 true, |
90 PrefService::UNSYNCABLE_PREF); | 86 PrefService::UNSYNCABLE_PREF); |
91 | 87 |
92 // This is the earliest point at which we can set up the trial, as | 88 // This is the earliest point at which we can set up the trial, as |
93 // it relies on prefs for parameterization. | 89 // it relies on prefs for parameterization. |
94 CreateHttpThrottlingTrial(prefs); | 90 CreateHttpThrottlingTrial(prefs); |
95 } | 91 } |
OLD | NEW |