| 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 #ifndef NET_REPORTING_REPORTING_CONTEXT_H_ | 5 #ifndef NET_REPORTING_REPORTING_CONTEXT_H_ |
| 6 #define NET_REPORTING_REPORTING_CONTEXT_H_ | 6 #define NET_REPORTING_REPORTING_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "net/base/backoff_entry.h" | 12 #include "net/base/backoff_entry.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/reporting/reporting_policy.h" | 14 #include "net/reporting/reporting_policy.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class Clock; | 17 class Clock; |
| 18 class TickClock; | 18 class TickClock; |
| 19 } // namespace base | 19 } // namespace base |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class ReportingCache; | 23 class ReportingCache; |
| 24 class ReportingDelegate; | |
| 25 class ReportingDeliveryAgent; | 24 class ReportingDeliveryAgent; |
| 26 class ReportingEndpointManager; | 25 class ReportingEndpointManager; |
| 27 class ReportingGarbageCollector; | 26 class ReportingGarbageCollector; |
| 28 class ReportingNetworkChangeObserver; | 27 class ReportingNetworkChangeObserver; |
| 29 class ReportingObserver; | 28 class ReportingObserver; |
| 30 class ReportingPersister; | 29 class ReportingPersister; |
| 31 class ReportingUploader; | 30 class ReportingUploader; |
| 32 class URLRequestContext; | 31 class URLRequestContext; |
| 33 | 32 |
| 34 // Contains the various internal classes that make up the Reporting system. | 33 // Contains the various internal classes that make up the Reporting system. |
| 35 // Wrapped by ReportingService, which provides the external interface. | 34 // Wrapped by ReportingService, which provides the external interface. |
| 36 class NET_EXPORT ReportingContext { | 35 class NET_EXPORT ReportingContext { |
| 37 public: | 36 public: |
| 38 static std::unique_ptr<ReportingContext> Create( | 37 static std::unique_ptr<ReportingContext> Create( |
| 39 const ReportingPolicy& policy, | 38 const ReportingPolicy& policy, |
| 40 std::unique_ptr<ReportingDelegate> delegate, | |
| 41 URLRequestContext* request_context); | 39 URLRequestContext* request_context); |
| 42 | 40 |
| 43 ~ReportingContext(); | 41 ~ReportingContext(); |
| 44 | 42 |
| 45 // Initializes the ReportingContext. This may take a while (e.g. it may | |
| 46 // involve reloading state persisted to disk). Should be called only once. | |
| 47 // | |
| 48 // Components of the ReportingContext won't reference their dependencies (e.g. | |
| 49 // the Clock/TickClock or Timers inside the individual components) until | |
| 50 // during/after the call to Init. | |
| 51 void Initialize(); | |
| 52 | |
| 53 bool initialized() const { return initialized_; } | |
| 54 | |
| 55 const ReportingPolicy& policy() { return policy_; } | 43 const ReportingPolicy& policy() { return policy_; } |
| 56 ReportingDelegate* delegate() { return delegate_.get(); } | |
| 57 | 44 |
| 58 base::Clock* clock() { return clock_.get(); } | 45 base::Clock* clock() { return clock_.get(); } |
| 59 base::TickClock* tick_clock() { return tick_clock_.get(); } | 46 base::TickClock* tick_clock() { return tick_clock_.get(); } |
| 60 ReportingUploader* uploader() { return uploader_.get(); } | 47 ReportingUploader* uploader() { return uploader_.get(); } |
| 61 | 48 |
| 62 ReportingCache* cache() { return cache_.get(); } | 49 ReportingCache* cache() { return cache_.get(); } |
| 63 ReportingEndpointManager* endpoint_manager() { | 50 ReportingEndpointManager* endpoint_manager() { |
| 64 return endpoint_manager_.get(); | 51 return endpoint_manager_.get(); |
| 65 } | 52 } |
| 66 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } | 53 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } |
| 67 ReportingGarbageCollector* garbage_collector() { | 54 ReportingGarbageCollector* garbage_collector() { |
| 68 return garbage_collector_.get(); | 55 return garbage_collector_.get(); |
| 69 } | 56 } |
| 70 | 57 |
| 71 ReportingPersister* persister() { return persister_.get(); } | 58 ReportingPersister* persister() { return persister_.get(); } |
| 72 | 59 |
| 73 void AddObserver(ReportingObserver* observer); | 60 void AddObserver(ReportingObserver* observer); |
| 74 void RemoveObserver(ReportingObserver* observer); | 61 void RemoveObserver(ReportingObserver* observer); |
| 75 | 62 |
| 76 void NotifyCacheUpdated(); | 63 void NotifyCacheUpdated(); |
| 77 | 64 |
| 78 protected: | 65 protected: |
| 79 ReportingContext(const ReportingPolicy& policy, | 66 ReportingContext(const ReportingPolicy& policy, |
| 80 std::unique_ptr<ReportingDelegate> delegate, | |
| 81 std::unique_ptr<base::Clock> clock, | 67 std::unique_ptr<base::Clock> clock, |
| 82 std::unique_ptr<base::TickClock> tick_clock, | 68 std::unique_ptr<base::TickClock> tick_clock, |
| 83 std::unique_ptr<ReportingUploader> uploader); | 69 std::unique_ptr<ReportingUploader> uploader); |
| 84 | 70 |
| 85 private: | 71 private: |
| 86 ReportingPolicy policy_; | 72 ReportingPolicy policy_; |
| 87 std::unique_ptr<ReportingDelegate> delegate_; | |
| 88 | 73 |
| 89 std::unique_ptr<base::Clock> clock_; | 74 std::unique_ptr<base::Clock> clock_; |
| 90 std::unique_ptr<base::TickClock> tick_clock_; | 75 std::unique_ptr<base::TickClock> tick_clock_; |
| 91 std::unique_ptr<ReportingUploader> uploader_; | 76 std::unique_ptr<ReportingUploader> uploader_; |
| 92 | 77 |
| 93 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; | 78 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; |
| 94 bool initialized_; | |
| 95 | 79 |
| 96 std::unique_ptr<ReportingCache> cache_; | 80 std::unique_ptr<ReportingCache> cache_; |
| 97 | 81 |
| 98 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. | 82 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. |
| 99 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; | 83 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; |
| 100 | 84 |
| 101 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, | 85 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, |
| 102 // and |endpoint_manager_|. | 86 // and |endpoint_manager_|. |
| 103 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; | 87 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; |
| 104 | 88 |
| 105 // |persister_| must come after |delegate_|, |clock_|, |tick_clock_|, and | 89 // |persister_| must come after |clock_|, |tick_clock_|, and |cache_|. |
| 106 // |cache_|. | |
| 107 std::unique_ptr<ReportingPersister> persister_; | 90 std::unique_ptr<ReportingPersister> persister_; |
| 108 | 91 |
| 109 // |garbage_collector_| must come after |tick_clock_| and |cache_|. | 92 // |garbage_collector_| must come after |tick_clock_| and |cache_|. |
| 110 std::unique_ptr<ReportingGarbageCollector> garbage_collector_; | 93 std::unique_ptr<ReportingGarbageCollector> garbage_collector_; |
| 111 | 94 |
| 112 // |network_change_observer_| must come after |cache_|. | 95 // |network_change_observer_| must come after |cache_|. |
| 113 std::unique_ptr<ReportingNetworkChangeObserver> network_change_observer_; | 96 std::unique_ptr<ReportingNetworkChangeObserver> network_change_observer_; |
| 114 | 97 |
| 115 DISALLOW_COPY_AND_ASSIGN(ReportingContext); | 98 DISALLOW_COPY_AND_ASSIGN(ReportingContext); |
| 116 }; | 99 }; |
| 117 | 100 |
| 118 } // namespace net | 101 } // namespace net |
| 119 | 102 |
| 120 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ | 103 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ |
| OLD | NEW |