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" |
21 #include "net/reporting/reporting_observer.h" | 22 #include "net/reporting/reporting_observer.h" |
| 23 #include "net/reporting/reporting_persister.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: |
(...skipping 13 matching lines...) Expand all Loading... |
45 std::unique_ptr<ReportingContext> ReportingContext::Create( | 47 std::unique_ptr<ReportingContext> ReportingContext::Create( |
46 const ReportingPolicy& policy, | 48 const ReportingPolicy& policy, |
47 std::unique_ptr<ReportingDelegate> delegate, | 49 std::unique_ptr<ReportingDelegate> delegate, |
48 URLRequestContext* request_context) { | 50 URLRequestContext* request_context) { |
49 return base::MakeUnique<ReportingContextImpl>(policy, std::move(delegate), | 51 return base::MakeUnique<ReportingContextImpl>(policy, std::move(delegate), |
50 request_context); | 52 request_context); |
51 } | 53 } |
52 | 54 |
53 ReportingContext::~ReportingContext() {} | 55 ReportingContext::~ReportingContext() {} |
54 | 56 |
| 57 void ReportingContext::Initialize() { |
| 58 DCHECK(!initialized_); |
| 59 |
| 60 for (auto& observer : observers_) |
| 61 observer.OnContextInitializing(); |
| 62 |
| 63 initialized_ = true; |
| 64 |
| 65 for (auto& observer : observers_) |
| 66 observer.OnContextInitialized(); |
| 67 } |
| 68 |
55 void ReportingContext::AddObserver(ReportingObserver* observer) { | 69 void ReportingContext::AddObserver(ReportingObserver* observer) { |
56 DCHECK(!observers_.HasObserver(observer)); | 70 DCHECK(!observers_.HasObserver(observer)); |
57 observers_.AddObserver(observer); | 71 observers_.AddObserver(observer); |
58 } | 72 } |
59 | 73 |
60 void ReportingContext::RemoveObserver(ReportingObserver* observer) { | 74 void ReportingContext::RemoveObserver(ReportingObserver* observer) { |
61 DCHECK(observers_.HasObserver(observer)); | 75 DCHECK(observers_.HasObserver(observer)); |
62 observers_.RemoveObserver(observer); | 76 observers_.RemoveObserver(observer); |
63 } | 77 } |
64 | 78 |
65 void ReportingContext::NotifyCacheUpdated() { | 79 void ReportingContext::NotifyCacheUpdated() { |
| 80 if (!initialized_) |
| 81 return; |
| 82 |
66 for (auto& observer : observers_) | 83 for (auto& observer : observers_) |
67 observer.OnCacheUpdated(); | 84 observer.OnCacheUpdated(); |
68 } | 85 } |
69 | 86 |
70 ReportingContext::ReportingContext(const ReportingPolicy& policy, | 87 ReportingContext::ReportingContext(const ReportingPolicy& policy, |
71 std::unique_ptr<ReportingDelegate> delegate, | 88 std::unique_ptr<ReportingDelegate> delegate, |
72 std::unique_ptr<base::Clock> clock, | 89 std::unique_ptr<base::Clock> clock, |
73 std::unique_ptr<base::TickClock> tick_clock, | 90 std::unique_ptr<base::TickClock> tick_clock, |
74 std::unique_ptr<ReportingUploader> uploader) | 91 std::unique_ptr<ReportingUploader> uploader) |
75 : policy_(policy), | 92 : policy_(policy), |
76 delegate_(std::move(delegate)), | 93 delegate_(std::move(delegate)), |
77 clock_(std::move(clock)), | 94 clock_(std::move(clock)), |
78 tick_clock_(std::move(tick_clock)), | 95 tick_clock_(std::move(tick_clock)), |
79 uploader_(std::move(uploader)), | 96 uploader_(std::move(uploader)), |
| 97 initialized_(false), |
80 cache_(base::MakeUnique<ReportingCache>(this)), | 98 cache_(base::MakeUnique<ReportingCache>(this)), |
81 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), | 99 endpoint_manager_(base::MakeUnique<ReportingEndpointManager>(this)), |
82 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)) {} | 100 delivery_agent_(base::MakeUnique<ReportingDeliveryAgent>(this)), |
| 101 persister_(ReportingPersister::Create(this)) {} |
83 | 102 |
84 } // namespace net | 103 } // namespace net |
OLD | NEW |