| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/data_usage/core/data_use_aggregator.h" | 22 #include "components/data_usage/core/data_use_aggregator.h" |
| 23 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) |
| 26 #include "base/android/application_status_listener.h" |
| 27 #endif |
| 28 |
| 25 namespace base { | 29 namespace base { |
| 26 class SingleThreadTaskRunner; | 30 class SingleThreadTaskRunner; |
| 27 } | 31 } |
| 28 | 32 |
| 29 namespace data_usage { | 33 namespace data_usage { |
| 30 struct DataUse; | 34 struct DataUse; |
| 31 } | 35 } |
| 32 | 36 |
| 33 namespace chrome { | 37 namespace chrome { |
| 34 | 38 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 void ShouldRegisterAsDataUseObserver(bool should_register); | 87 void ShouldRegisterAsDataUseObserver(bool should_register); |
| 84 | 88 |
| 85 base::WeakPtr<ExternalDataUseObserver> GetWeakPtr(); | 89 base::WeakPtr<ExternalDataUseObserver> GetWeakPtr(); |
| 86 | 90 |
| 87 private: | 91 private: |
| 88 friend class DataUseTabModelTest; | 92 friend class DataUseTabModelTest; |
| 89 friend class ExternalDataUseObserverTest; | 93 friend class ExternalDataUseObserverTest; |
| 90 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); | 94 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); |
| 91 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); | 95 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferSize); |
| 92 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, DataUseReportTimedOut); | 96 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, DataUseReportTimedOut); |
| 97 #if defined(OS_ANDROID) |
| 98 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 99 DataUseReportingOnApplicationStatusChange); |
| 100 #endif |
| 93 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); | 101 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, HashFunction); |
| 94 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); | 102 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleMatchingRules); |
| 95 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 103 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 96 PeriodicFetchMatchingRules); | 104 PeriodicFetchMatchingRules); |
| 97 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 105 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 98 RegisteredAsDataUseObserver); | 106 RegisteredAsDataUseObserver); |
| 99 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); | 107 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ReportsMergedCorrectly); |
| 100 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); | 108 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); |
| 101 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 109 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 102 TimestampsMergedCorrectly); | 110 TimestampsMergedCorrectly); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // network. | 192 // network. |
| 185 void BufferDataUseReport(const data_usage::DataUse& data_use, | 193 void BufferDataUseReport(const data_usage::DataUse& data_use, |
| 186 const std::string& label, | 194 const std::string& label, |
| 187 const base::Time& start_time, | 195 const base::Time& start_time, |
| 188 const base::Time& end_time); | 196 const base::Time& end_time); |
| 189 | 197 |
| 190 // Submits the first data report among the buffered data reports in | 198 // Submits the first data report among the buffered data reports in |
| 191 // |buffered_data_reports_|. Since an unordered map is used to buffer the | 199 // |buffered_data_reports_|. Since an unordered map is used to buffer the |
| 192 // reports, the order of reports may change. The reports are buffered in an | 200 // reports, the order of reports may change. The reports are buffered in an |
| 193 // arbitrary order and there are no guarantees that the next report to be | 201 // arbitrary order and there are no guarantees that the next report to be |
| 194 // submitted is the oldest one buffered. | 202 // submitted is the oldest one buffered. |immediate| indicates whether to |
| 195 void SubmitBufferedDataUseReport(); | 203 // submit the report immediately or to wait until |data_use_report_min_bytes_| |
| 204 // unreported bytes are buffered. |
| 205 void SubmitBufferedDataUseReport(bool immediate); |
| 206 |
| 207 #if defined(OS_ANDROID) |
| 208 // Called whenever the application transitions from foreground to background |
| 209 // or vice versa. |
| 210 void OnApplicationStateChange(base::android::ApplicationState new_state); |
| 211 #endif |
| 196 | 212 |
| 197 // Aggregator that sends data use observations to |this|. | 213 // Aggregator that sends data use observations to |this|. |
| 198 data_usage::DataUseAggregator* data_use_aggregator_; | 214 data_usage::DataUseAggregator* data_use_aggregator_; |
| 199 | 215 |
| 200 // Maintains tab sessions and is owned by |this|. It is created on IO thread | 216 // Maintains tab sessions and is owned by |this|. It is created on IO thread |
| 201 // but afterwards, should only be accessed on UI thread. | 217 // but afterwards, should only be accessed on UI thread. |
| 202 DataUseTabModel* data_use_tab_model_; | 218 DataUseTabModel* data_use_tab_model_; |
| 203 | 219 |
| 204 // Time when the currently pending data use report was submitted. | 220 // Time when the currently pending data use report was submitted. |
| 205 // |last_data_report_submitted_ticks_| is null if no data use report is | 221 // |last_data_report_submitted_ticks_| is null if no data use report is |
| (...skipping 30 matching lines...) Expand all Loading... |
| 236 const base::TimeDelta fetch_matching_rules_duration_; | 252 const base::TimeDelta fetch_matching_rules_duration_; |
| 237 | 253 |
| 238 // Minimum number of bytes that should be buffered before a data use report is | 254 // Minimum number of bytes that should be buffered before a data use report is |
| 239 // submitted. | 255 // submitted. |
| 240 const int64_t data_use_report_min_bytes_; | 256 const int64_t data_use_report_min_bytes_; |
| 241 | 257 |
| 242 // If a data use report is pending for more than |data_report_submit_timeout_| | 258 // If a data use report is pending for more than |data_report_submit_timeout_| |
| 243 // duration, it is considered as timed out. | 259 // duration, it is considered as timed out. |
| 244 const base::TimeDelta data_report_submit_timeout_; | 260 const base::TimeDelta data_report_submit_timeout_; |
| 245 | 261 |
| 262 #if defined(OS_ANDROID) |
| 263 // Listens to when Chromium gets backgrounded and submits buffered data use |
| 264 // reports. |
| 265 scoped_ptr<base::android::ApplicationStatusListener> app_state_listener_; |
| 266 #endif |
| 267 |
| 246 // True if |this| is currently registered as a data use observer. | 268 // True if |this| is currently registered as a data use observer. |
| 247 bool registered_as_data_use_observer_; | 269 bool registered_as_data_use_observer_; |
| 248 | 270 |
| 249 base::ThreadChecker thread_checker_; | 271 base::ThreadChecker thread_checker_; |
| 250 | 272 |
| 251 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; | 273 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; |
| 252 | 274 |
| 253 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); | 275 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); |
| 254 }; | 276 }; |
| 255 | 277 |
| 256 } // namespace android | 278 } // namespace android |
| 257 | 279 |
| 258 } // namespace chrome | 280 } // namespace chrome |
| 259 | 281 |
| 260 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ | 282 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
| OLD | NEW |