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/time/time.h" | 11 #include "base/time/time.h" |
11 #include "net/base/backoff_entry.h" | 12 #include "net/base/backoff_entry.h" |
12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
13 #include "net/reporting/reporting_policy.h" | 14 #include "net/reporting/reporting_policy.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class Clock; | 17 class Clock; |
17 class TickClock; | 18 class TickClock; |
18 } // namespace base | 19 } // namespace base |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 class ReportingCache; | 23 class ReportingCache; |
23 class ReportingDelegate; | 24 class ReportingDelegate; |
24 class ReportingDeliveryAgent; | 25 class ReportingDeliveryAgent; |
25 class ReportingEndpointManager; | 26 class ReportingEndpointManager; |
| 27 class ReportingObserver; |
26 class ReportingUploader; | 28 class ReportingUploader; |
27 class URLRequestContext; | 29 class URLRequestContext; |
28 | 30 |
29 // Contains the various internal classes that make up the Reporting system. | 31 // Contains the various internal classes that make up the Reporting system. |
30 // Wrapped by ReportingService, which provides the external interface. | 32 // Wrapped by ReportingService, which provides the external interface. |
31 class NET_EXPORT ReportingContext { | 33 class NET_EXPORT ReportingContext { |
32 public: | 34 public: |
33 static std::unique_ptr<ReportingContext> Create( | 35 static std::unique_ptr<ReportingContext> Create( |
34 const ReportingPolicy& policy, | 36 const ReportingPolicy& policy, |
35 std::unique_ptr<ReportingDelegate> delegate, | 37 std::unique_ptr<ReportingDelegate> delegate, |
36 URLRequestContext* request_context); | 38 URLRequestContext* request_context); |
37 | 39 |
38 ~ReportingContext(); | 40 ~ReportingContext(); |
39 | 41 |
40 const ReportingPolicy& policy() { return policy_; } | 42 const ReportingPolicy& policy() { return policy_; } |
41 ReportingDelegate* delegate() { return delegate_.get(); } | 43 ReportingDelegate* delegate() { return delegate_.get(); } |
42 | 44 |
43 base::Clock* clock() { return clock_.get(); } | 45 base::Clock* clock() { return clock_.get(); } |
44 base::TickClock* tick_clock() { return tick_clock_.get(); } | 46 base::TickClock* tick_clock() { return tick_clock_.get(); } |
45 ReportingUploader* uploader() { return uploader_.get(); } | 47 ReportingUploader* uploader() { return uploader_.get(); } |
46 | 48 |
47 ReportingCache* cache() { return cache_.get(); } | 49 ReportingCache* cache() { return cache_.get(); } |
48 ReportingEndpointManager* endpoint_manager() { | 50 ReportingEndpointManager* endpoint_manager() { |
49 return endpoint_manager_.get(); | 51 return endpoint_manager_.get(); |
50 } | 52 } |
51 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } | 53 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } |
52 | 54 |
| 55 void AddObserver(ReportingObserver* observer); |
| 56 void RemoveObserver(ReportingObserver* observer); |
| 57 |
| 58 void NotifyCacheUpdated(); |
| 59 |
53 protected: | 60 protected: |
54 ReportingContext(const ReportingPolicy& policy, | 61 ReportingContext(const ReportingPolicy& policy, |
55 std::unique_ptr<ReportingDelegate> delegate, | 62 std::unique_ptr<ReportingDelegate> delegate, |
56 std::unique_ptr<base::Clock> clock, | 63 std::unique_ptr<base::Clock> clock, |
57 std::unique_ptr<base::TickClock> tick_clock, | 64 std::unique_ptr<base::TickClock> tick_clock, |
58 std::unique_ptr<ReportingUploader> uploader); | 65 std::unique_ptr<ReportingUploader> uploader); |
59 | 66 |
60 private: | 67 private: |
61 ReportingPolicy policy_; | 68 ReportingPolicy policy_; |
62 std::unique_ptr<ReportingDelegate> delegate_; | 69 std::unique_ptr<ReportingDelegate> delegate_; |
63 | 70 |
64 std::unique_ptr<base::Clock> clock_; | 71 std::unique_ptr<base::Clock> clock_; |
65 std::unique_ptr<base::TickClock> tick_clock_; | 72 std::unique_ptr<base::TickClock> tick_clock_; |
66 std::unique_ptr<ReportingUploader> uploader_; | 73 std::unique_ptr<ReportingUploader> uploader_; |
67 | 74 |
| 75 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; |
| 76 |
68 std::unique_ptr<ReportingCache> cache_; | 77 std::unique_ptr<ReportingCache> cache_; |
69 | 78 |
70 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. | 79 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. |
71 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; | 80 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; |
72 | 81 |
73 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, | 82 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, |
74 // and |endpoint_manager_|. | 83 // and |endpoint_manager_|. |
75 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; | 84 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; |
76 | 85 |
77 DISALLOW_COPY_AND_ASSIGN(ReportingContext); | 86 DISALLOW_COPY_AND_ASSIGN(ReportingContext); |
78 }; | 87 }; |
79 | 88 |
80 } // namespace net | 89 } // namespace net |
81 | 90 |
82 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ | 91 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ |
OLD | NEW |