Chromium Code Reviews| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/prefs/proxy_prefs.h" | 11 #include "chrome/browser/prefs/proxy_prefs.h" |
| 11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "net/proxy/proxy_config.h" | |
| 14 #include "net/proxy/proxy_info.h" | |
| 15 #include "net/proxy/proxy_service.h" | |
| 12 | 16 |
| 13 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( | 17 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( |
| 14 PrefService* prefs) : prefs_(prefs) { | 18 PrefService* prefs, |
| 15 DCHECK(prefs); | 19 scoped_refptr<base::SequencedTaskRunner> network_task_runner) |
| 20 : prefs_(prefs), network_task_runner_(network_task_runner) { | |
| 16 } | 21 } |
| 17 | 22 |
| 18 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { | 23 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { |
| 19 } | 24 } |
| 20 | 25 |
| 21 void DataReductionProxyChromeConfigurator::Enable( | 26 void DataReductionProxyChromeConfigurator::Enable( |
| 22 bool primary_restricted, | 27 bool primary_restricted, |
| 23 bool fallback_restricted, | 28 bool fallback_restricted, |
| 24 const std::string& primary_origin, | 29 const std::string& primary_origin, |
| 25 const std::string& fallback_origin, | 30 const std::string& fallback_origin, |
| 26 const std::string& ssl_origin) { | 31 const std::string& ssl_origin) { |
| 27 DCHECK(prefs_); | 32 DCHECK(prefs_); |
| 28 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 33 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
| 34 // TODO(bengr): Consider relying on the proxy config for all data reduction | |
| 35 // proxy configuration. | |
| 29 base::DictionaryValue* dict = update.Get(); | 36 base::DictionaryValue* dict = update.Get(); |
| 30 | 37 |
| 31 std::vector<std::string> proxies; | 38 std::vector<std::string> proxies; |
| 32 if (!primary_restricted) { | 39 if (!primary_restricted) { |
| 33 std::string trimmed_primary; | 40 std::string trimmed_primary; |
| 34 base::TrimString(primary_origin, "/", &trimmed_primary); | 41 base::TrimString(primary_origin, "/", &trimmed_primary); |
| 35 if (!trimmed_primary.empty()) | 42 if (!trimmed_primary.empty()) |
| 36 proxies.push_back(trimmed_primary); | 43 proxies.push_back(trimmed_primary); |
| 37 } | 44 } |
| 38 if (!fallback_restricted) { | 45 if (!fallback_restricted) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 53 | 60 |
| 54 std::string trimmed_ssl; | 61 std::string trimmed_ssl; |
| 55 base::TrimString(ssl_origin, "/", &trimmed_ssl); | 62 base::TrimString(ssl_origin, "/", &trimmed_ssl); |
| 56 | 63 |
| 57 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" | 64 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" |
| 58 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); | 65 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); |
| 59 | 66 |
| 60 dict->SetString("server", server); | 67 dict->SetString("server", server); |
| 61 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 68 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
| 62 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 69 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
| 70 | |
| 71 net::ProxyConfig config; | |
| 72 config.proxy_rules().ParseFromString(server); | |
| 73 config.proxy_rules().bypass_rules.ParseFromString( | |
| 74 JoinString(bypass_rules_, ", ")); | |
| 75 // The ID is set to a bogus value. It cannot be left uninitialized, else the | |
| 76 // config will return invalid. | |
| 77 net::ProxyConfig::ID unused_id = 1; | |
| 78 config.set_id(unused_id); | |
|
Ryan Sleevi
2014/08/14 19:19:51
why not just set_id(1)? Why do you need to declare
| |
| 79 network_task_runner_->PostTask( | |
| 80 FROM_HERE, | |
| 81 base::Bind( | |
| 82 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | |
| 83 base::Unretained(this), | |
|
Ryan Sleevi
2014/08/14 19:19:50
This is a very dangerous usage.
No where in the h
| |
| 84 config)); | |
| 63 } | 85 } |
| 64 | 86 |
| 65 void DataReductionProxyChromeConfigurator::Disable() { | 87 void DataReductionProxyChromeConfigurator::Disable() { |
| 66 DCHECK(prefs_); | 88 DCHECK(prefs_); |
| 67 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 89 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
| 68 base::DictionaryValue* dict = update.Get(); | 90 base::DictionaryValue* dict = update.Get(); |
| 69 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 91 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| 70 dict->SetString("server", ""); | 92 dict->SetString("server", ""); |
| 71 dict->SetString("bypass_list", ""); | 93 dict->SetString("bypass_list", ""); |
|
Ryan Sleevi
2014/08/14 19:19:50
cleanup: These should all be std::string() instead
| |
| 94 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); | |
| 95 network_task_runner_->PostTask( | |
| 96 FROM_HERE, | |
| 97 base::Bind( | |
| 98 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | |
| 99 base::Unretained(this), | |
| 100 config)); | |
|
Ryan Sleevi
2014/08/14 19:19:50
Did git-cl-format do this? It seems odd for it.
| |
| 72 } | 101 } |
| 73 | 102 |
| 74 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( | 103 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( |
| 75 const std::string& pattern) { | 104 const std::string& pattern) { |
| 76 bypass_rules_.push_back(pattern); | 105 bypass_rules_.push_back(pattern); |
| 77 } | 106 } |
| 78 | 107 |
| 79 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( | 108 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
| 80 const std::string& pattern) { | 109 const std::string& pattern) { |
| 81 size_t pos = pattern.find('/'); | 110 size_t pos = pattern.find('/'); |
| 82 if (pattern.find('/', pos + 1) == pos + 1) | 111 if (pattern.find('/', pos + 1) == pos + 1) |
| 83 pos = pattern.find('/', pos + 2); | 112 pos = pattern.find('/', pos + 2); |
| 84 | 113 |
| 85 std::string host_pattern; | 114 std::string host_pattern; |
| 86 if (pos != std::string::npos) | 115 if (pos != std::string::npos) |
| 87 host_pattern = pattern.substr(0, pos); | 116 host_pattern = pattern.substr(0, pos); |
| 88 else | 117 else |
| 89 host_pattern = pattern; | 118 host_pattern = pattern; |
| 90 | 119 |
| 91 AddHostPatternToBypass(host_pattern); | 120 AddHostPatternToBypass(host_pattern); |
| 92 } | 121 } |
| 122 | |
| 123 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( | |
|
Ryan Sleevi
2014/08/14 19:19:50
If you decide to keep these methods (ideally, you
| |
| 124 const net::ProxyConfig& config) { | |
| 125 config_ = config; | |
| 126 } | |
| 127 | |
| 128 const net::ProxyConfig& | |
| 129 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { | |
| 130 return config_; | |
| 131 } | |
| OLD | NEW |