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