| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // This class allows platform APIs that are external to Chromium to observe how | 45 // This class allows platform APIs that are external to Chromium to observe how |
| 46 // much data is used by Chromium on the current Android device. This class | 46 // much data is used by Chromium on the current Android device. This class |
| 47 // receives regular expressions from the platform. It also registers as a data | 47 // receives regular expressions from the platform. It also registers as a data |
| 48 // use observer with DataUseAggregator, filters the received observations by | 48 // use observer with DataUseAggregator, filters the received observations by |
| 49 // applying the regex matching to the URLs of the requests, and notifies the | 49 // applying the regex matching to the URLs of the requests, and notifies the |
| 50 // filtered data use to the platform. This class is not thread safe, and must | 50 // filtered data use to the platform. This class is not thread safe, and must |
| 51 // only be accessed on IO thread. | 51 // only be accessed on IO thread. |
| 52 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer { | 52 class ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer { |
| 53 public: | 53 public: |
| 54 // Result of data usage report submission. This enum must remain synchronized |
| 55 // with the enum of the same name in metrics/histograms/histograms.xml. |
| 56 enum DataUsageReportSubmissionResult { |
| 57 // Submission of data use report to the external observer was successful. |
| 58 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0, |
| 59 // Submission of data use report to the external observer returned error. |
| 60 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1, |
| 61 // Submission of data use report to the external observer timed out. |
| 62 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2, |
| 63 // Data use report was lost before an attempt was made to submit it. |
| 64 DATAUSAGE_REPORT_SUBMISSION_LOST = 3, |
| 65 DATAUSAGE_REPORT_SUBMISSION_MAX = 4 |
| 66 }; |
| 67 |
| 54 // External data use observer field trial name. | 68 // External data use observer field trial name. |
| 55 static const char kExternalDataUseObserverFieldTrial[]; | 69 static const char kExternalDataUseObserverFieldTrial[]; |
| 56 | 70 |
| 57 ExternalDataUseObserver( | 71 ExternalDataUseObserver( |
| 58 data_usage::DataUseAggregator* data_use_aggregator, | 72 data_usage::DataUseAggregator* data_use_aggregator, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 73 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 74 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
| 61 ~ExternalDataUseObserver() override; | 75 ~ExternalDataUseObserver() override; |
| 62 | 76 |
| 63 // Returns true if the |gurl| matches the registered regular expressions. | 77 // Returns true if the |gurl| matches the registered regular expressions. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 DataUseTabModel* data_use_tab_model() const { | 108 DataUseTabModel* data_use_tab_model() const { |
| 95 return data_use_tab_model_.get(); | 109 return data_use_tab_model_.get(); |
| 96 } | 110 } |
| 97 | 111 |
| 98 private: | 112 private: |
| 99 friend class DataUseTabModelTest; | 113 friend class DataUseTabModelTest; |
| 100 friend class ExternalDataUseObserverTest; | 114 friend class ExternalDataUseObserverTest; |
| 101 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); | 115 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); |
| 102 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); | 116 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); |
| 103 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ChangeRegex); | 117 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ChangeRegex); |
| 118 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, DataUseReportTimedOut); |
| 104 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); | 119 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); |
| 105 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved); | 120 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, LabelRemoved); |
| 106 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); | 121 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); |
| 107 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleRegex); | 122 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleRegex); |
| 108 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 123 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 109 PeriodicFetchMatchingRules); | 124 PeriodicFetchMatchingRules); |
| 110 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); | 125 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); |
| 111 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); | 126 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); |
| 112 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, SingleRegex); | 127 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, SingleRegex); |
| 113 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 128 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 250 |
| 236 // Aggregator that sends data use observations to |this|. | 251 // Aggregator that sends data use observations to |this|. |
| 237 data_usage::DataUseAggregator* data_use_aggregator_; | 252 data_usage::DataUseAggregator* data_use_aggregator_; |
| 238 | 253 |
| 239 // Maintains tab sessions. | 254 // Maintains tab sessions. |
| 240 scoped_ptr<DataUseTabModel> data_use_tab_model_; | 255 scoped_ptr<DataUseTabModel> data_use_tab_model_; |
| 241 | 256 |
| 242 // True if callback from |FetchMatchingRulesDone| is currently pending. | 257 // True if callback from |FetchMatchingRulesDone| is currently pending. |
| 243 bool matching_rules_fetch_pending_; | 258 bool matching_rules_fetch_pending_; |
| 244 | 259 |
| 245 // True if callback from |SubmitDataUseReportCallback| is currently pending. | 260 // Time when the currently pending data use report was submitted. |
| 246 bool submit_data_report_pending_; | 261 // |last_data_report_submitted_ticks_| is null if no data use report is |
| 262 // currently pending. |
| 263 base::TimeTicks last_data_report_submitted_ticks_; |
| 264 |
| 265 // |pending_report_bytes_| is the total byte count in the data use report that |
| 266 // is currently pending. |
| 267 int64_t pending_report_bytes_; |
| 247 | 268 |
| 248 // Contains matching rules. | 269 // Contains matching rules. |
| 249 std::vector<scoped_ptr<MatchingRule>> matching_rules_; | 270 std::vector<scoped_ptr<MatchingRule>> matching_rules_; |
| 250 | 271 |
| 251 // Buffered data reports that need to be submitted to the | 272 // Buffered data reports that need to be submitted to the |
| 252 // |external_data_use_observer_bridge_|. | 273 // |external_data_use_observer_bridge_|. |
| 253 DataUseReports buffered_data_reports_; | 274 DataUseReports buffered_data_reports_; |
| 254 | 275 |
| 255 // True if |this| is currently registered as a data use observer. | 276 // True if |this| is currently registered as a data use observer. |
| 256 bool registered_as_observer_; | 277 bool registered_as_observer_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 274 // reports. | 295 // reports. |
| 275 int64_t total_bytes_buffered_; | 296 int64_t total_bytes_buffered_; |
| 276 | 297 |
| 277 // Duration after which matching rules are periodically fetched. | 298 // Duration after which matching rules are periodically fetched. |
| 278 const base::TimeDelta fetch_matching_rules_duration_; | 299 const base::TimeDelta fetch_matching_rules_duration_; |
| 279 | 300 |
| 280 // Minimum number of bytes that should be buffered before a data use report is | 301 // Minimum number of bytes that should be buffered before a data use report is |
| 281 // submitted. | 302 // submitted. |
| 282 const int64_t data_use_report_min_bytes_; | 303 const int64_t data_use_report_min_bytes_; |
| 283 | 304 |
| 305 // If a data use report is pending for more than |data_report_submit_timeout_| |
| 306 // duration, it is considered as timed out. |
| 307 const base::TimeDelta data_report_submit_timeout_; |
| 308 |
| 284 base::ThreadChecker thread_checker_; | 309 base::ThreadChecker thread_checker_; |
| 285 | 310 |
| 286 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; | 311 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; |
| 287 | 312 |
| 288 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); | 313 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); |
| 289 }; | 314 }; |
| 290 | 315 |
| 291 } // namespace android | 316 } // namespace android |
| 292 | 317 |
| 293 } // namespace chrome | 318 } // namespace chrome |
| 294 | 319 |
| 295 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ | 320 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
| OLD | NEW |