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

Side by Side Diff: chrome/browser/safe_browsing/certificate_reporting_service.h

Issue 2601203002: Fix crash during CertificateReportingService shutdown (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | chrome/browser/safe_browsing/certificate_reporting_service.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 DISALLOW_COPY_AND_ASSIGN(BoundedReportList); 98 DISALLOW_COPY_AND_ASSIGN(BoundedReportList);
99 }; 99 };
100 100
101 // Class that handles report uploads and implements the upload retry logic. 101 // Class that handles report uploads and implements the upload retry logic.
102 class Reporter { 102 class Reporter {
103 public: 103 public:
104 Reporter( 104 Reporter(
105 std::unique_ptr<certificate_reporting::ErrorReporter> error_reporter_, 105 std::unique_ptr<certificate_reporting::ErrorReporter> error_reporter_,
106 std::unique_ptr<BoundedReportList> retry_list, 106 std::unique_ptr<BoundedReportList> retry_list,
107 base::Clock* clock, 107 base::Clock* const clock,
108 base::TimeDelta report_ttl, 108 base::TimeDelta report_ttl,
109 bool retries_enabled); 109 bool retries_enabled);
110 ~Reporter(); 110 ~Reporter();
111 111
112 // Sends a report. If the send fails, the report will be added to the retry 112 // Sends a report. If the send fails, the report will be added to the retry
113 // list. 113 // list.
114 void Send(const std::string& serialized_report); 114 void Send(const std::string& serialized_report);
115 115
116 // Sends all pending reports. Skips reports older than the |report_ttl| 116 // Sends all pending reports. Skips reports older than the |report_ttl|
117 // provided in the constructor. Failed reports will be added to the retry 117 // provided in the constructor. Failed reports will be added to the retry
118 // list. 118 // list.
119 void SendPending(); 119 void SendPending();
120 120
121 // Getter and setters for testing: 121 // Getter and setters for testing:
122 size_t inflight_report_count_for_testing() const; 122 size_t inflight_report_count_for_testing() const;
123 BoundedReportList* GetQueueForTesting() const; 123 BoundedReportList* GetQueueForTesting() const;
124 124
125 private: 125 private:
126 void SendInternal(const Report& report); 126 void SendInternal(const Report& report);
127 void ErrorCallback(int report_id, const GURL& url, int error); 127 void ErrorCallback(int report_id, const GURL& url, int error);
128 void SuccessCallback(int report_id); 128 void SuccessCallback(int report_id);
129 129
130 std::unique_ptr<certificate_reporting::ErrorReporter> error_reporter_; 130 std::unique_ptr<certificate_reporting::ErrorReporter> error_reporter_;
131 std::unique_ptr<BoundedReportList> retry_list_; 131 std::unique_ptr<BoundedReportList> retry_list_;
132 base::Clock* clock_; 132 base::Clock* const clock_;
133 // Maximum age of a queued report. Reports older than this are discarded in 133 // Maximum age of a queued report. Reports older than this are discarded in
134 // the next SendPending() call. 134 // the next SendPending() call.
135 const base::TimeDelta report_ttl_; 135 const base::TimeDelta report_ttl_;
136 const bool retries_enabled_; 136 const bool retries_enabled_;
137 // Current report id, starting from zero and monotonically incrementing. 137 // Current report id, starting from zero and monotonically incrementing.
138 int current_report_id_; 138 int current_report_id_;
139 139
140 std::map<int, Report> inflight_reports_; 140 std::map<int, Report> inflight_reports_;
141 141
142 base::WeakPtrFactory<Reporter> weak_factory_; 142 base::WeakPtrFactory<Reporter> weak_factory_;
(...skipping 26 matching lines...) Expand all
169 // Enables or disables reporting. When disabled, pending report queue is 169 // Enables or disables reporting. When disabled, pending report queue is
170 // cleared and incoming reports are ignored. Reporting is enabled by default 170 // cleared and incoming reports are ignored. Reporting is enabled by default
171 // once the service is initialized. 171 // once the service is initialized.
172 void SetEnabled(bool enabled); 172 void SetEnabled(bool enabled);
173 173
174 // Getters for testing. 174 // Getters for testing.
175 Reporter* GetReporterForTesting() const; 175 Reporter* GetReporterForTesting() const;
176 static GURL GetReportingURLForTesting(); 176 static GURL GetReportingURLForTesting();
177 177
178 private: 178 private:
179 void Reset();
180
181 void InitializeOnIOThread( 179 void InitializeOnIOThread(
182 bool enabled, 180 bool enabled,
183 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 181 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
184 size_t max_queued_report_count, 182 size_t max_queued_report_count,
185 base::TimeDelta max_report_age, 183 base::TimeDelta max_report_age,
186 base::Clock* clock, 184 base::Clock* const clock,
187 uint8_t* server_public_key, 185 uint8_t* server_public_key,
188 uint32_t server_public_key_version); 186 uint32_t server_public_key_version);
189 187
190 // Resets the reporter on the IO thread. Changes in SafeBrowsing or extended 188 // Resets the reporter on the IO thread. Changes in SafeBrowsing or extended
191 // reporting enabled states cause the reporter to be reset. 189 // reporting enabled states cause the reporter to be reset.
192 // If |enabled| is false or |url_request_context_getter| is null, report is 190 // If |enabled| is false or |url_request_context_getter| is null, report is
193 // set to null, effectively cancelling all in flight uploads and clearing the 191 // set to null, effectively cancelling all in flight uploads and clearing the
194 // pending reports queue. 192 // pending reports queue.
195 void ResetOnIOThread(bool enabled, 193 void ResetOnIOThread(bool enabled,
196 net::URLRequestContext* url_request_context, 194 net::URLRequestContext* url_request_context,
197 size_t max_queued_report_count, 195 size_t max_queued_report_count,
198 base::TimeDelta max_report_age, 196 base::TimeDelta max_report_age,
199 base::Clock* clock, 197 base::Clock* const clock,
200 uint8_t* server_public_key, 198 uint8_t* server_public_key,
201 uint32_t server_public_key_version); 199 uint32_t server_public_key_version);
202 200
203 void OnPreferenceChanged(); 201 void OnPreferenceChanged();
204 202
205 const PrefService& pref_service_; 203 const PrefService& pref_service_;
206
207 // If true, reporting is enabled. When SafeBrowsing preferences change, this
208 // might be set to false.
209 bool enabled_;
210
211 net::URLRequestContext* url_request_context_; 204 net::URLRequestContext* url_request_context_;
212 std::unique_ptr<Reporter> reporter_; 205 std::unique_ptr<Reporter> reporter_;
213 206
214 // Subscription for url request context shutdowns. When this subscription is 207 // Subscription for url request context shutdowns. When this subscription is
215 // notified, it means SafeBrowsingService is shutting down, and this service 208 // notified, it means SafeBrowsingService is shutting down, and this service
216 // must also shut down. 209 // must also shut down.
217 std::unique_ptr<base::CallbackList<void(void)>::Subscription> 210 std::unique_ptr<base::CallbackList<void(void)>::Subscription>
218 safe_browsing_service_shutdown_subscription_; 211 safe_browsing_service_shutdown_subscription_;
219 212
220 // Subscription for state changes. When this subscription is notified, it 213 // Subscription for state changes. When this subscription is notified, it
221 // means SafeBrowsingService is enabled/disabled or one of the preferences 214 // means SafeBrowsingService is enabled/disabled or one of the preferences
222 // related to it is changed. 215 // related to it is changed.
223 std::unique_ptr<base::CallbackList<void(void)>::Subscription> 216 std::unique_ptr<base::CallbackList<void(void)>::Subscription>
224 safe_browsing_state_subscription_; 217 safe_browsing_state_subscription_;
225 218
226 // Maximum number of reports to be queued for retry. 219 // Maximum number of reports to be queued for retry.
227 size_t max_queued_report_count_; 220 const size_t max_queued_report_count_;
228 221
229 // Maximum age of the reports to be queued for retry, from the time the 222 // Maximum age of the reports to be queued for retry, from the time the
230 // certificate error was first encountered by the user. Any report older than 223 // certificate error was first encountered by the user. Any report older than
231 // this age is ignored and is not re-uploaded. 224 // this age is ignored and is not re-uploaded.
232 base::TimeDelta max_report_age_; 225 const base::TimeDelta max_report_age_;
233 226
234 base::Clock* clock_; 227 base::Clock* const clock_;
235 228
236 // Encryption parameters. 229 // Encryption parameters.
237 uint8_t* server_public_key_; 230 uint8_t* server_public_key_;
238 uint32_t server_public_key_version_; 231 uint32_t server_public_key_version_;
239 232
240 DISALLOW_COPY_AND_ASSIGN(CertificateReportingService); 233 DISALLOW_COPY_AND_ASSIGN(CertificateReportingService);
241 }; 234 };
242 235
243 #endif // CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ 236 #endif // CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/certificate_reporting_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698