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