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 "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" | 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" |
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
18 #include "components/variations/variations_associated_data.h" | 18 #include "components/variations/variations_associated_data.h" |
19 #include "net/proxy/proxy_server.h" | 19 #include "net/proxy/proxy_server.h" |
20 #include "url/url_constants.h" | 20 #include "url/url_constants.h" |
21 | 21 |
| 22 #if defined(OS_ANDROID) |
| 23 #include "base/android/build_info.h" |
| 24 #endif |
| 25 |
22 using base::FieldTrialList; | 26 using base::FieldTrialList; |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const char kEnabled[] = "Enabled"; | 30 const char kEnabled[] = "Enabled"; |
27 const char kControl[] = "Control"; | 31 const char kControl[] = "Control"; |
28 const char kDisabled[] = "Disabled"; | 32 const char kDisabled[] = "Disabled"; |
29 const char kLitePage[] = "Enabled_Preview"; | 33 const char kLitePage[] = "Enabled_Preview"; |
30 const char kDefaultSpdyOrigin[] = "https://proxy.googlezip.net:443"; | 34 const char kDefaultSpdyOrigin[] = "https://proxy.googlezip.net:443"; |
31 // A one-off change, until the Data Reduction Proxy configuration service is | 35 // A one-off change, until the Data Reduction Proxy configuration service is |
32 // available. | 36 // available. |
33 const char kCarrierTestOrigin[] = | 37 const char kCarrierTestOrigin[] = |
34 "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80"; | 38 "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80"; |
35 const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; | 39 const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; |
36 const char kDefaultSecureProxyCheckUrl[] = "http://check.googlezip.net/connect"; | 40 const char kDefaultSecureProxyCheckUrl[] = "http://check.googlezip.net/connect"; |
37 const char kDefaultWarmupUrl[] = "http://check.googlezip.net/generate_204"; | 41 const char kDefaultWarmupUrl[] = "http://check.googlezip.net/generate_204"; |
38 | 42 |
39 const char kAndroidOneIdentifier[] = "sprout"; | |
40 | |
41 const char kQuicFieldTrial[] = "DataReductionProxyUseQuic"; | 43 const char kQuicFieldTrial[] = "DataReductionProxyUseQuic"; |
42 | 44 |
43 const char kLoFiFieldTrial[] = "DataCompressionProxyLoFi"; | 45 const char kLoFiFieldTrial[] = "DataCompressionProxyLoFi"; |
44 const char kLoFiFlagFieldTrial[] = "DataCompressionProxyLoFiFlag"; | 46 const char kLoFiFlagFieldTrial[] = "DataCompressionProxyLoFiFlag"; |
45 | 47 |
46 const char kBlackListTransitionFieldTrial[] = | 48 const char kBlackListTransitionFieldTrial[] = |
47 "DataReductionProxyPreviewsBlackListTransition"; | 49 "DataReductionProxyPreviewsBlackListTransition"; |
48 | 50 |
49 const char kTrustedSpdyProxyFieldTrialName[] = "DataReductionTrustedSpdyProxy"; | 51 const char kTrustedSpdyProxyFieldTrialName[] = "DataReductionTrustedSpdyProxy"; |
50 | 52 |
(...skipping 22 matching lines...) Expand all Loading... |
73 std::string GetStringValueForVariationParamWithDefaultValue( | 75 std::string GetStringValueForVariationParamWithDefaultValue( |
74 const std::map<std::string, std::string>& variation_params, | 76 const std::map<std::string, std::string>& variation_params, |
75 const std::string& parameter_name, | 77 const std::string& parameter_name, |
76 const std::string& default_value) { | 78 const std::string& default_value) { |
77 const auto it = variation_params.find(parameter_name); | 79 const auto it = variation_params.find(parameter_name); |
78 if (it == variation_params.end()) | 80 if (it == variation_params.end()) |
79 return default_value; | 81 return default_value; |
80 return it->second; | 82 return it->second; |
81 } | 83 } |
82 | 84 |
| 85 bool IsIncludedInAndroidOnePromoFieldTrial( |
| 86 base::StringPiece build_fingerprint) { |
| 87 static const char kAndroidOneIdentifier[] = "sprout"; |
| 88 return build_fingerprint.find(kAndroidOneIdentifier) != std::string::npos; |
| 89 } |
| 90 |
83 } // namespace | 91 } // namespace |
84 | 92 |
85 namespace data_reduction_proxy { | 93 namespace data_reduction_proxy { |
86 namespace params { | 94 namespace params { |
87 | 95 |
88 bool IsIncludedInPromoFieldTrial() { | 96 bool IsIncludedInPromoFieldTrial() { |
89 return IsIncludedInFieldTrial("DataCompressionProxyPromoVisibility"); | 97 if (IsIncludedInFieldTrial("DataCompressionProxyPromoVisibility")) |
| 98 return true; |
| 99 |
| 100 #if defined(OS_ANDROID) |
| 101 base::StringPiece android_build_fingerprint = |
| 102 base::android::BuildInfo::GetInstance()->android_build_fp(); |
| 103 |
| 104 return IsIncludedInAndroidOnePromoFieldTrial(android_build_fingerprint); |
| 105 #endif |
| 106 return false; |
| 107 } |
| 108 |
| 109 bool IsIncludedInAndroidOnePromoFieldTrialForTesting( |
| 110 base::StringPiece build_fingerprint) { |
| 111 return IsIncludedInAndroidOnePromoFieldTrial(build_fingerprint); |
90 } | 112 } |
91 | 113 |
92 bool IsIncludedInHoldbackFieldTrial() { | 114 bool IsIncludedInHoldbackFieldTrial() { |
93 return IsIncludedInFieldTrial("DataCompressionProxyHoldback"); | 115 return IsIncludedInFieldTrial("DataCompressionProxyHoldback"); |
94 } | 116 } |
95 | 117 |
96 bool IsIncludedInAndroidOnePromoFieldTrial( | |
97 base::StringPiece build_fingerprint) { | |
98 return build_fingerprint.find(kAndroidOneIdentifier) != std::string::npos; | |
99 } | |
100 | |
101 const char* GetTrustedSpdyProxyFieldTrialName() { | 118 const char* GetTrustedSpdyProxyFieldTrialName() { |
102 return kTrustedSpdyProxyFieldTrialName; | 119 return kTrustedSpdyProxyFieldTrialName; |
103 } | 120 } |
104 | 121 |
105 bool IsIncludedInTrustedSpdyProxyFieldTrial() { | 122 bool IsIncludedInTrustedSpdyProxyFieldTrial() { |
106 return IsIncludedInFieldTrial(GetTrustedSpdyProxyFieldTrialName()); | 123 return IsIncludedInFieldTrial(GetTrustedSpdyProxyFieldTrialName()); |
107 } | 124 } |
108 | 125 |
109 const char* GetLoFiFieldTrialName() { | 126 const char* GetLoFiFieldTrialName() { |
110 return kLoFiFieldTrial; | 127 return kLoFiFieldTrial; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 416 |
400 } // namespace params | 417 } // namespace params |
401 | 418 |
402 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() : proxy_index(0) {} | 419 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() : proxy_index(0) {} |
403 | 420 |
404 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo( | 421 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo( |
405 const DataReductionProxyTypeInfo& other) = default; | 422 const DataReductionProxyTypeInfo& other) = default; |
406 | 423 |
407 DataReductionProxyTypeInfo::~DataReductionProxyTypeInfo() {} | 424 DataReductionProxyTypeInfo::~DataReductionProxyTypeInfo() {} |
408 | 425 |
409 DataReductionProxyParams::DataReductionProxyParams(int flags) | 426 DataReductionProxyParams::DataReductionProxyParams() |
410 : DataReductionProxyParams(flags, true) {} | 427 : DataReductionProxyParams(true) {} |
411 | 428 |
412 DataReductionProxyParams::~DataReductionProxyParams() {} | 429 DataReductionProxyParams::~DataReductionProxyParams() {} |
413 | 430 |
414 DataReductionProxyParams::DataReductionProxyParams(int flags, | 431 DataReductionProxyParams::DataReductionProxyParams(bool should_call_init) |
415 bool should_call_init) | 432 : use_override_proxies_for_http_(false) { |
416 : promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), | |
417 holdback_((flags & kHoldback) == kHoldback), | |
418 use_override_proxies_for_http_(false) { | |
419 if (should_call_init) { | 433 if (should_call_init) { |
420 bool result = Init(); | 434 bool result = Init(); |
421 DCHECK(result); | 435 DCHECK(result); |
422 } | 436 } |
423 } | 437 } |
424 | 438 |
425 void DataReductionProxyParams::SetProxiesForHttpForTesting( | 439 void DataReductionProxyParams::SetProxiesForHttpForTesting( |
426 const std::vector<DataReductionProxyServer>& proxies_for_http) { | 440 const std::vector<DataReductionProxyServer>& proxies_for_http) { |
427 proxies_for_http_ = proxies_for_http; | 441 proxies_for_http_ = proxies_for_http; |
428 } | 442 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 return override_data_reduction_proxy_servers_; | 512 return override_data_reduction_proxy_servers_; |
499 return proxies_for_http_; | 513 return proxies_for_http_; |
500 } | 514 } |
501 | 515 |
502 // Returns the URL to check to decide if the secure proxy origin should be | 516 // Returns the URL to check to decide if the secure proxy origin should be |
503 // used. | 517 // used. |
504 const GURL& DataReductionProxyParams::secure_proxy_check_url() const { | 518 const GURL& DataReductionProxyParams::secure_proxy_check_url() const { |
505 return secure_proxy_check_url_; | 519 return secure_proxy_check_url_; |
506 } | 520 } |
507 | 521 |
508 // Returns true if the data reduction proxy promo may be shown. | |
509 // This is idependent of whether the data reduction proxy is allowed. | |
510 // TODO(bengr): maybe tie to whether proxy is allowed. | |
511 bool DataReductionProxyParams::promo_allowed() const { | |
512 return promo_allowed_; | |
513 } | |
514 | |
515 // Returns true if the data reduction proxy should not actually use the | |
516 // proxy if enabled. | |
517 bool DataReductionProxyParams::holdback() const { | |
518 return holdback_; | |
519 } | |
520 | |
521 // TODO(kundaji): Remove tests for macro definitions. | 522 // TODO(kundaji): Remove tests for macro definitions. |
522 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 523 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
523 const base::CommandLine& command_line = | 524 const base::CommandLine& command_line = |
524 *base::CommandLine::ForCurrentProcess(); | 525 *base::CommandLine::ForCurrentProcess(); |
525 if (command_line.HasSwitch(switches::kEnableDataReductionProxyCarrierTest)) | 526 if (command_line.HasSwitch(switches::kEnableDataReductionProxyCarrierTest)) |
526 return kCarrierTestOrigin; | 527 return kCarrierTestOrigin; |
527 return kDefaultSpdyOrigin; | 528 return kDefaultSpdyOrigin; |
528 } | 529 } |
529 | 530 |
530 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 531 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
531 return kDefaultFallbackOrigin; | 532 return kDefaultFallbackOrigin; |
532 } | 533 } |
533 | 534 |
534 std::string DataReductionProxyParams::GetDefaultSecureProxyCheckURL() const { | 535 std::string DataReductionProxyParams::GetDefaultSecureProxyCheckURL() const { |
535 return kDefaultSecureProxyCheckUrl; | 536 return kDefaultSecureProxyCheckUrl; |
536 } | 537 } |
537 | 538 |
538 | 539 |
539 } // namespace data_reduction_proxy | 540 } // namespace data_reduction_proxy |
OLD | NEW |