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_context.h" | 5 #include "net/reporting/reporting_context.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/time/clock.h" | 11 #include "base/time/clock.h" |
12 #include "base/time/default_clock.h" | 12 #include "base/time/default_clock.h" |
13 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
14 #include "base/time/tick_clock.h" | 14 #include "base/time/tick_clock.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" |
16 #include "net/base/backoff_entry.h" | 17 #include "net/base/backoff_entry.h" |
17 #include "net/reporting/reporting_cache.h" | 18 #include "net/reporting/reporting_cache.h" |
18 #include "net/reporting/reporting_delegate.h" | 19 #include "net/reporting/reporting_delegate.h" |
19 #include "net/reporting/reporting_delivery_agent.h" | 20 #include "net/reporting/reporting_delivery_agent.h" |
20 #include "net/reporting/reporting_endpoint_manager.h" | 21 #include "net/reporting/reporting_endpoint_manager.h" |
| 22 #include "net/reporting/reporting_garbage_collector.h" |
21 #include "net/reporting/reporting_observer.h" | 23 #include "net/reporting/reporting_observer.h" |
22 #include "net/reporting/reporting_policy.h" | 24 #include "net/reporting/reporting_policy.h" |
23 | 25 |
24 namespace net { | 26 namespace net { |
25 | 27 |
26 class URLRequestContext; | 28 class URLRequestContext; |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 class ReportingContextImpl : public ReportingContext { | 32 class ReportingContextImpl : public ReportingContext { |
31 public: | 33 public: |
32 ReportingContextImpl(const ReportingPolicy& policy, | 34 ReportingContextImpl(const ReportingPolicy& policy, |
33 std::unique_ptr<ReportingDelegate> delegate, | 35 std::unique_ptr<ReportingDelegate> delegate, |
34 URLRequestContext* request_context) | 36 URLRequestContext* request_context) |
35 : ReportingContext(policy) { | 37 : ReportingContext(policy) { |
36 Init(std::move(delegate), base::MakeUnique<base::DefaultClock>(), | 38 Init(std::move(delegate), base::MakeUnique<base::DefaultClock>(), |
37 base::MakeUnique<base::DefaultTickClock>(), | 39 base::MakeUnique<base::DefaultTickClock>(), |
| 40 base::MakeUnique<base::OneShotTimer>(), |
38 ReportingUploader::Create(request_context)); | 41 ReportingUploader::Create(request_context)); |
39 } | 42 } |
40 }; | 43 }; |
41 | 44 |
42 } // namespace | 45 } // namespace |
43 | 46 |
44 // static | 47 // static |
45 std::unique_ptr<ReportingContext> ReportingContext::Create( | 48 std::unique_ptr<ReportingContext> ReportingContext::Create( |
46 const ReportingPolicy& policy, | 49 const ReportingPolicy& policy, |
47 std::unique_ptr<ReportingDelegate> delegate, | 50 std::unique_ptr<ReportingDelegate> delegate, |
(...skipping 16 matching lines...) Expand all Loading... |
64 | 67 |
65 void ReportingContext::NotifyCacheUpdated() { | 68 void ReportingContext::NotifyCacheUpdated() { |
66 for (auto& observer : observers_) | 69 for (auto& observer : observers_) |
67 observer.OnCacheUpdated(); | 70 observer.OnCacheUpdated(); |
68 } | 71 } |
69 | 72 |
70 ReportingContext::ReportingContext(const ReportingPolicy& policy) | 73 ReportingContext::ReportingContext(const ReportingPolicy& policy) |
71 : policy_(policy), | 74 : policy_(policy), |
72 cache_(base::MakeUnique<ReportingCache>(this)), | 75 cache_(base::MakeUnique<ReportingCache>(this)), |
73 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), | 76 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), |
74 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)) {} | 77 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)), |
| 78 garbage_collector_(ReportingGarbageCollector::Create(this)) {} |
75 | 79 |
76 void ReportingContext::Init(std::unique_ptr<ReportingDelegate> delegate, | 80 void ReportingContext::Init( |
77 std::unique_ptr<base::Clock> clock, | 81 std::unique_ptr<ReportingDelegate> delegate, |
78 std::unique_ptr<base::TickClock> tick_clock, | 82 std::unique_ptr<base::Clock> clock, |
79 std::unique_ptr<ReportingUploader> uploader) { | 83 std::unique_ptr<base::TickClock> tick_clock, |
| 84 std::unique_ptr<base::Timer> garbage_collection_timer, |
| 85 std::unique_ptr<ReportingUploader> uploader) { |
80 delegate_ = std::move(delegate); | 86 delegate_ = std::move(delegate); |
81 clock_ = std::move(clock); | 87 clock_ = std::move(clock); |
82 tick_clock_ = std::move(tick_clock); | 88 tick_clock_ = std::move(tick_clock); |
| 89 garbage_collection_timer_ = std::move(garbage_collection_timer); |
83 uploader_ = std::move(uploader); | 90 uploader_ = std::move(uploader); |
84 } | 91 } |
85 | 92 |
86 } // namespace net | 93 } // namespace net |
OLD | NEW |