| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "net/reporting/reporting_endpoint_manager.h" | 5 #include "net/reporting/reporting_endpoint_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/time/tick_clock.h" | 14 #include "base/time/tick_clock.h" |
| 15 #include "net/base/backoff_entry.h" | 15 #include "net/base/backoff_entry.h" |
| 16 #include "net/reporting/reporting_cache.h" | 16 #include "net/reporting/reporting_cache.h" |
| 17 #include "net/reporting/reporting_client.h" | 17 #include "net/reporting/reporting_client.h" |
| 18 #include "net/reporting/reporting_policy.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 #include "url/origin.h" | 20 #include "url/origin.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 ReportingEndpointManager::ReportingEndpointManager( | 24 ReportingEndpointManager::ReportingEndpointManager(ReportingContext* context) |
| 24 base::TickClock* clock, | 25 : context_(context) {} |
| 25 const ReportingCache* cache, | |
| 26 const BackoffEntry::Policy* backoff_policy) | |
| 27 : clock_(clock), cache_(cache), backoff_policy_(backoff_policy) {} | |
| 28 | 26 |
| 29 ReportingEndpointManager::~ReportingEndpointManager() {} | 27 ReportingEndpointManager::~ReportingEndpointManager() {} |
| 30 | 28 |
| 31 bool ReportingEndpointManager::FindEndpointForOriginAndGroup( | 29 bool ReportingEndpointManager::FindEndpointForOriginAndGroup( |
| 32 const url::Origin& origin, | 30 const url::Origin& origin, |
| 33 const std::string& group, | 31 const std::string& group, |
| 34 GURL* endpoint_url_out) { | 32 GURL* endpoint_url_out) { |
| 35 std::vector<const ReportingClient*> clients; | 33 std::vector<const ReportingClient*> clients; |
| 36 cache_->GetClientsForOriginAndGroup(origin, group, &clients); | 34 cache()->GetClientsForOriginAndGroup(origin, group, &clients); |
| 37 | 35 |
| 38 // Filter out expired, pending, and backed-off endpoints. | 36 // Filter out expired, pending, and backed-off endpoints. |
| 39 std::vector<const ReportingClient*> available_clients; | 37 std::vector<const ReportingClient*> available_clients; |
| 40 base::TimeTicks now = clock_->NowTicks(); | 38 base::TimeTicks now = tick_clock()->NowTicks(); |
| 41 for (const ReportingClient* client : clients) { | 39 for (const ReportingClient* client : clients) { |
| 42 if (client->expires < now) | 40 if (client->expires < now) |
| 43 continue; | 41 continue; |
| 44 if (base::ContainsKey(pending_endpoints_, client->endpoint)) | 42 if (base::ContainsKey(pending_endpoints_, client->endpoint)) |
| 45 continue; | 43 continue; |
| 46 if (base::ContainsKey(endpoint_backoff_, client->endpoint) && | 44 if (base::ContainsKey(endpoint_backoff_, client->endpoint) && |
| 47 endpoint_backoff_[client->endpoint]->ShouldRejectRequest()) { | 45 endpoint_backoff_[client->endpoint]->ShouldRejectRequest()) { |
| 48 continue; | 46 continue; |
| 49 } | 47 } |
| 50 available_clients.push_back(client); | 48 available_clients.push_back(client); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 } | 64 } |
| 67 | 65 |
| 68 void ReportingEndpointManager::ClearEndpointPending(const GURL& endpoint) { | 66 void ReportingEndpointManager::ClearEndpointPending(const GURL& endpoint) { |
| 69 DCHECK(base::ContainsKey(pending_endpoints_, endpoint)); | 67 DCHECK(base::ContainsKey(pending_endpoints_, endpoint)); |
| 70 pending_endpoints_.erase(endpoint); | 68 pending_endpoints_.erase(endpoint); |
| 71 } | 69 } |
| 72 | 70 |
| 73 void ReportingEndpointManager::InformOfEndpointRequest(const GURL& endpoint, | 71 void ReportingEndpointManager::InformOfEndpointRequest(const GURL& endpoint, |
| 74 bool succeeded) { | 72 bool succeeded) { |
| 75 if (!base::ContainsKey(endpoint_backoff_, endpoint)) { | 73 if (!base::ContainsKey(endpoint_backoff_, endpoint)) { |
| 76 endpoint_backoff_[endpoint] = | 74 endpoint_backoff_[endpoint] = base::MakeUnique<BackoffEntry>( |
| 77 base::MakeUnique<BackoffEntry>(backoff_policy_, clock_); | 75 &policy().endpoint_backoff_policy, tick_clock()); |
| 78 } | 76 } |
| 79 endpoint_backoff_[endpoint]->InformOfRequest(succeeded); | 77 endpoint_backoff_[endpoint]->InformOfRequest(succeeded); |
| 80 } | 78 } |
| 81 | 79 |
| 82 } // namespace net | 80 } // namespace net |
| OLD | NEW |