Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: net/reporting/reporting_context.h

Issue 2751883003: Reporting: Implement serializer. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ReportingGarbageCollector; 27 class ReportingGarbageCollector;
28 class ReportingObserver; 28 class ReportingObserver;
29 class ReportingPersister;
29 class ReportingUploader; 30 class ReportingUploader;
30 class URLRequestContext; 31 class URLRequestContext;
31 32
32 // Contains the various internal classes that make up the Reporting system. 33 // Contains the various internal classes that make up the Reporting system.
33 // Wrapped by ReportingService, which provides the external interface. 34 // Wrapped by ReportingService, which provides the external interface.
34 class NET_EXPORT ReportingContext { 35 class NET_EXPORT ReportingContext {
35 public: 36 public:
36 static std::unique_ptr<ReportingContext> Create( 37 static std::unique_ptr<ReportingContext> Create(
37 const ReportingPolicy& policy, 38 const ReportingPolicy& policy,
38 std::unique_ptr<ReportingDelegate> delegate, 39 std::unique_ptr<ReportingDelegate> delegate,
39 URLRequestContext* request_context); 40 URLRequestContext* request_context);
40 41
41 ~ReportingContext(); 42 ~ReportingContext();
42 43
44 // Initializes the ReportingContext. This may take a while (e.g. it may
45 // involve reloading state persisted to disk). Should be called only once.
46 //
47 // Components of the ReportingContext won't reference their dependencies (e.g.
48 // the Clock/TickClock or Timers inside the individual components) until
49 // during/after the call to Init.
50 void Initialize();
51
52 bool initialized() const { return initialized_; }
53
43 const ReportingPolicy& policy() { return policy_; } 54 const ReportingPolicy& policy() { return policy_; }
44 ReportingDelegate* delegate() { return delegate_.get(); } 55 ReportingDelegate* delegate() { return delegate_.get(); }
45 56
46 base::Clock* clock() { return clock_.get(); } 57 base::Clock* clock() { return clock_.get(); }
47 base::TickClock* tick_clock() { return tick_clock_.get(); } 58 base::TickClock* tick_clock() { return tick_clock_.get(); }
48 ReportingUploader* uploader() { return uploader_.get(); } 59 ReportingUploader* uploader() { return uploader_.get(); }
49 60
50 ReportingCache* cache() { return cache_.get(); } 61 ReportingCache* cache() { return cache_.get(); }
51 ReportingEndpointManager* endpoint_manager() { 62 ReportingEndpointManager* endpoint_manager() {
52 return endpoint_manager_.get(); 63 return endpoint_manager_.get();
53 } 64 }
54 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); } 65 ReportingDeliveryAgent* delivery_agent() { return delivery_agent_.get(); }
55 ReportingGarbageCollector* garbage_collector() { 66 ReportingGarbageCollector* garbage_collector() {
56 return garbage_collector_.get(); 67 return garbage_collector_.get();
57 } 68 }
58 69
70 ReportingPersister* persister() { return persister_.get(); }
71
59 void AddObserver(ReportingObserver* observer); 72 void AddObserver(ReportingObserver* observer);
60 void RemoveObserver(ReportingObserver* observer); 73 void RemoveObserver(ReportingObserver* observer);
61 74
62 void NotifyCacheUpdated(); 75 void NotifyCacheUpdated();
63 76
64 protected: 77 protected:
65 ReportingContext(const ReportingPolicy& policy, 78 ReportingContext(const ReportingPolicy& policy,
66 std::unique_ptr<ReportingDelegate> delegate, 79 std::unique_ptr<ReportingDelegate> delegate,
67 std::unique_ptr<base::Clock> clock, 80 std::unique_ptr<base::Clock> clock,
68 std::unique_ptr<base::TickClock> tick_clock, 81 std::unique_ptr<base::TickClock> tick_clock,
69 std::unique_ptr<ReportingUploader> uploader); 82 std::unique_ptr<ReportingUploader> uploader);
70 83
71 private: 84 private:
72 ReportingPolicy policy_; 85 ReportingPolicy policy_;
73 std::unique_ptr<ReportingDelegate> delegate_; 86 std::unique_ptr<ReportingDelegate> delegate_;
74 87
75 std::unique_ptr<base::Clock> clock_; 88 std::unique_ptr<base::Clock> clock_;
76 std::unique_ptr<base::TickClock> tick_clock_; 89 std::unique_ptr<base::TickClock> tick_clock_;
77 std::unique_ptr<ReportingUploader> uploader_; 90 std::unique_ptr<ReportingUploader> uploader_;
78 91
79 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_; 92 base::ObserverList<ReportingObserver, /* check_empty= */ true> observers_;
93 bool initialized_;
80 94
81 std::unique_ptr<ReportingCache> cache_; 95 std::unique_ptr<ReportingCache> cache_;
82 96
83 // |endpoint_manager_| must come after |tick_clock_| and |cache_|. 97 // |endpoint_manager_| must come after |tick_clock_| and |cache_|.
84 std::unique_ptr<ReportingEndpointManager> endpoint_manager_; 98 std::unique_ptr<ReportingEndpointManager> endpoint_manager_;
85 99
86 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|, 100 // |delivery_agent_| must come after |tick_clock_|, |uploader_|, |cache_|,
87 // and |endpoint_manager_|. 101 // and |endpoint_manager_|.
88 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_; 102 std::unique_ptr<ReportingDeliveryAgent> delivery_agent_;
89 103
104 // |persister_| must come after |delegate_|, |clock_|, |tick_clock_|, and
105 // |cache_|.
106 std::unique_ptr<ReportingPersister> persister_;
107
90 // |garbage_collector_| must come after |tick_clock_| and |cache_|. 108 // |garbage_collector_| must come after |tick_clock_| and |cache_|.
91 std::unique_ptr<ReportingGarbageCollector> garbage_collector_; 109 std::unique_ptr<ReportingGarbageCollector> garbage_collector_;
92 110
93 DISALLOW_COPY_AND_ASSIGN(ReportingContext); 111 DISALLOW_COPY_AND_ASSIGN(ReportingContext);
94 }; 112 };
95 113
96 } // namespace net 114 } // namespace net
97 115
98 #endif // NET_REPORTING_REPORTING_CONTEXT_H_ 116 #endif // NET_REPORTING_REPORTING_CONTEXT_H_
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698