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

Side by Side Diff: components/domain_reliability/context.h

Issue 1180223006: Domain Reliability: Simplify configs and reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, make requested changes Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ 6 #define COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 12 matching lines...) Expand all
23 class Value; 23 class Value;
24 } 24 }
25 25
26 namespace domain_reliability { 26 namespace domain_reliability {
27 27
28 class DomainReliabilityDispatcher; 28 class DomainReliabilityDispatcher;
29 class DomainReliabilityUploader; 29 class DomainReliabilityUploader;
30 class MockableTime; 30 class MockableTime;
31 31
32 // The per-domain context for the Domain Reliability client; includes the 32 // The per-domain context for the Domain Reliability client; includes the
33 // domain's config and per-resource beacon queues. 33 // domain's config and per-resource beacon queues.
Randy Smith (Not in Mondays) 2015/10/29 22:36:10 Is this comment still valid? I see a beacon queue
Deprecated (see juliatuttle) 2015/11/02 23:19:30 Wow, no, that is super out of date. Fixed.
34 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityContext { 34 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityContext {
35 public: 35 public:
36 class DOMAIN_RELIABILITY_EXPORT Factory { 36 class DOMAIN_RELIABILITY_EXPORT Factory {
37 public: 37 public:
38 virtual ~Factory(); 38 virtual ~Factory();
39 virtual scoped_ptr<DomainReliabilityContext> CreateContextForConfig( 39 virtual scoped_ptr<DomainReliabilityContext> CreateContextForConfig(
40 scoped_ptr<const DomainReliabilityConfig> config) = 0; 40 scoped_ptr<const DomainReliabilityConfig> config) = 0;
41 }; 41 };
42 42
43 DomainReliabilityContext( 43 DomainReliabilityContext(
44 MockableTime* time, 44 MockableTime* time,
45 const DomainReliabilityScheduler::Params& scheduler_params, 45 const DomainReliabilityScheduler::Params& scheduler_params,
46 const std::string& upload_reporter_string, 46 const std::string& upload_reporter_string,
47 const base::TimeTicks* last_network_change_time, 47 const base::TimeTicks* last_network_change_time,
48 DomainReliabilityDispatcher* dispatcher, 48 DomainReliabilityDispatcher* dispatcher,
49 DomainReliabilityUploader* uploader, 49 DomainReliabilityUploader* uploader,
50 scoped_ptr<const DomainReliabilityConfig> config); 50 scoped_ptr<const DomainReliabilityConfig> config);
51 ~DomainReliabilityContext(); 51 ~DomainReliabilityContext();
52 52
53 // Notifies the context of a beacon on its domain(s); may or may not save the 53 // Notifies the context of a beacon on its domain(s); may or may not save the
54 // actual beacon to be uploaded, depending on the sample rates in the config, 54 // actual beacon to be uploaded, depending on the sample rates in the config,
55 // but will increment one of the request counters in any case. 55 // but will increment one of the request counters in any case.
56 void OnBeacon(const GURL& url, const DomainReliabilityBeacon& beacon); 56 void OnBeacon(scoped_ptr<DomainReliabilityBeacon> beacon);
57 57
58 // Called to clear browsing data, since beacons are like browsing history. 58 // Called to clear browsing data, since beacons are like browsing history.
59 void ClearBeacons(); 59 void ClearBeacons();
60 60
61 // Gets a Value containing data that can be formatted into a web page for 61 // Gets a Value containing data that can be formatted into a web page for
62 // debugging purposes. 62 // debugging purposes.
63 scoped_ptr<base::Value> GetWebUIData() const; 63 scoped_ptr<base::Value> GetWebUIData() const;
64 64
65 // Gets the beacons queued for upload in this context. |beacons_out| will be
Randy Smith (Not in Mondays) 2015/10/29 22:36:11 nit: |*beacons_out|.
Deprecated (see juliatuttle) 2015/11/02 23:19:30 Done.
66 // cleared and filled with pointers to the beacons; the pointers remain valid
67 // as long as no other requests are reported to the DomainReliabilityMonitor.
Randy Smith (Not in Mondays) 2015/10/29 22:36:11 nit, suggestion: These lifetime related requiremen
Deprecated (see juliatuttle) 2015/11/02 23:19:30 Would you be okay if I punted this to another CL t
Randy Smith (Not in Mondays) 2015/11/03 21:48:12 Sure.
65 void GetQueuedBeaconsForTesting( 68 void GetQueuedBeaconsForTesting(
66 std::vector<DomainReliabilityBeacon>* beacons_out) const; 69 std::vector<const DomainReliabilityBeacon*>* beacons_out) const;
67
68 void GetRequestCountsForTesting(
69 size_t resource_index,
70 uint32* successful_requests_out,
71 uint32* failed_requests_out) const;
72 70
73 const DomainReliabilityConfig& config() const { return *config_.get(); } 71 const DomainReliabilityConfig& config() const { return *config_.get(); }
74 72
75 // Maximum number of beacons queued per context; if more than this many are 73 // Maximum number of beacons queued per context; if more than this many are
76 // queued; the oldest beacons will be removed. 74 // queued; the oldest beacons will be removed.
77 static const size_t kMaxQueuedBeacons; 75 static const size_t kMaxQueuedBeacons;
78 76
79 private: 77 private:
80 class ResourceState; 78 typedef std::deque<DomainReliabilityBeacon*> BeaconDeque;
81 79
82 typedef std::deque<DomainReliabilityBeacon> BeaconDeque;
83 typedef ScopedVector<ResourceState> ResourceStateVector;
84 typedef ResourceStateVector::const_iterator ResourceStateIterator;
85
86 void InitializeResourceStates();
87 void ScheduleUpload(base::TimeDelta min_delay, base::TimeDelta max_delay); 80 void ScheduleUpload(base::TimeDelta min_delay, base::TimeDelta max_delay);
88 void StartUpload(); 81 void StartUpload();
89 void OnUploadComplete(const DomainReliabilityUploader::UploadResult& result); 82 void OnUploadComplete(const DomainReliabilityUploader::UploadResult& result);
90 83
91 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time) const; 84 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time,
85 const GURL& collector_url) const;
92 86
93 // Remembers the current state of the context when an upload starts. Can be 87 // Remembers the current state of the context when an upload starts. Can be
94 // called multiple times in a row (without |CommitUpload|) if uploads fail 88 // called multiple times in a row (without |CommitUpload|) if uploads fail
95 // and are retried. 89 // and are retried.
96 void MarkUpload(); 90 void MarkUpload();
97 91
98 // Uses the state remembered by |MarkUpload| to remove successfully uploaded 92 // Uses the state remembered by |MarkUpload| to remove successfully uploaded
99 // data but keep beacons and request counts added after the upload started. 93 // data but keep beacons and request counts added after the upload started.
100 void CommitUpload(); 94 void CommitUpload();
101 95
102 void RollbackUpload(); 96 void RollbackUpload();
103 97
104 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called 98 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called
105 // when there are too many beacons queued.) 99 // when there are too many beacons queued.)
106 void RemoveOldestBeacon(); 100 void RemoveOldestBeacon();
107 101
108 scoped_ptr<const DomainReliabilityConfig> config_; 102 scoped_ptr<const DomainReliabilityConfig> config_;
109 MockableTime* time_; 103 MockableTime* time_;
110 const std::string& upload_reporter_string_; 104 const std::string& upload_reporter_string_;
111 DomainReliabilityScheduler scheduler_; 105 DomainReliabilityScheduler scheduler_;
112 DomainReliabilityDispatcher* dispatcher_; 106 DomainReliabilityDispatcher* dispatcher_;
113 DomainReliabilityUploader* uploader_; 107 DomainReliabilityUploader* uploader_;
114 108
115 BeaconDeque beacons_; 109 BeaconDeque beacons_;
116 size_t uploading_beacons_size_; 110 size_t uploading_beacons_size_;
117 // Each ResourceState in |states_| corresponds to the Resource of the same
118 // index in the config.
119 ResourceStateVector states_;
120 base::TimeTicks upload_time_; 111 base::TimeTicks upload_time_;
121 base::TimeTicks last_upload_time_; 112 base::TimeTicks last_upload_time_;
122 // The last network change time is not tracked per-context, so this is a 113 // The last network change time is not tracked per-context, so this is a
123 // pointer to that value in a wider (e.g. per-Monitor or unittest) scope. 114 // pointer to that value in a wider (e.g. per-Monitor or unittest) scope.
124 const base::TimeTicks* last_network_change_time_; 115 const base::TimeTicks* last_network_change_time_;
125 116
126 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_; 117 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_;
127 118
128 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext); 119 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext);
129 }; 120 };
130 121
131 } // namespace domain_reliability 122 } // namespace domain_reliability
132 123
133 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ 124 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698