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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/prefs/proxy_prefs.h" | 10 #include "chrome/browser/prefs/proxy_prefs.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 | 12 |
13 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( | 13 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( |
14 PrefService* prefs) : prefs_(prefs) { | 14 PrefService* prefs) : prefs_(prefs) { |
15 DCHECK(prefs); | 15 DCHECK(prefs); |
16 } | 16 } |
17 | 17 |
18 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { | 18 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { |
19 } | 19 } |
20 | 20 |
21 void DataReductionProxyChromeConfigurator::Enable(bool primary_restricted, | 21 void DataReductionProxyChromeConfigurator::Enable( |
22 bool fallback_restricted, | 22 bool primary_restricted, |
23 const std::string& primary_origin, | 23 bool fallback_restricted, |
24 const std::string& fallback_origin) { | 24 const std::string& primary_origin, |
| 25 const std::string& fallback_origin, |
| 26 const std::string& ssl_origin) { |
25 DCHECK(prefs_); | 27 DCHECK(prefs_); |
26 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 28 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
27 base::DictionaryValue* dict = update.Get(); | 29 base::DictionaryValue* dict = update.Get(); |
28 | 30 |
29 std::vector<std::string> proxies; | 31 std::vector<std::string> proxies; |
30 if (!primary_restricted) { | 32 if (!primary_restricted) { |
31 std::string trimmed_primary; | 33 std::string trimmed_primary; |
32 base::TrimString(primary_origin, "/", &trimmed_primary); | 34 base::TrimString(primary_origin, "/", &trimmed_primary); |
33 if (!trimmed_primary.empty()) | 35 if (!trimmed_primary.empty()) |
34 proxies.push_back(trimmed_primary); | 36 proxies.push_back(trimmed_primary); |
35 } | 37 } |
36 if (!fallback_restricted) { | 38 if (!fallback_restricted) { |
37 std::string trimmed_fallback; | 39 std::string trimmed_fallback; |
38 base::TrimString(fallback_origin, "/", &trimmed_fallback); | 40 base::TrimString(fallback_origin, "/", &trimmed_fallback); |
39 if (!trimmed_fallback.empty()) | 41 if (!trimmed_fallback.empty()) |
40 proxies.push_back(trimmed_fallback); | 42 proxies.push_back(trimmed_fallback); |
41 } | 43 } |
42 if (proxies.empty()) { | 44 if (proxies.empty()) { |
43 std::string mode; | 45 std::string mode; |
44 // If already in a disabled mode, do nothing. | 46 // If already in a disabled mode, do nothing. |
45 if (dict->GetString("mode", &mode)) | 47 if (dict->GetString("mode", &mode)) |
46 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) | 48 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) |
47 return; | 49 return; |
48 Disable(); | 50 Disable(); |
49 return; | 51 return; |
50 } | 52 } |
51 | 53 |
52 dict->SetString("server", "http=" + JoinString(proxies, ",") + ",direct://;"); | 54 std::string trimmed_ssl; |
| 55 base::TrimString(ssl_origin, "/", &trimmed_ssl); |
| 56 |
| 57 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" |
| 58 + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;")); |
| 59 |
| 60 dict->SetString("server", server); |
53 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 61 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
54 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 62 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
55 } | 63 } |
56 | 64 |
57 void DataReductionProxyChromeConfigurator::Disable() { | 65 void DataReductionProxyChromeConfigurator::Disable() { |
58 DCHECK(prefs_); | 66 DCHECK(prefs_); |
59 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 67 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
60 base::DictionaryValue* dict = update.Get(); | 68 base::DictionaryValue* dict = update.Get(); |
61 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 69 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
62 dict->SetString("server", ""); | 70 dict->SetString("server", ""); |
(...skipping 12 matching lines...) Expand all Loading... |
75 pos = pattern.find('/', pos + 2); | 83 pos = pattern.find('/', pos + 2); |
76 | 84 |
77 std::string host_pattern; | 85 std::string host_pattern; |
78 if (pos != std::string::npos) | 86 if (pos != std::string::npos) |
79 host_pattern = pattern.substr(0, pos); | 87 host_pattern = pattern.substr(0, pos); |
80 else | 88 else |
81 host_pattern = pattern; | 89 host_pattern = pattern; |
82 | 90 |
83 AddHostPatternToBypass(host_pattern); | 91 AddHostPatternToBypass(host_pattern); |
84 } | 92 } |
OLD | NEW |