Chromium Code Reviews| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "components/data_usage/core/data_use_aggregator.h" | 21 #include "components/data_usage/core/data_use_aggregator.h" |
| 22 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 23 | 23 |
| 24 #if defined(OS_ANDROID) | |
| 25 #include "base/android/application_status_listener.h" | |
| 26 #endif | |
| 27 | |
| 24 namespace base { | 28 namespace base { |
| 25 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 26 } | 30 } |
| 27 | 31 |
| 28 namespace data_usage { | 32 namespace data_usage { |
| 29 struct DataUse; | 33 struct DataUse; |
| 30 } | 34 } |
| 31 | 35 |
| 32 namespace chrome { | 36 namespace chrome { |
| 33 | 37 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 74 |
| 71 // Returns the pointer to the DataUseTabModel object owned by |this|. The | 75 // Returns the pointer to the DataUseTabModel object owned by |this|. The |
| 72 // caller does not owns the returned pointer. | 76 // caller does not owns the returned pointer. |
| 73 DataUseTabModel* GetDataUseTabModel() const; | 77 DataUseTabModel* GetDataUseTabModel() const; |
| 74 | 78 |
| 75 // Called by ExternalDataUseObserverBridge::OnReportDataUseDone when a data | 79 // Called by ExternalDataUseObserverBridge::OnReportDataUseDone when a data |
| 76 // use report has been submitted. |success| is true if the request was | 80 // use report has been submitted. |success| is true if the request was |
| 77 // successfully submitted to the external data use observer by Java. | 81 // successfully submitted to the external data use observer by Java. |
| 78 void OnReportDataUseDone(bool success); | 82 void OnReportDataUseDone(bool success); |
| 79 | 83 |
| 84 #if defined(OS_ANDROID) | |
| 85 // Called whenever the application transitions from foreground to background | |
| 86 // and vice versa. | |
| 87 void OnApplicationStateChange(base::android::ApplicationState new_state); | |
|
tbansal1
2015/12/21 21:03:24
Does this method need to be public?
Raj
2015/12/29 23:17:35
Done.
| |
| 88 #endif | |
| 89 | |
| 80 // Called by DataUseMatcher. |should_register| is true if |this| should | 90 // Called by DataUseMatcher. |should_register| is true if |this| should |
| 81 // register as a data use observer. | 91 // register as a data use observer. |
| 82 void ShouldRegisterAsDataUseObserver(bool should_register); | 92 void ShouldRegisterAsDataUseObserver(bool should_register); |
| 83 | 93 |
| 84 base::WeakPtr<ExternalDataUseObserver> GetWeakPtr(); | 94 base::WeakPtr<ExternalDataUseObserver> GetWeakPtr(); |
| 85 | 95 |
| 86 private: | 96 private: |
| 87 friend class DataUseTabModelTest; | 97 friend class DataUseTabModelTest; |
| 88 friend class ExternalDataUseObserverTest; | 98 friend class ExternalDataUseObserverTest; |
| 89 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); | 99 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, BufferDataUseReports); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 // network. | 193 // network. |
| 184 void BufferDataUseReport(const data_usage::DataUse& data_use, | 194 void BufferDataUseReport(const data_usage::DataUse& data_use, |
| 185 const std::string& label, | 195 const std::string& label, |
| 186 const base::Time& start_time, | 196 const base::Time& start_time, |
| 187 const base::Time& end_time); | 197 const base::Time& end_time); |
| 188 | 198 |
| 189 // Submits the first data report among the buffered data reports in | 199 // Submits the first data report among the buffered data reports in |
| 190 // |buffered_data_reports_|. Since an unordered map is used to buffer the | 200 // |buffered_data_reports_|. Since an unordered map is used to buffer the |
| 191 // reports, the order of reports may change. The reports are buffered in an | 201 // reports, the order of reports may change. The reports are buffered in an |
| 192 // arbitrary order and there are no guarantees that the next report to be | 202 // arbitrary order and there are no guarantees that the next report to be |
| 193 // submitted is the oldest one buffered. | 203 // submitted is the oldest one buffered. |immediate| indicates whether to |
| 194 void SubmitBufferedDataUseReport(); | 204 // submit the report immediately or to wait until |data_use_report_min_bytes_| |
| 205 // unreported bytes are buffered. | |
| 206 void SubmitBufferedDataUseReport(bool immediate); | |
| 195 | 207 |
| 196 // Aggregator that sends data use observations to |this|. | 208 // Aggregator that sends data use observations to |this|. |
| 197 data_usage::DataUseAggregator* data_use_aggregator_; | 209 data_usage::DataUseAggregator* data_use_aggregator_; |
| 198 | 210 |
| 199 // Maintains tab sessions and is owned by |this|. It is created on IO thread | 211 // Maintains tab sessions and is owned by |this|. It is created on IO thread |
| 200 // but afterwards, should only be accessed on UI thread. | 212 // but afterwards, should only be accessed on UI thread. |
| 201 DataUseTabModel* data_use_tab_model_; | 213 DataUseTabModel* data_use_tab_model_; |
| 202 | 214 |
| 203 // Time when the currently pending data use report was submitted. | 215 // Time when the currently pending data use report was submitted. |
| 204 // |last_data_report_submitted_ticks_| is null if no data use report is | 216 // |last_data_report_submitted_ticks_| is null if no data use report is |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 235 const base::TimeDelta fetch_matching_rules_duration_; | 247 const base::TimeDelta fetch_matching_rules_duration_; |
| 236 | 248 |
| 237 // Minimum number of bytes that should be buffered before a data use report is | 249 // Minimum number of bytes that should be buffered before a data use report is |
| 238 // submitted. | 250 // submitted. |
| 239 const int64_t data_use_report_min_bytes_; | 251 const int64_t data_use_report_min_bytes_; |
| 240 | 252 |
| 241 // If a data use report is pending for more than |data_report_submit_timeout_| | 253 // If a data use report is pending for more than |data_report_submit_timeout_| |
| 242 // duration, it is considered as timed out. | 254 // duration, it is considered as timed out. |
| 243 const base::TimeDelta data_report_submit_timeout_; | 255 const base::TimeDelta data_report_submit_timeout_; |
| 244 | 256 |
| 257 #if defined(OS_ANDROID) | |
| 258 // ApplicationStatusListener used to listen when Chromium gets backgrounded | |
| 259 // and submit buffered data use reports. | |
| 260 scoped_ptr<base::android::ApplicationStatusListener> app_state_listener_; | |
| 261 #endif | |
| 262 | |
| 245 // True if |this| is currently registered as a data use observer. | 263 // True if |this| is currently registered as a data use observer. |
| 246 bool registered_as_data_use_observer_; | 264 bool registered_as_data_use_observer_; |
| 247 | 265 |
| 248 base::ThreadChecker thread_checker_; | 266 base::ThreadChecker thread_checker_; |
| 249 | 267 |
| 250 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; | 268 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; |
| 251 | 269 |
| 252 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); | 270 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); |
| 253 }; | 271 }; |
| 254 | 272 |
| 255 } // namespace android | 273 } // namespace android |
| 256 | 274 |
| 257 } // namespace chrome | 275 } // namespace chrome |
| 258 | 276 |
| 259 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ | 277 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
| OLD | NEW |