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

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: Add new configs Created 5 years, 2 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void GetQueuedBeaconsForTesting( 65 void GetQueuedBeaconsForTesting(
66 std::vector<DomainReliabilityBeacon>* beacons_out) const; 66 std::vector<const DomainReliabilityBeacon*>* beacons_out) const;
davidben 2015/10/20 23:35:54 What is the lifetime story for these pointers? (Sh
Deprecated (see juliatuttle) 2015/10/26 19:08:41 Done.
67
68 void GetRequestCountsForTesting(
69 size_t resource_index,
70 uint32* successful_requests_out,
71 uint32* failed_requests_out) const;
72 67
73 const DomainReliabilityConfig& config() const { return *config_.get(); } 68 const DomainReliabilityConfig& config() const { return *config_.get(); }
74 69
75 // Maximum number of beacons queued per context; if more than this many are 70 // Maximum number of beacons queued per context; if more than this many are
76 // queued; the oldest beacons will be removed. 71 // queued; the oldest beacons will be removed.
77 static const size_t kMaxQueuedBeacons; 72 static const size_t kMaxQueuedBeacons;
78 73
79 private: 74 private:
80 class ResourceState; 75 typedef std::deque<DomainReliabilityBeacon*> BeaconDeque;
76 typedef BeaconDeque::iterator BeaconIterator;
77 typedef BeaconDeque::const_iterator BeaconConstIterator;
davidben 2015/10/20 23:35:54 Nit: I don't think BeaconConstIterator is used at
Deprecated (see juliatuttle) 2015/10/26 19:08:41 Done.
81 78
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); 79 void ScheduleUpload(base::TimeDelta min_delay, base::TimeDelta max_delay);
88 void StartUpload(); 80 void StartUpload();
89 void OnUploadComplete(const DomainReliabilityUploader::UploadResult& result); 81 void OnUploadComplete(const DomainReliabilityUploader::UploadResult& result);
90 82
91 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time) const; 83 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time,
84 const GURL& collector_url) const;
92 85
93 // Remembers the current state of the context when an upload starts. Can be 86 // 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 87 // called multiple times in a row (without |CommitUpload|) if uploads fail
95 // and are retried. 88 // and are retried.
96 void MarkUpload(); 89 void MarkUpload();
97 90
98 // Uses the state remembered by |MarkUpload| to remove successfully uploaded 91 // Uses the state remembered by |MarkUpload| to remove successfully uploaded
99 // data but keep beacons and request counts added after the upload started. 92 // data but keep beacons and request counts added after the upload started.
100 void CommitUpload(); 93 void CommitUpload();
101 94
102 void RollbackUpload(); 95 void RollbackUpload();
103 96
104 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called 97 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called
105 // when there are too many beacons queued.) 98 // when there are too many beacons queued.)
106 void RemoveOldestBeacon(); 99 void RemoveOldestBeacon();
107 100
108 scoped_ptr<const DomainReliabilityConfig> config_; 101 scoped_ptr<const DomainReliabilityConfig> config_;
109 MockableTime* time_; 102 MockableTime* time_;
110 const std::string& upload_reporter_string_; 103 const std::string& upload_reporter_string_;
111 DomainReliabilityScheduler scheduler_; 104 DomainReliabilityScheduler scheduler_;
112 DomainReliabilityDispatcher* dispatcher_; 105 DomainReliabilityDispatcher* dispatcher_;
113 DomainReliabilityUploader* uploader_; 106 DomainReliabilityUploader* uploader_;
114 107
115 BeaconDeque beacons_; 108 BeaconDeque beacons_;
116 size_t uploading_beacons_size_; 109 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_; 110 base::TimeTicks upload_time_;
121 base::TimeTicks last_upload_time_; 111 base::TimeTicks last_upload_time_;
122 // The last network change time is not tracked per-context, so this is a 112 // 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. 113 // pointer to that value in a wider (e.g. per-Monitor or unittest) scope.
124 const base::TimeTicks* last_network_change_time_; 114 const base::TimeTicks* last_network_change_time_;
125 115
126 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_; 116 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_;
127 117
128 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext); 118 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext);
129 }; 119 };
130 120
131 } // namespace domain_reliability 121 } // namespace domain_reliability
132 122
133 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ 123 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698