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/monitor.h" | 5 #include "components/domain_reliability/monitor.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 contexts_.clear(); | 189 contexts_.clear(); |
190 } | 190 } |
191 | 191 |
192 void DomainReliabilityMonitor::OnRequestLegComplete( | 192 void DomainReliabilityMonitor::OnRequestLegComplete( |
193 const RequestInfo& request) { | 193 const RequestInfo& request) { |
194 int response_code; | 194 int response_code; |
195 if (request.response_info.headers) | 195 if (request.response_info.headers) |
196 response_code = request.response_info.headers->response_code(); | 196 response_code = request.response_info.headers->response_code(); |
197 else | 197 else |
198 response_code = -1; | 198 response_code = -1; |
199 ContextMap::iterator context_it; | |
200 std::string beacon_status; | 199 std::string beacon_status; |
201 | 200 |
202 int error_code = net::OK; | 201 int error_code = net::OK; |
203 if (request.status.status() == net::URLRequestStatus::FAILED) | 202 if (request.status.status() == net::URLRequestStatus::FAILED) |
204 error_code = request.status.error(); | 203 error_code = request.status.error(); |
205 | 204 |
| 205 DomainReliabilityContext* context = GetContextForHost(request.url.host()); |
| 206 |
206 // Ignore requests where: | 207 // Ignore requests where: |
207 // 1. There is no context for the request host. | 208 // 1. There is no context for the request host. |
208 // 2. The request did not access the network. | 209 // 2. The request did not access the network. |
209 // 3. The request is not supposed to send cookies (to avoid associating the | 210 // 3. The request is not supposed to send cookies (to avoid associating the |
210 // request with any potentially unique data in the config). | 211 // request with any potentially unique data in the config). |
211 // 4. The request was itself a Domain Reliability upload (to avoid loops). | 212 // 4. The request was itself a Domain Reliability upload (to avoid loops). |
212 // 5. There is no defined beacon status for the error or HTTP response code | 213 // 5. There is no defined beacon status for the error or HTTP response code |
213 // (to avoid leaking network-local errors). | 214 // (to avoid leaking network-local errors). |
214 if ((context_it = contexts_.find(request.url.host())) == contexts_.end() || | 215 if (!context || |
215 !request.AccessedNetwork() || | 216 !request.AccessedNetwork() || |
216 (request.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) || | 217 (request.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) || |
217 request.is_upload || | 218 request.is_upload || |
218 !GetDomainReliabilityBeaconStatus( | 219 !GetDomainReliabilityBeaconStatus( |
219 error_code, response_code, &beacon_status)) { | 220 error_code, response_code, &beacon_status)) { |
220 return; | 221 return; |
221 } | 222 } |
222 | 223 |
223 DomainReliabilityBeacon beacon; | 224 DomainReliabilityBeacon beacon; |
224 beacon.status = beacon_status; | 225 beacon.status = beacon_status; |
225 beacon.chrome_error = error_code; | 226 beacon.chrome_error = error_code; |
226 if (!request.response_info.was_fetched_via_proxy) | 227 if (!request.response_info.was_fetched_via_proxy) |
227 beacon.server_ip = request.response_info.socket_address.host(); | 228 beacon.server_ip = request.response_info.socket_address.host(); |
228 else | 229 else |
229 beacon.server_ip.clear(); | 230 beacon.server_ip.clear(); |
230 beacon.protocol = GetDomainReliabilityProtocol( | 231 beacon.protocol = GetDomainReliabilityProtocol( |
231 request.response_info.connection_info, | 232 request.response_info.connection_info, |
232 request.response_info.ssl_info.is_valid()); | 233 request.response_info.ssl_info.is_valid()); |
233 beacon.http_response_code = response_code; | 234 beacon.http_response_code = response_code; |
234 beacon.start_time = request.load_timing_info.request_start; | 235 beacon.start_time = request.load_timing_info.request_start; |
235 beacon.elapsed = time_->NowTicks() - beacon.start_time; | 236 beacon.elapsed = time_->NowTicks() - beacon.start_time; |
236 context_it->second->OnBeacon(request.url, beacon); | 237 context->OnBeacon(request.url, beacon); |
| 238 } |
| 239 |
| 240 // TODO(ttuttle): Keep a separate wildcard_contexts_ map to avoid having to |
| 241 // prepend '*.' to domains. |
| 242 DomainReliabilityContext* DomainReliabilityMonitor::GetContextForHost( |
| 243 const std::string& host) const { |
| 244 ContextMap::const_iterator context_it; |
| 245 |
| 246 context_it = contexts_.find(host); |
| 247 if (context_it != contexts_.end()) |
| 248 return context_it->second; |
| 249 |
| 250 std::string host_with_asterisk = "*." + host; |
| 251 context_it = contexts_.find(host_with_asterisk); |
| 252 if (context_it != contexts_.end()) |
| 253 return context_it->second; |
| 254 |
| 255 size_t dot_pos = host.find('.'); |
| 256 if (dot_pos == std::string::npos) |
| 257 return NULL; |
| 258 |
| 259 // TODO(ttuttle): Make sure parent is not in PSL before using. |
| 260 |
| 261 std::string parent_with_asterisk = "*." + host.substr(dot_pos + 1); |
| 262 context_it = contexts_.find(parent_with_asterisk); |
| 263 if (context_it != contexts_.end()) |
| 264 return context_it->second; |
| 265 |
| 266 return NULL; |
237 } | 267 } |
238 | 268 |
239 base::WeakPtr<DomainReliabilityMonitor> | 269 base::WeakPtr<DomainReliabilityMonitor> |
240 DomainReliabilityMonitor::MakeWeakPtr() { | 270 DomainReliabilityMonitor::MakeWeakPtr() { |
241 return weak_factory_.GetWeakPtr(); | 271 return weak_factory_.GetWeakPtr(); |
242 } | 272 } |
243 | 273 |
244 } // namespace domain_reliability | 274 } // namespace domain_reliability |
OLD | NEW |