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

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: Addressed sclittle comments 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 <jni.h> 8 #include <jni.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // owns a Java listener object that is notified of the data usage observations 47 // owns a Java listener object that is notified of the data usage observations
48 // of Chromium. This class receives regular expressions from the Java listener 48 // of Chromium. This class receives regular expressions from the Java listener
49 // object. It also registers as a data use observer with DataUseAggregator, 49 // object. It also registers as a data use observer with DataUseAggregator,
50 // filters the received observations by applying the regex matching to the URLs 50 // filters the received observations by applying the regex matching to the URLs
51 // of the requests, and notifies the filtered data use to the Java listener. The 51 // of the requests, and notifies the filtered data use to the Java listener. The
52 // Java object in turn may notify the platform APIs of the data usage 52 // Java object in turn may notify the platform APIs of the data usage
53 // observations. 53 // observations.
54 // TODO(tbansal): Create an inner class that manages the UI and IO threads. 54 // TODO(tbansal): Create an inner class that manages the UI and IO threads.
55 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer { 55 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer {
56 public: 56 public:
57 // Result of data usage report submission. This enum must remain synchronized
58 // with the enum of the same name in metrics/histograms/histograms.xml.
59 enum DataUsageReportSubmissionResult {
60 // Submission of data use report to the external observer was successful.
61 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0,
62 // Submission of data use report to the external observer returned error.
63 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1,
64 // Submission of data use report to the external observer timed out.
65 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2,
66 // Data use report was lost before an attempt was made to submit it.
67 DATAUSAGE_REPORT_SUBMISSION_LOST = 3,
68 DATAUSAGE_REPORT_SUBMISSION_MAX = 4
69 };
70
57 // External data use observer field trial name. 71 // External data use observer field trial name.
58 static const char kExternalDataUseObserverFieldTrial[]; 72 static const char kExternalDataUseObserverFieldTrial[];
59 73
60 ExternalDataUseObserver( 74 ExternalDataUseObserver(
61 data_usage::DataUseAggregator* data_use_aggregator, 75 data_usage::DataUseAggregator* data_use_aggregator,
62 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
63 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); 77 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
64 ~ExternalDataUseObserver() override; 78 ~ExternalDataUseObserver() override;
65 79
66 // Called by Java when new matching rules have been fetched. This may be 80 // Called by Java when new matching rules have been fetched. This may be
(...skipping 29 matching lines...) Expand all
96 // names. |label| must not be null. If a match is found, the |label| is set 110 // names. |label| must not be null. If a match is found, the |label| is set
97 // to the matching rule's label. 111 // to the matching rule's label.
98 bool MatchesAppPackageName(const std::string& app_package_name, 112 bool MatchesAppPackageName(const std::string& app_package_name,
99 std::string* label) const; 113 std::string* label) const;
100 114
101 DataUseTabModel* GetDataUseTabModel() const; 115 DataUseTabModel* GetDataUseTabModel() const;
102 116
103 private: 117 private:
104 friend class DataUseTabModelTest; 118 friend class DataUseTabModelTest;
105 friend class ExternalDataUseObserverTest; 119 friend class ExternalDataUseObserverTest;
106 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest);
107 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); 120 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports);
108 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); 121 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize);
109 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ChangeRegex); 122 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ChangeRegex);
123 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, DataUseReportTimedOut);
110 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); 124 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction);
111 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved); 125 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved);
112 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); 126 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules);
113 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleRegex); 127 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleRegex);
114 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, 128 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest,
115 PeriodicFetchMatchingRules); 129 PeriodicFetchMatchingRules);
116 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); 130 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly);
131 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest);
117 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, SingleRegex); 132 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, SingleRegex);
118 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, 133 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest,
119 TimestampsMergedCorrectly); 134 TimestampsMergedCorrectly);
120 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, TwoRegex); 135 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, TwoRegex);
121 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations); 136 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations);
122 137
123 // DataUseReportKey is a unique identifier for a data use report. 138 // DataUseReportKey is a unique identifier for a data use report.
124 struct DataUseReportKey { 139 struct DataUseReportKey {
125 DataUseReportKey(const std::string& label, 140 DataUseReportKey(const std::string& label,
126 net::NetworkChangeNotifier::ConnectionType connection_type, 141 net::NetworkChangeNotifier::ConnectionType connection_type,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // expressions are applied to the request URLs, and filtered data use is 287 // expressions are applied to the request URLs, and filtered data use is
273 // notified to |j_external_data_use_observer_|. 288 // notified to |j_external_data_use_observer_|.
274 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; 289 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_;
275 290
276 // Maintains tab sessions. 291 // Maintains tab sessions.
277 scoped_ptr<DataUseTabModel> data_use_tab_model_; 292 scoped_ptr<DataUseTabModel> data_use_tab_model_;
278 293
279 // True if callback from |FetchMatchingRulesDone| is currently pending. 294 // True if callback from |FetchMatchingRulesDone| is currently pending.
280 bool matching_rules_fetch_pending_; 295 bool matching_rules_fetch_pending_;
281 296
282 // True if callback from |SubmitDataUseReportCallback| is currently pending. 297 // Time when the currently pending data use report was submitted.
283 bool submit_data_report_pending_; 298 // |last_data_report_submitted_ticks_| is null if no data use report is
299 // currently pending.
300 base::TimeTicks last_data_report_submitted_ticks_;
301
302 // |pending_report_bytes_| is the total byte count in the data use report that
303 // is currently pending.
304 int64_t pending_report_bytes_;
284 305
285 // Contains matching rules. 306 // Contains matching rules.
286 std::vector<scoped_ptr<MatchingRule>> matching_rules_; 307 std::vector<scoped_ptr<MatchingRule>> matching_rules_;
287 308
288 // Buffered data reports that need to be submitted to the Java data use 309 // Buffered data reports that need to be submitted to the Java data use
289 // observer. 310 // observer.
290 DataUseReports buffered_data_reports_; 311 DataUseReports buffered_data_reports_;
291 312
292 // True if |this| is currently registered as a data use observer. 313 // True if |this| is currently registered as a data use observer.
293 bool registered_as_observer_; 314 bool registered_as_observer_;
(...skipping 16 matching lines...) Expand all
310 // reports. 331 // reports.
311 int64_t total_bytes_buffered_; 332 int64_t total_bytes_buffered_;
312 333
313 // Duration after which matching rules are periodically fetched. 334 // Duration after which matching rules are periodically fetched.
314 const base::TimeDelta fetch_matching_rules_duration_; 335 const base::TimeDelta fetch_matching_rules_duration_;
315 336
316 // Minimum number of bytes that should be buffered before a data use report is 337 // Minimum number of bytes that should be buffered before a data use report is
317 // submitted. 338 // submitted.
318 const int64_t data_use_report_min_bytes_; 339 const int64_t data_use_report_min_bytes_;
319 340
341 // If a data use report is pending for more than |data_report_submit_timeout_|
342 // duration, it is considered as timed out.
343 const base::TimeDelta data_report_submit_timeout_;
344
320 base::ThreadChecker thread_checker_; 345 base::ThreadChecker thread_checker_;
321 346
322 // |io_weak_factory_| and |ui_weak_factory_| are used for posting tasks on the 347 // |io_weak_factory_| and |ui_weak_factory_| are used for posting tasks on the
323 // IO and UI thread, respectively. 348 // IO and UI thread, respectively.
324 base::WeakPtrFactory<ExternalDataUseObserver> io_weak_factory_; 349 base::WeakPtrFactory<ExternalDataUseObserver> io_weak_factory_;
325 base::WeakPtrFactory<ExternalDataUseObserver> ui_weak_factory_; 350 base::WeakPtrFactory<ExternalDataUseObserver> ui_weak_factory_;
326 351
327 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); 352 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver);
328 }; 353 };
329 354
330 bool RegisterExternalDataUseObserver(JNIEnv* env); 355 bool RegisterExternalDataUseObserver(JNIEnv* env);
331 356
332 } // namespace android 357 } // namespace android
333 358
334 } // namespace chrome 359 } // namespace chrome
335 360
336 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ 361 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698