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 class Timer; | |
19 } // namespace base | 20 } // namespace base |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 class ReportingCache; | 24 class ReportingCache; |
24 class ReportingDelegate; | 25 class ReportingDelegate; |
25 class ReportingDeliveryAgent; | 26 class ReportingDeliveryAgent; |
26 class ReportingEndpointManager; | 27 class ReportingEndpointManager; |
28 class ReportingGarbageCollector; | |
27 class ReportingObserver; | 29 class ReportingObserver; |
28 class ReportingUploader; | 30 class ReportingUploader; |
29 class URLRequestContext; | 31 class URLRequestContext; |
30 | 32 |
31 // Contains the various internal classes that make up the Reporting system. | 33 // Contains the various internal classes that make up the Reporting system. |
32 // Wrapped by ReportingService, which provides the external interface. | 34 // Wrapped by ReportingService, which provides the external interface. |
33 class NET_EXPORT ReportingContext { | 35 class NET_EXPORT ReportingContext { |
34 public: | 36 public: |
35 static std::unique_ptr<ReportingContext> Create( | 37 static std::unique_ptr<ReportingContext> Create( |
36 const ReportingPolicy& policy, | 38 const ReportingPolicy& policy, |
37 std::unique_ptr<ReportingDelegate> delegate, | 39 std::unique_ptr<ReportingDelegate> delegate, |
38 URLRequestContext* request_context); | 40 URLRequestContext* request_context); |
39 | 41 |
40 ~ReportingContext(); | 42 ~ReportingContext(); |
41 | 43 |
42 const ReportingPolicy& policy() { return policy_; } | 44 const ReportingPolicy& policy() { return policy_; } |
43 ReportingDelegate* delegate() { return delegate_.get(); } | 45 ReportingDelegate* delegate() { return delegate_.get(); } |
44 | 46 |
45 base::Clock* clock() { return clock_.get(); } | 47 base::Clock* clock() { return clock_.get(); } |
46 base::TickClock* tick_clock() { return tick_clock_.get(); } | 48 base::TickClock* tick_clock() { return tick_clock_.get(); } |
49 base::Timer* garbage_collection_timer() { | |
50 return garbage_collection_timer_.get(); | |
51 } | |
47 ReportingUploader* uploader() { return uploader_.get(); } | 52 ReportingUploader* uploader() { return uploader_.get(); } |
48 | 53 |
49 ReportingCache* cache() { return cache_.get(); } | 54 ReportingCache* cache() { return cache_.get(); } |
50 ReportingEndpointManager* endpoint_manager() { | 55 ReportingEndpointManager* endpoint_manager() { |
51 return endpoint_manager_.get(); | 56 return endpoint_manager_.get(); |
52 } | 57 } |
53 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } | 58 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } |
59 ReportingGarbageCollector* garbage_collector() { | |
60 return garbage_collector_.get(); | |
61 } | |
54 | 62 |
55 void AddObserver(ReportingObserver* observer); | 63 void AddObserver(ReportingObserver* observer); |
56 void RemoveObserver(ReportingObserver* observer); | 64 void RemoveObserver(ReportingObserver* observer); |
57 | 65 |
58 void NotifyCacheUpdated(); | 66 void NotifyCacheUpdated(); |
59 | 67 |
60 protected: | 68 protected: |
61 ReportingContext(const ReportingPolicy& policy); | 69 ReportingContext(const ReportingPolicy& policy); |
62 | 70 |
63 void Init(std::unique_ptr<ReportingDelegate> delegate, | 71 void Init(std::unique_ptr<ReportingDelegate> delegate, |
64 std::unique_ptr<base::Clock> clock, | 72 std::unique_ptr<base::Clock> clock, |
65 std::unique_ptr<base::TickClock> tick_clock, | 73 std::unique_ptr<base::TickClock> tick_clock, |
74 std::unique_ptr<base::Timer> garbage_collection_timer, | |
66 std::unique_ptr<ReportingUploader> uploader); | 75 std::unique_ptr<ReportingUploader> uploader); |
67 | 76 |
68 private: | 77 private: |
69 ReportingPolicy policy_; | 78 ReportingPolicy policy_; |
70 std::unique_ptr<ReportingDelegate> delegate_; | 79 std::unique_ptr<ReportingDelegate> delegate_; |
71 | 80 |
72 std::unique_ptr<base::Clock> clock_; | 81 std::unique_ptr<base::Clock> clock_; |
73 std::unique_ptr<base::TickClock> tick_clock_; | 82 std::unique_ptr<base::TickClock> tick_clock_; |
83 std::unique_ptr<base::Timer> garbage_collection_timer_; | |
shivanisha
2017/04/05 16:44:05
Since the garbage_collector_ object is responsible
| |
74 std::unique_ptr<ReportingUploader> uploader_; | 84 std::unique_ptr<ReportingUploader> uploader_; |
75 | 85 |
76 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; | 86 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; |
77 | 87 |
78 std::unique_ptr<ReportingCache> cache_; | 88 std::unique_ptr<ReportingCache> cache_; |
79 | 89 |
80 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. | 90 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. |
81 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; | 91 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; |
82 | 92 |
83 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, | 93 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, |
84 // and |endpoint_manager_|. | 94 // and |endpoint_manager_|. |
85 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; | 95 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; |
86 | 96 |
97 // |garbage_collector_| must come after |tick_clock_|, | |
98 // |garbage_collection_timer_|, and |cache_|. | |
99 std::unique_ptr<ReportingGarbageCollector> garbage_collector_; | |
100 | |
87 DISALLOW_COPY_AND_ASSIGN(ReportingContext); | 101 DISALLOW_COPY_AND_ASSIGN(ReportingContext); |
88 }; | 102 }; |
89 | 103 |
90 } // namespace net | 104 } // namespace net |
91 | 105 |
92 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ | 106 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ |
OLD | NEW |