OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/spdyproxy/data_reduction_proxy_chrome_configurator. h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator. h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 60 |
61 std::string trimmed_ssl; | 61 std::string trimmed_ssl; |
62 base::TrimString(ssl_origin, "/", &trimmed_ssl); | 62 base::TrimString(ssl_origin, "/", &trimmed_ssl); |
63 | 63 |
64 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" | 64 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" |
65 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); | 65 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); |
66 | 66 |
67 dict->SetString("server", server); | 67 dict->SetString("server", server); |
68 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 68 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
69 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 69 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
70 dict->SetBoolean("is_data_reduction_proxy", true); | |
bengr
2014/10/27 23:28:01
How about "use_with_off_the_record", false
Not at Google. Contact bengr
2014/10/28 19:51:03
Discussed in person. Odd to use a label which is n
| |
70 | 71 |
71 net::ProxyConfig config; | 72 net::ProxyConfig config; |
72 config.proxy_rules().ParseFromString(server); | 73 config.proxy_rules().ParseFromString(server); |
73 config.proxy_rules().bypass_rules.ParseFromString( | 74 config.proxy_rules().bypass_rules.ParseFromString( |
74 JoinString(bypass_rules_, ", ")); | 75 JoinString(bypass_rules_, ", ")); |
75 // The ID is set to a bogus value. It cannot be left uninitialized, else the | 76 // The ID is set to a bogus value. It cannot be left uninitialized, else the |
76 // config will return invalid. | 77 // config will return invalid. |
77 net::ProxyConfig::ID unused_id = 1; | 78 net::ProxyConfig::ID unused_id = 1; |
78 config.set_id(unused_id); | 79 config.set_id(unused_id); |
79 network_task_runner_->PostTask( | 80 network_task_runner_->PostTask( |
80 FROM_HERE, | 81 FROM_HERE, |
81 base::Bind( | 82 base::Bind( |
82 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 83 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
83 base::Unretained(this), | 84 base::Unretained(this), |
84 config)); | 85 config)); |
85 } | 86 } |
86 | 87 |
87 void DataReductionProxyChromeConfigurator::Disable() { | 88 void DataReductionProxyChromeConfigurator::Disable() { |
88 DCHECK(prefs_); | 89 DCHECK(prefs_); |
89 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 90 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
90 base::DictionaryValue* dict = update.Get(); | 91 base::DictionaryValue* dict = update.Get(); |
91 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 92 bool is_data_reduction_proxy = false; |
92 dict->SetString("server", ""); | 93 dict->GetBoolean("is_data_reduction_proxy", &is_data_reduction_proxy); |
bengr
2014/10/27 23:28:01
Please verify (and add a test) that this will get
Not at Google. Contact bengr
2014/10/28 19:51:03
This approach does not work since the dictionary d
| |
93 dict->SetString("bypass_list", ""); | 94 if (is_data_reduction_proxy) { |
bengr
2014/10/27 23:28:01
if (!is_data_reduction_proxy)
return;
Not at Google. Contact bengr
2014/10/28 19:51:03
Done.
| |
94 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); | 95 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
95 network_task_runner_->PostTask( | 96 dict->SetString("server", ""); |
96 FROM_HERE, | 97 dict->SetString("bypass_list", ""); |
97 base::Bind( | 98 dict->SetBoolean("is_data_reduction_proxy", false); |
98 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 99 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
99 base::Unretained(this), | 100 network_task_runner_->PostTask( |
100 config)); | 101 FROM_HERE, |
102 base::Bind( | |
103 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | |
104 base::Unretained(this), | |
105 config)); | |
106 } | |
101 } | 107 } |
102 | 108 |
103 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( | 109 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( |
104 const std::string& pattern) { | 110 const std::string& pattern) { |
105 bypass_rules_.push_back(pattern); | 111 bypass_rules_.push_back(pattern); |
106 } | 112 } |
107 | 113 |
108 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( | 114 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
109 const std::string& pattern) { | 115 const std::string& pattern) { |
110 size_t pos = pattern.find('/'); | 116 size_t pos = pattern.find('/'); |
(...skipping 11 matching lines...) Expand all Loading... | |
122 | 128 |
123 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( | 129 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( |
124 const net::ProxyConfig& config) { | 130 const net::ProxyConfig& config) { |
125 config_ = config; | 131 config_ = config; |
126 } | 132 } |
127 | 133 |
128 const net::ProxyConfig& | 134 const net::ProxyConfig& |
129 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { | 135 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { |
130 return config_; | 136 return config_; |
131 } | 137 } |
OLD | NEW |