| 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, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 | 58 |
| 54 std::string trimmed_ssl; | 59 std::string trimmed_ssl; |
| 55 base::TrimString(ssl_origin, "/", &trimmed_ssl); | 60 base::TrimString(ssl_origin, "/", &trimmed_ssl); |
| 56 | 61 |
| 57 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" | 62 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" |
| 58 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); | 63 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); |
| 59 | 64 |
| 60 dict->SetString("server", server); | 65 dict->SetString("server", server); |
| 61 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 66 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
| 62 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 67 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
| 68 |
| 69 net::ProxyConfig config; |
| 70 config.proxy_rules().ParseFromString(server); |
| 71 config.proxy_rules().bypass_rules.ParseFromString( |
| 72 JoinString(bypass_rules_, ", ")); |
| 73 net::ProxyConfig::ID unused_id = 1; |
| 74 config.set_id(unused_id); |
| 75 network_task_runner_->PostTask( |
| 76 FROM_HERE, |
| 77 base::Bind( |
| 78 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
| 79 base::Unretained(this), |
| 80 config)); |
| 63 } | 81 } |
| 64 | 82 |
| 65 void DataReductionProxyChromeConfigurator::Disable() { | 83 void DataReductionProxyChromeConfigurator::Disable() { |
| 66 DCHECK(prefs_); | 84 DCHECK(prefs_); |
| 67 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 85 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
| 68 base::DictionaryValue* dict = update.Get(); | 86 base::DictionaryValue* dict = update.Get(); |
| 69 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 87 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| 70 dict->SetString("server", ""); | 88 dict->SetString("server", ""); |
| 71 dict->SetString("bypass_list", ""); | 89 dict->SetString("bypass_list", ""); |
| 90 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
| 91 network_task_runner_->PostTask( |
| 92 FROM_HERE, |
| 93 base::Bind( |
| 94 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
| 95 base::Unretained(this), |
| 96 config)); |
| 72 } | 97 } |
| 73 | 98 |
| 74 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( | 99 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( |
| 75 const std::string& pattern) { | 100 const std::string& pattern) { |
| 76 bypass_rules_.push_back(pattern); | 101 bypass_rules_.push_back(pattern); |
| 77 } | 102 } |
| 78 | 103 |
| 79 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( | 104 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
| 80 const std::string& pattern) { | 105 const std::string& pattern) { |
| 81 size_t pos = pattern.find('/'); | 106 size_t pos = pattern.find('/'); |
| 82 if (pattern.find('/', pos + 1) == pos + 1) | 107 if (pattern.find('/', pos + 1) == pos + 1) |
| 83 pos = pattern.find('/', pos + 2); | 108 pos = pattern.find('/', pos + 2); |
| 84 | 109 |
| 85 std::string host_pattern; | 110 std::string host_pattern; |
| 86 if (pos != std::string::npos) | 111 if (pos != std::string::npos) |
| 87 host_pattern = pattern.substr(0, pos); | 112 host_pattern = pattern.substr(0, pos); |
| 88 else | 113 else |
| 89 host_pattern = pattern; | 114 host_pattern = pattern; |
| 90 | 115 |
| 91 AddHostPatternToBypass(host_pattern); | 116 AddHostPatternToBypass(host_pattern); |
| 92 } | 117 } |
| 118 |
| 119 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( |
| 120 const net::ProxyConfig& config) { |
| 121 config_ = config; |
| 122 } |
| 123 |
| 124 const net::ProxyConfig& |
| 125 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { |
| 126 return config_; |
| 127 } |
| OLD | NEW |