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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_tokenizer.h" | 14 #include "base/strings/string_tokenizer.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "build/build_config.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_clien
t_config_parser.h" | 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_clien
t_config_parser.h" |
21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
24 #include "components/data_reduction_proxy/core/common/version.h" | 25 #include "components/data_reduction_proxy/core/common/version.h" |
25 #include "crypto/random.h" | 26 #include "crypto/random.h" |
26 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
27 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
28 #include "net/proxy/proxy_server.h" | 29 #include "net/proxy/proxy_server.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 experiment_tokenizer.set_quote_chars("\""); | 145 experiment_tokenizer.set_quote_chars("\""); |
145 while (experiment_tokenizer.GetNext()) { | 146 while (experiment_tokenizer.GetNext()) { |
146 if (!experiment_tokenizer.token().empty()) | 147 if (!experiment_tokenizer.token().empty()) |
147 experiments_.push_back(experiment_tokenizer.token()); | 148 experiments_.push_back(experiment_tokenizer.token()); |
148 } | 149 } |
149 RegenerateRequestHeaderValue(); | 150 RegenerateRequestHeaderValue(); |
150 } | 151 } |
151 | 152 |
152 // static | 153 // static |
153 base::string16 DataReductionProxyRequestOptions::AuthHashForSalt( | 154 base::string16 DataReductionProxyRequestOptions::AuthHashForSalt( |
154 int64 salt, | 155 int64_t salt, |
155 const std::string& key) { | 156 const std::string& key) { |
156 std::string salted_key = | 157 std::string salted_key = |
157 base::StringPrintf("%lld%s%lld", | 158 base::StringPrintf("%lld%s%lld", |
158 static_cast<long long>(salt), | 159 static_cast<long long>(salt), |
159 key.c_str(), | 160 key.c_str(), |
160 static_cast<long long>(salt)); | 161 static_cast<long long>(salt)); |
161 return base::UTF8ToUTF16(base::MD5String(salted_key)); | 162 return base::UTF8ToUTF16(base::MD5String(salted_key)); |
162 } | 163 } |
163 | 164 |
164 base::Time DataReductionProxyRequestOptions::Now() const { | 165 base::Time DataReductionProxyRequestOptions::Now() const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 header_value += header_value_; | 206 header_value += header_value_; |
206 headers->SetHeader(kChromeProxyHeader, header_value); | 207 headers->SetHeader(kChromeProxyHeader, header_value); |
207 } | 208 } |
208 | 209 |
209 void DataReductionProxyRequestOptions::ComputeCredentials( | 210 void DataReductionProxyRequestOptions::ComputeCredentials( |
210 const base::Time& now, | 211 const base::Time& now, |
211 std::string* session, | 212 std::string* session, |
212 std::string* credentials) const { | 213 std::string* credentials) const { |
213 DCHECK(session); | 214 DCHECK(session); |
214 DCHECK(credentials); | 215 DCHECK(credentials); |
215 int64 timestamp = | 216 int64_t timestamp = (now - base::Time::UnixEpoch()).InMilliseconds() / 1000; |
216 (now - base::Time::UnixEpoch()).InMilliseconds() / 1000; | |
217 | 217 |
218 int32 rand[3]; | 218 int32_t rand[3]; |
219 RandBytes(rand, 3 * sizeof(rand[0])); | 219 RandBytes(rand, 3 * sizeof(rand[0])); |
220 *session = base::StringPrintf("%lld-%u-%u-%u", | 220 *session = base::StringPrintf("%lld-%u-%u-%u", |
221 static_cast<long long>(timestamp), | 221 static_cast<long long>(timestamp), |
222 rand[0], | 222 rand[0], |
223 rand[1], | 223 rand[1], |
224 rand[2]); | 224 rand[2]); |
225 *credentials = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_)); | 225 *credentials = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_)); |
226 | 226 |
227 DVLOG(1) << "session: [" << *session << "] " | 227 DVLOG(1) << "session: [" << *session << "] " |
228 << "password: [" << *credentials << "]"; | 228 << "password: [" << *credentials << "]"; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 headers.push_back(FormatOption(kBuildNumberHeaderOption, build_)); | 313 headers.push_back(FormatOption(kBuildNumberHeaderOption, build_)); |
314 headers.push_back(FormatOption(kPatchNumberHeaderOption, patch_)); | 314 headers.push_back(FormatOption(kPatchNumberHeaderOption, patch_)); |
315 } | 315 } |
316 for (const auto& experiment : experiments_) | 316 for (const auto& experiment : experiments_) |
317 headers.push_back(FormatOption(kExperimentsOption, experiment)); | 317 headers.push_back(FormatOption(kExperimentsOption, experiment)); |
318 | 318 |
319 header_value_ = base::JoinString(headers, ", "); | 319 header_value_ = base::JoinString(headers, ", "); |
320 } | 320 } |
321 | 321 |
322 } // namespace data_reduction_proxy | 322 } // namespace data_reduction_proxy |
OLD | NEW |