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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/safe_sprintf.h" | 10 #include "base/strings/safe_sprintf.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_tokenizer.h" | 13 #include "base/strings/string_tokenizer.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" |
| 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu res.h" | |
| 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
| 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" |
| 23 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
| 24 #include "crypto/random.h" | 25 #include "crypto/random.h" |
| 25 #include "net/base/host_port_pair.h" | 26 #include "net/base/host_port_pair.h" |
| 26 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
| 27 #include "net/proxy/proxy_server.h" | 28 #include "net/proxy/proxy_server.h" |
| 28 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 29 | 30 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // Called on the UI thread, but should be checked on the IO thread. | 94 // Called on the UI thread, but should be checked on the IO thread. |
| 94 thread_checker_.DetachFromThread(); | 95 thread_checker_.DetachFromThread(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 std::string DataReductionProxyRequestOptions::GetHeaderValueForTesting() const { | 98 std::string DataReductionProxyRequestOptions::GetHeaderValueForTesting() const { |
| 98 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 99 return header_value_; | 100 return header_value_; |
| 100 } | 101 } |
| 101 | 102 |
| 102 void DataReductionProxyRequestOptions::UpdateExperiments() { | 103 void DataReductionProxyRequestOptions::UpdateExperiments() { |
| 103 // TODO(bengr): Simplify this so there's only one way to set experiment via | 104 experiments_.clear(); |
| 104 // flags. See crbug.com/656195. | |
| 105 std::string experiments = | 105 std::string experiments = |
| 106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 107 data_reduction_proxy::switches::kDataReductionProxyExperiment); | 107 data_reduction_proxy::switches::kDataReductionProxyExperiment); |
| 108 | 108 |
| 109 // The command line override takes precedence over field trial "exp" | |
| 110 // directives. | |
| 109 if (!experiments.empty()) { | 111 if (!experiments.empty()) { |
| 110 base::StringTokenizer experiment_tokenizer(experiments, ", "); | 112 base::StringTokenizer experiment_tokenizer(experiments, ", "); |
| 111 experiment_tokenizer.set_quote_chars("\""); | 113 experiment_tokenizer.set_quote_chars("\""); |
| 112 while (experiment_tokenizer.GetNext()) { | 114 while (experiment_tokenizer.GetNext()) { |
| 113 if (!experiment_tokenizer.token().empty()) | 115 if (!experiment_tokenizer.token().empty()) |
| 114 experiments_.push_back(experiment_tokenizer.token()); | 116 experiments_.push_back(experiment_tokenizer.token()); |
| 115 } | 117 } |
| 118 } else if (params::AreLitePagesEnabledViaFlags()) { | |
| 119 experiments_.push_back(chrome_proxy_lite_page_ignore_blacklist()); | |
| 116 } else { | 120 } else { |
| 121 // If no other "exp" directive is forced by flags, add the field trial | |
| 122 // value. | |
| 117 AddServerExperimentFromFieldTrial(); | 123 AddServerExperimentFromFieldTrial(); |
| 118 } | 124 } |
| 119 | 125 |
| 120 RegenerateRequestHeaderValue(); | 126 RegenerateRequestHeaderValue(); |
|
tbansal1
2017/05/23 23:13:34
nit: DCHECK_GE(1, experiments_.size());
RyanSturm
2017/05/23 23:18:11
Acknowledged.
| |
| 121 } | 127 } |
| 122 | 128 |
| 123 void DataReductionProxyRequestOptions::AddServerExperimentFromFieldTrial() { | 129 void DataReductionProxyRequestOptions::AddServerExperimentFromFieldTrial() { |
| 124 if (!params::IsIncludedInServerExperimentsFieldTrial()) | 130 if (!params::IsIncludedInServerExperimentsFieldTrial()) |
| 125 return; | 131 return; |
| 126 const std::string server_experiment = variations::GetVariationParamValue( | 132 const std::string server_experiment = variations::GetVariationParamValue( |
| 127 params::GetServerExperimentsFieldTrialName(), kExperimentsOption); | 133 params::GetServerExperimentsFieldTrialName(), kExperimentsOption); |
| 128 if (!server_experiment.empty()) | 134 if (!server_experiment.empty()) |
| 129 experiments_.push_back(server_experiment); | 135 experiments_.push_back(server_experiment); |
| 130 } | 136 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 // Caller should not depend on order. | 322 // Caller should not depend on order. |
| 317 return ++current_page_id_; | 323 return ++current_page_id_; |
| 318 } | 324 } |
| 319 | 325 |
| 320 void DataReductionProxyRequestOptions::ResetPageId() { | 326 void DataReductionProxyRequestOptions::ResetPageId() { |
| 321 // Caller should not depend on reset setting the page ID to 0. | 327 // Caller should not depend on reset setting the page ID to 0. |
| 322 current_page_id_ = 0; | 328 current_page_id_ = 0; |
| 323 } | 329 } |
| 324 | 330 |
| 325 } // namespace data_reduction_proxy | 331 } // namespace data_reduction_proxy |
| OLD | NEW |