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_heade
rs.h" | 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <string> | 10 #include <string> |
8 #include <vector> | 11 #include <vector> |
9 | 12 |
10 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
11 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
13 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
14 #include "base/time/time.h" | 17 #include "base/time/time.h" |
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" | 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" |
16 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
(...skipping 20 matching lines...) Expand all Loading... |
37 const char kChromeProxyActionFingerprintChromeProxy[] = "fcp"; | 40 const char kChromeProxyActionFingerprintChromeProxy[] = "fcp"; |
38 const char kChromeProxyActionFingerprintVia[] = "fvia"; | 41 const char kChromeProxyActionFingerprintVia[] = "fvia"; |
39 const char kChromeProxyActionFingerprintOtherHeaders[] = "foh"; | 42 const char kChromeProxyActionFingerprintOtherHeaders[] = "foh"; |
40 const char kChromeProxyActionFingerprintContentLength[] = "fcl"; | 43 const char kChromeProxyActionFingerprintContentLength[] = "fcl"; |
41 | 44 |
42 const int kShortBypassMaxSeconds = 59; | 45 const int kShortBypassMaxSeconds = 59; |
43 const int kMediumBypassMaxSeconds = 300; | 46 const int kMediumBypassMaxSeconds = 300; |
44 | 47 |
45 // Returns a random bypass duration between 1 and 5 minutes. | 48 // Returns a random bypass duration between 1 and 5 minutes. |
46 base::TimeDelta GetDefaultBypassDuration() { | 49 base::TimeDelta GetDefaultBypassDuration() { |
47 const int64 delta_ms = | 50 const int64_t delta_ms = |
48 base::RandInt(base::TimeDelta::FromMinutes(1).InMilliseconds(), | 51 base::RandInt(base::TimeDelta::FromMinutes(1).InMilliseconds(), |
49 base::TimeDelta::FromMinutes(5).InMilliseconds()); | 52 base::TimeDelta::FromMinutes(5).InMilliseconds()); |
50 return TimeDelta::FromMilliseconds(delta_ms); | 53 return TimeDelta::FromMilliseconds(delta_ms); |
51 } | 54 } |
52 | 55 |
53 } // namespace | 56 } // namespace |
54 | 57 |
55 namespace data_reduction_proxy { | 58 namespace data_reduction_proxy { |
56 | 59 |
57 const char* chrome_proxy_header() { | 60 const char* chrome_proxy_header() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // A valid action does not include a trailing '='. | 106 // A valid action does not include a trailing '='. |
104 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); | 107 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); |
105 void* iter = NULL; | 108 void* iter = NULL; |
106 std::string value; | 109 std::string value; |
107 std::string prefix = action_prefix + kActionValueDelimiter; | 110 std::string prefix = action_prefix + kActionValueDelimiter; |
108 | 111 |
109 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { | 112 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { |
110 if (value.size() > prefix.size()) { | 113 if (value.size() > prefix.size()) { |
111 if (base::StartsWith(value, prefix, | 114 if (base::StartsWith(value, prefix, |
112 base::CompareCase::INSENSITIVE_ASCII)) { | 115 base::CompareCase::INSENSITIVE_ASCII)) { |
113 int64 seconds; | 116 int64_t seconds; |
114 if (!base::StringToInt64( | 117 if (!base::StringToInt64( |
115 StringPiece(value.begin() + prefix.size(), value.end()), | 118 StringPiece(value.begin() + prefix.size(), value.end()), |
116 &seconds) || seconds < 0) { | 119 &seconds) || seconds < 0) { |
117 continue; // In case there is a well formed instruction. | 120 continue; // In case there is a well formed instruction. |
118 } | 121 } |
119 if (seconds != 0) { | 122 if (seconds != 0) { |
120 *bypass_duration = TimeDelta::FromSeconds(seconds); | 123 *bypass_duration = TimeDelta::FromSeconds(seconds); |
121 } else { | 124 } else { |
122 // Server deferred to us to choose a duration. Default to a random | 125 // Server deferred to us to choose a duration. Default to a random |
123 // duration between one and five minutes. | 126 // duration between one and five minutes. |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if (base::StartsWith(value, chrome_proxy_fingerprint_prefix, | 319 if (base::StartsWith(value, chrome_proxy_fingerprint_prefix, |
317 base::CompareCase::INSENSITIVE_ASCII)) { | 320 base::CompareCase::INSENSITIVE_ASCII)) { |
318 continue; | 321 continue; |
319 } | 322 } |
320 } | 323 } |
321 values->push_back(value); | 324 values->push_back(value); |
322 } | 325 } |
323 } | 326 } |
324 | 327 |
325 } // namespace data_reduction_proxy | 328 } // namespace data_reduction_proxy |
OLD | NEW |