| 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/context.h" | 5 #include "components/domain_reliability/context.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 DomainReliabilityContext::~DomainReliabilityContext() {} | 135 DomainReliabilityContext::~DomainReliabilityContext() {} |
| 136 | 136 |
| 137 void DomainReliabilityContext::OnBeacon(const GURL& url, | 137 void DomainReliabilityContext::OnBeacon(const GURL& url, |
| 138 const DomainReliabilityBeacon& beacon) { | 138 const DomainReliabilityBeacon& beacon) { |
| 139 size_t index = config_->GetResourceIndexForUrl(url); | 139 size_t index = config_->GetResourceIndexForUrl(url); |
| 140 if (index == DomainReliabilityConfig::kInvalidResourceIndex) | 140 if (index == DomainReliabilityConfig::kInvalidResourceIndex) |
| 141 return; | 141 return; |
| 142 DCHECK_GT(states_.size(), index); | 142 DCHECK_GT(states_.size(), index); |
| 143 | 143 |
| 144 bool success = (beacon.status == "ok"); |
| 145 |
| 144 ResourceState* state = states_[index]; | 146 ResourceState* state = states_[index]; |
| 145 bool success = beacon.http_response_code >= 200 && | |
| 146 beacon.http_response_code < 400; | |
| 147 if (success) | 147 if (success) |
| 148 ++state->successful_requests; | 148 ++state->successful_requests; |
| 149 else | 149 else |
| 150 ++state->failed_requests; | 150 ++state->failed_requests; |
| 151 | 151 |
| 152 bool reported = false; | 152 bool reported = false; |
| 153 bool evicted = false; | 153 bool evicted = false; |
| 154 if (state->config->DecideIfShouldReportRequest(success)) { | 154 if (state->config->DecideIfShouldReportRequest(success)) { |
| 155 state->beacons.push_back(beacon); | 155 state->beacons.push_back(beacon); |
| 156 ++beacon_count_; | 156 ++beacon_count_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 287 |
| 288 min_resource->RemoveOldestBeacon(); | 288 min_resource->RemoveOldestBeacon(); |
| 289 --beacon_count_; | 289 --beacon_count_; |
| 290 // If that just removed a beacon counted in uploading_beacon_count_, decrement | 290 // If that just removed a beacon counted in uploading_beacon_count_, decrement |
| 291 // that. | 291 // that. |
| 292 if (uploading_beacon_count_ > 0) | 292 if (uploading_beacon_count_ > 0) |
| 293 --uploading_beacon_count_; | 293 --uploading_beacon_count_; |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace domain_reliability | 296 } // namespace domain_reliability |
| OLD | NEW |