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/domain_reliability/util.h" | 5 #include "components/domain_reliability/util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 { net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, | 60 { net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, |
61 "http.request.range_not_satisfiable" }, | 61 "http.request.range_not_satisfiable" }, |
62 { net::ERR_INVALID_RESPONSE, "http.response.invalid" }, | 62 { net::ERR_INVALID_RESPONSE, "http.response.invalid" }, |
63 { net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, | 63 { net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, |
64 "http.response.headers.multiple_content_disposition" }, | 64 "http.response.headers.multiple_content_disposition" }, |
65 { net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, | 65 { net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, |
66 "http.response.headers.multiple_content_length" }, | 66 "http.response.headers.multiple_content_length" }, |
67 { net::ERR_SSL_UNRECOGNIZED_NAME_ALERT, "ssl.unrecognized_name_alert" } | 67 { net::ERR_SSL_UNRECOGNIZED_NAME_ALERT, "ssl.unrecognized_name_alert" } |
68 }; | 68 }; |
69 | 69 |
| 70 bool CanReportFullBeaconURLToCollector(const GURL& beacon_url, |
| 71 const GURL& collector_url) { |
| 72 return beacon_url.GetOrigin() == collector_url.GetOrigin(); |
| 73 } |
| 74 |
70 } // namespace | 75 } // namespace |
71 | 76 |
72 // static | 77 // static |
73 bool GetDomainReliabilityBeaconStatus( | 78 bool GetDomainReliabilityBeaconStatus( |
74 int net_error, | 79 int net_error, |
75 int http_response_code, | 80 int http_response_code, |
76 std::string* beacon_status_out) { | 81 std::string* beacon_status_out) { |
77 if (net_error == net::OK) { | 82 if (net_error == net::OK) { |
78 if (http_response_code >= 400 && http_response_code < 600) | 83 if (http_response_code >= 400 && http_response_code < 600) |
79 *beacon_status_out = "http.error"; | 84 *beacon_status_out = "http.error"; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 retry_after != base::TimeDelta()) { | 152 retry_after != base::TimeDelta()) { |
148 result->status = DomainReliabilityUploader::UploadResult::RETRY_AFTER; | 153 result->status = DomainReliabilityUploader::UploadResult::RETRY_AFTER; |
149 result->retry_after = retry_after; | 154 result->retry_after = retry_after; |
150 return; | 155 return; |
151 } | 156 } |
152 | 157 |
153 result->status = DomainReliabilityUploader::UploadResult::FAILURE; | 158 result->status = DomainReliabilityUploader::UploadResult::FAILURE; |
154 return; | 159 return; |
155 } | 160 } |
156 | 161 |
| 162 // N.B. This uses a ScopedVector because that's what JSONValueConverter uses |
| 163 // for repeated fields of any type, and Config uses JSONValueConverter to parse |
| 164 // JSON configs. |
| 165 GURL SanitizeURLForReport(const GURL& beacon_url, |
| 166 const GURL& collector_url, |
| 167 const ScopedVector<std::string>& path_prefixes) { |
| 168 if (CanReportFullBeaconURLToCollector(beacon_url, collector_url)) |
| 169 return beacon_url.GetAsReferrer(); |
| 170 |
| 171 std::string path = beacon_url.path(); |
| 172 const std::string empty_path; |
| 173 const std::string* longest_path_prefix = &empty_path; |
| 174 for (const std::string* path_prefix : path_prefixes) { |
| 175 if (path.substr(0, path_prefix->length()) == *path_prefix && |
| 176 path_prefix->length() > longest_path_prefix->length()) { |
| 177 longest_path_prefix = path_prefix; |
| 178 } |
| 179 } |
| 180 |
| 181 GURL::Replacements replacements; |
| 182 replacements.ClearUsername(); |
| 183 replacements.ClearPassword(); |
| 184 replacements.SetPathStr(*longest_path_prefix); |
| 185 replacements.ClearQuery(); |
| 186 replacements.ClearRef(); |
| 187 return beacon_url.ReplaceComponents(replacements); |
| 188 } |
| 189 |
157 namespace { | 190 namespace { |
158 | 191 |
159 class ActualTimer : public MockableTime::Timer { | 192 class ActualTimer : public MockableTime::Timer { |
160 public: | 193 public: |
161 // Initialize base timer with retain_user_info and is_repeating false. | 194 // Initialize base timer with retain_user_info and is_repeating false. |
162 ActualTimer() : base_timer_(false, false) {} | 195 ActualTimer() : base_timer_(false, false) {} |
163 | 196 |
164 ~ActualTimer() override {} | 197 ~ActualTimer() override {} |
165 | 198 |
166 // MockableTime::Timer implementation: | 199 // MockableTime::Timer implementation: |
(...skipping 23 matching lines...) Expand all Loading... |
190 ActualTime::~ActualTime() {} | 223 ActualTime::~ActualTime() {} |
191 | 224 |
192 base::Time ActualTime::Now() { return base::Time::Now(); } | 225 base::Time ActualTime::Now() { return base::Time::Now(); } |
193 base::TimeTicks ActualTime::NowTicks() { return base::TimeTicks::Now(); } | 226 base::TimeTicks ActualTime::NowTicks() { return base::TimeTicks::Now(); } |
194 | 227 |
195 scoped_ptr<MockableTime::Timer> ActualTime::CreateTimer() { | 228 scoped_ptr<MockableTime::Timer> ActualTime::CreateTimer() { |
196 return scoped_ptr<MockableTime::Timer>(new ActualTimer()); | 229 return scoped_ptr<MockableTime::Timer>(new ActualTimer()); |
197 } | 230 } |
198 | 231 |
199 } // namespace domain_reliability | 232 } // namespace domain_reliability |
OLD | NEW |