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