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/time/clock.h" | 11 #include "base/time/clock.h" |
11 #include "base/time/default_clock.h" | 12 #include "base/time/default_clock.h" |
12 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
13 #include "base/time/tick_clock.h" | 14 #include "base/time/tick_clock.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "net/base/backoff_entry.h" | 16 #include "net/base/backoff_entry.h" |
16 #include "net/reporting/reporting_cache.h" | 17 #include "net/reporting/reporting_cache.h" |
17 #include "net/reporting/reporting_delegate.h" | 18 #include "net/reporting/reporting_delegate.h" |
18 #include "net/reporting/reporting_delivery_agent.h" | 19 #include "net/reporting/reporting_delivery_agent.h" |
19 #include "net/reporting/reporting_endpoint_manager.h" | 20 #include "net/reporting/reporting_endpoint_manager.h" |
| 21 #include "net/reporting/reporting_observer.h" |
20 #include "net/reporting/reporting_policy.h" | 22 #include "net/reporting/reporting_policy.h" |
21 | 23 |
22 namespace net { | 24 namespace net { |
23 | 25 |
24 class URLRequestContext; | 26 class URLRequestContext; |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 class ReportingContextImpl : public ReportingContext { | 30 class ReportingContextImpl : public ReportingContext { |
29 public: | 31 public: |
(...skipping 13 matching lines...) Expand all Loading... |
43 std::unique_ptr<ReportingContext> ReportingContext::Create( | 45 std::unique_ptr<ReportingContext> ReportingContext::Create( |
44 const ReportingPolicy& policy, | 46 const ReportingPolicy& policy, |
45 std::unique_ptr<ReportingDelegate> delegate, | 47 std::unique_ptr<ReportingDelegate> delegate, |
46 URLRequestContext* request_context) { | 48 URLRequestContext* request_context) { |
47 return base::MakeUnique<ReportingContextImpl>(policy, std::move(delegate), | 49 return base::MakeUnique<ReportingContextImpl>(policy, std::move(delegate), |
48 request_context); | 50 request_context); |
49 } | 51 } |
50 | 52 |
51 ReportingContext::~ReportingContext() {} | 53 ReportingContext::~ReportingContext() {} |
52 | 54 |
| 55 void ReportingContext::AddObserver(ReportingObserver* observer) { |
| 56 DCHECK(!observers_.HasObserver(observer)); |
| 57 observers_.AddObserver(observer); |
| 58 } |
| 59 |
| 60 void ReportingContext::RemoveObserver(ReportingObserver* observer) { |
| 61 DCHECK(observers_.HasObserver(observer)); |
| 62 observers_.RemoveObserver(observer); |
| 63 } |
| 64 |
| 65 void ReportingContext::NotifyCacheUpdated() { |
| 66 for (auto& observer : observers_) |
| 67 observer.OnCacheUpdated(); |
| 68 } |
| 69 |
53 ReportingContext::ReportingContext(const ReportingPolicy& policy, | 70 ReportingContext::ReportingContext(const ReportingPolicy& policy, |
54 std::unique_ptr<ReportingDelegate> delegate, | 71 std::unique_ptr<ReportingDelegate> delegate, |
55 std::unique_ptr<base::Clock> clock, | 72 std::unique_ptr<base::Clock> clock, |
56 std::unique_ptr<base::TickClock> tick_clock, | 73 std::unique_ptr<base::TickClock> tick_clock, |
57 std::unique_ptr<ReportingUploader> uploader) | 74 std::unique_ptr<ReportingUploader> uploader) |
58 : policy_(policy), | 75 : policy_(policy), |
59 delegate_(std::move(delegate)), | 76 delegate_(std::move(delegate)), |
60 clock_(std::move(clock)), | 77 clock_(std::move(clock)), |
61 tick_clock_(std::move(tick_clock)), | 78 tick_clock_(std::move(tick_clock)), |
62 uploader_(std::move(uploader)), | 79 uploader_(std::move(uploader)), |
63 cache_(base::MakeUnique<ReportingCache>(this)), | 80 cache_(base::MakeUnique<ReportingCache>(this)), |
64 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), | 81 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), |
65 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)) {} | 82 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)) {} |
66 | 83 |
67 } // namespace net | 84 } // namespace net |
OLD | NEW |