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_delegate.h" |
18 #include "net/reporting/reporting_policy.h" | 19 #include "net/reporting/reporting_policy.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 #include "url/origin.h" | 21 #include "url/origin.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 | 24 |
24 ReportingEndpointManager::ReportingEndpointManager(ReportingContext* context) | 25 ReportingEndpointManager::ReportingEndpointManager(ReportingContext* context) |
25 : context_(context) {} | 26 : context_(context) {} |
26 | 27 |
27 ReportingEndpointManager::~ReportingEndpointManager() {} | 28 ReportingEndpointManager::~ReportingEndpointManager() {} |
(...skipping 10 matching lines...) Expand all Loading... |
38 base::TimeTicks now = tick_clock()->NowTicks(); | 39 base::TimeTicks now = tick_clock()->NowTicks(); |
39 for (const ReportingClient* client : clients) { | 40 for (const ReportingClient* client : clients) { |
40 if (client->expires < now) | 41 if (client->expires < now) |
41 continue; | 42 continue; |
42 if (base::ContainsKey(pending_endpoints_, client->endpoint)) | 43 if (base::ContainsKey(pending_endpoints_, client->endpoint)) |
43 continue; | 44 continue; |
44 if (base::ContainsKey(endpoint_backoff_, client->endpoint) && | 45 if (base::ContainsKey(endpoint_backoff_, client->endpoint) && |
45 endpoint_backoff_[client->endpoint]->ShouldRejectRequest()) { | 46 endpoint_backoff_[client->endpoint]->ShouldRejectRequest()) { |
46 continue; | 47 continue; |
47 } | 48 } |
| 49 if (!delegate()->CanUseClient(client->origin, client->endpoint)) |
| 50 continue; |
48 available_clients.push_back(client); | 51 available_clients.push_back(client); |
49 } | 52 } |
50 | 53 |
51 if (available_clients.empty()) { | 54 if (available_clients.empty()) { |
52 *endpoint_url_out = GURL(); | 55 *endpoint_url_out = GURL(); |
53 return false; | 56 return false; |
54 } | 57 } |
55 | 58 |
56 int random_index = base::RandInt(0, available_clients.size() - 1); | 59 int random_index = base::RandInt(0, available_clients.size() - 1); |
57 *endpoint_url_out = available_clients[random_index]->endpoint; | 60 *endpoint_url_out = available_clients[random_index]->endpoint; |
(...skipping 13 matching lines...) Expand all Loading... |
71 void ReportingEndpointManager::InformOfEndpointRequest(const GURL& endpoint, | 74 void ReportingEndpointManager::InformOfEndpointRequest(const GURL& endpoint, |
72 bool succeeded) { | 75 bool succeeded) { |
73 if (!base::ContainsKey(endpoint_backoff_, endpoint)) { | 76 if (!base::ContainsKey(endpoint_backoff_, endpoint)) { |
74 endpoint_backoff_[endpoint] = base::MakeUnique<BackoffEntry>( | 77 endpoint_backoff_[endpoint] = base::MakeUnique<BackoffEntry>( |
75 &policy().endpoint_backoff_policy, tick_clock()); | 78 &policy().endpoint_backoff_policy, tick_clock()); |
76 } | 79 } |
77 endpoint_backoff_[endpoint]->InformOfRequest(succeeded); | 80 endpoint_backoff_[endpoint]->InformOfRequest(succeeded); |
78 } | 81 } |
79 | 82 |
80 } // namespace net | 83 } // namespace net |
OLD | NEW |