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

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_observer.h

Issue 1491793002: Add histograms for ExternalDataUseObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_
6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 27 matching lines...) Expand all
38 38
39 // This class allows platform APIs that are external to Chromium to observe how 39 // This class allows platform APIs that are external to Chromium to observe how
40 // much data is used by Chromium on the current Android device. This class 40 // much data is used by Chromium on the current Android device. This class
41 // receives regular expressions from the platform. It also registers as a data 41 // receives regular expressions from the platform. It also registers as a data
42 // use observer with DataUseAggregator, filters the received observations by 42 // use observer with DataUseAggregator, filters the received observations by
43 // applying the regex matching to the URLs of the requests, and notifies the 43 // applying the regex matching to the URLs of the requests, and notifies the
44 // filtered data use to the platform. This class is not thread safe, and must 44 // filtered data use to the platform. This class is not thread safe, and must
45 // only be accessed on IO thread. 45 // only be accessed on IO thread.
46 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer { 46 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer {
47 public: 47 public:
48 // Result of data usage report submission. This enum must remain synchronized
49 // with the enum of the same name in metrics/histograms/histograms.xml.
50 enum DataUsageReportSubmissionResult {
51 // Submission of data use report to the external observer was successful.
52 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0,
53 // Submission of data use report to the external observer returned error.
54 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1,
55 // Submission of data use report to the external observer timed out.
56 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2,
57 // Data use report was lost before an attempt was made to submit it.
58 DATAUSAGE_REPORT_SUBMISSION_LOST = 3,
59 DATAUSAGE_REPORT_SUBMISSION_MAX = 4
60 };
61
48 // External data use observer field trial name. 62 // External data use observer field trial name.
49 static const char kExternalDataUseObserverFieldTrial[]; 63 static const char kExternalDataUseObserverFieldTrial[];
50 64
51 ExternalDataUseObserver( 65 ExternalDataUseObserver(
52 data_usage::DataUseAggregator* data_use_aggregator, 66 data_usage::DataUseAggregator* data_use_aggregator,
53 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 67 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
54 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 68 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
55 ~ExternalDataUseObserver() override; 69 ~ExternalDataUseObserver() override;
56 70
57 DataUseTabModel* GetDataUseTabModel() const; 71 DataUseTabModel* GetDataUseTabModel() const;
(...skipping 18 matching lines...) Expand all
76 90
77 DataUseTabModel* data_use_tab_model() const { 91 DataUseTabModel* data_use_tab_model() const {
78 return data_use_tab_model_.get(); 92 return data_use_tab_model_.get();
79 } 93 }
80 94
81 private: 95 private:
82 friend class DataUseTabModelTest; 96 friend class DataUseTabModelTest;
83 friend class ExternalDataUseObserverTest; 97 friend class ExternalDataUseObserverTest;
84 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); 98 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports);
85 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); 99 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize);
100 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, DataUseReportTimedOut);
86 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); 101 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction);
87 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved); 102 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved);
88 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); 103 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules);
89 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, 104 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest,
90 PeriodicFetchMatchingRules); 105 PeriodicFetchMatchingRules);
91 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); 106 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly);
92 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); 107 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest);
93 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, 108 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest,
94 TimestampsMergedCorrectly); 109 TimestampsMergedCorrectly);
95 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations); 110 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 196
182 // Aggregator that sends data use observations to |this|. 197 // Aggregator that sends data use observations to |this|.
183 data_usage::DataUseAggregator* data_use_aggregator_; 198 data_usage::DataUseAggregator* data_use_aggregator_;
184 199
185 // Maintains tab sessions. 200 // Maintains tab sessions.
186 scoped_ptr<DataUseTabModel> data_use_tab_model_; 201 scoped_ptr<DataUseTabModel> data_use_tab_model_;
187 202
188 // True if callback from |FetchMatchingRulesDone| is currently pending. 203 // True if callback from |FetchMatchingRulesDone| is currently pending.
189 bool matching_rules_fetch_pending_; 204 bool matching_rules_fetch_pending_;
190 205
191 // True if callback from |SubmitDataUseReportCallback| is currently pending. 206 // Time when the currently pending data use report was submitted.
192 bool submit_data_report_pending_; 207 // |last_data_report_submitted_ticks_| is null if no data use report is
208 // currently pending.
209 base::TimeTicks last_data_report_submitted_ticks_;
210
211 // |pending_report_bytes_| is the total byte count in the data use report that
212 // is currently pending.
213 int64_t pending_report_bytes_;
193 214
194 // Buffered data reports that need to be submitted to the 215 // Buffered data reports that need to be submitted to the
195 // |external_data_use_observer_bridge_|. 216 // |external_data_use_observer_bridge_|.
196 DataUseReports buffered_data_reports_; 217 DataUseReports buffered_data_reports_;
197 218
198 // |ui_task_runner_| is used to call ExternalDataUseObserverBridge methods on 219 // |ui_task_runner_| is used to call ExternalDataUseObserverBridge methods on
199 // UI thread. 220 // UI thread.
200 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 221 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
201 222
202 // Time when the data use reports were last received from DataUseAggregator. 223 // Time when the data use reports were last received from DataUseAggregator.
(...skipping 11 matching lines...) Expand all
214 // reports. 235 // reports.
215 int64_t total_bytes_buffered_; 236 int64_t total_bytes_buffered_;
216 237
217 // Duration after which matching rules are periodically fetched. 238 // Duration after which matching rules are periodically fetched.
218 const base::TimeDelta fetch_matching_rules_duration_; 239 const base::TimeDelta fetch_matching_rules_duration_;
219 240
220 // Minimum number of bytes that should be buffered before a data use report is 241 // Minimum number of bytes that should be buffered before a data use report is
221 // submitted. 242 // submitted.
222 const int64_t data_use_report_min_bytes_; 243 const int64_t data_use_report_min_bytes_;
223 244
245 // If a data use report is pending for more than |data_report_submit_timeout_|
246 // duration, it is considered as timed out.
247 const base::TimeDelta data_report_submit_timeout_;
248
224 base::ThreadChecker thread_checker_; 249 base::ThreadChecker thread_checker_;
225 250
226 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; 251 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_;
227 252
228 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); 253 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver);
229 }; 254 };
230 255
231 } // namespace android 256 } // namespace android
232 257
233 } // namespace chrome 258 } // namespace chrome
234 259
235 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ 260 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698