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