Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_REPORTER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/callback.h" | |
| 14 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 15 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | |
| 19 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 20 | 22 |
| 21 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
| 22 #include "base/android/application_status_listener.h" | 24 #include "base/android/application_status_listener.h" |
| 23 #endif | 25 #endif |
| 24 | 26 |
| 25 namespace data_usage { | 27 namespace data_usage { |
| 26 struct DataUse; | 28 struct DataUse; |
| 27 } | 29 } |
| 28 | 30 |
| 29 namespace chrome { | 31 namespace chrome { |
| 30 | 32 |
| 31 namespace android { | 33 namespace android { |
| 32 | 34 |
| 33 class DataUseTabModel; | |
| 34 class ExternalDataUseObserverBridge; | 35 class ExternalDataUseObserverBridge; |
| 35 | 36 |
| 36 // This class receives data use observations from ExternalDataUseObserver, | 37 // This class receives data use observations from ExternalDataUseObserver, |
| 37 // labels the data use using DataUseTabModel, and buffers the data use report. | 38 // labels the data use using DataUseTabModel, and buffers the data use report. |
| 38 // The buffered reports are submitted to the platform when a minimum number of | 39 // The buffered reports are submitted to the platform when a minimum number of |
| 39 // data usage bytes is reached, or when Chromium goes into background, or when | 40 // data usage bytes is reached, or when Chromium goes into background, or when |
| 40 // the previous report submission times out. This class is not thread safe, and | 41 // the previous report submission times out. This class is not thread safe, and |
| 41 // must only be accessed on UI thread. | 42 // must only be accessed on UI thread. |
| 42 class ExternalDataUseReporter { | 43 class ExternalDataUseReporter { |
| 43 public: | 44 public: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 54 DATAUSAGE_REPORT_SUBMISSION_LOST = 3, | 55 DATAUSAGE_REPORT_SUBMISSION_LOST = 3, |
| 55 DATAUSAGE_REPORT_SUBMISSION_MAX = 4 | 56 DATAUSAGE_REPORT_SUBMISSION_MAX = 4 |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 // The caller should guarantee that |data_use_tab_model| and | 59 // The caller should guarantee that |data_use_tab_model| and |
| 59 // |external_data_use_observer_bridge| to be non-null during the lifetime of | 60 // |external_data_use_observer_bridge| to be non-null during the lifetime of |
| 60 // |this|. |field_trial| is the field trial name to get the various | 61 // |this|. |field_trial| is the field trial name to get the various |
| 61 // paramenters from. | 62 // paramenters from. |
| 62 ExternalDataUseReporter( | 63 ExternalDataUseReporter( |
| 63 const char* field_trial, | 64 const char* field_trial, |
| 64 DataUseTabModel* data_use_tab_model, | 65 const base::Callback<bool(SessionID::id_type, |
| 65 ExternalDataUseObserverBridge* external_data_use_observer_bridge); | 66 const base::TimeTicks&, |
| 67 DataUseTabModel::TrackingInfo*)>& | |
| 68 get_tracking_info_callback, | |
| 69 const base::Callback<void(const std::string&, | |
| 70 const std::string&, | |
| 71 net::NetworkChangeNotifier::ConnectionType, | |
| 72 const std::string&, | |
| 73 const base::Time&, | |
| 74 const base::Time&, | |
|
tbansal1
2016/07/21 00:19:30
Pass by value.
Raj
2016/07/21 04:09:16
Done.
| |
| 75 int64_t, | |
| 76 int64_t)>& report_data_use_callback); | |
| 77 | |
| 66 virtual ~ExternalDataUseReporter(); | 78 virtual ~ExternalDataUseReporter(); |
| 67 | 79 |
| 68 void InitOnUIThread(); | 80 void InitOnUIThread(); |
| 69 | 81 |
| 70 // Notifies the ExternalDataUseReporter of data usage. The data use is | 82 // Notifies the ExternalDataUseReporter of data usage. The data use is |
| 71 // labeled using |data_use_tab_model_|, buffered and then reported to | 83 // labeled using |data_use_tab_model_|, buffered and then reported to |
| 72 // |external_data_use_observer_bridge_| later. | 84 // |external_data_use_observer_bridge_| later. |
| 73 void OnDataUse(const data_usage::DataUse& data_use); | 85 void OnDataUse(const data_usage::DataUse& data_use); |
| 74 | 86 |
| 75 void OnReportDataUseDone(bool success); | 87 void OnReportDataUseDone(bool success); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // submit the report immediately or to wait until |data_use_report_min_bytes_| | 194 // submit the report immediately or to wait until |data_use_report_min_bytes_| |
| 183 // unreported bytes are buffered. | 195 // unreported bytes are buffered. |
| 184 void SubmitBufferedDataUseReport(bool immediate); | 196 void SubmitBufferedDataUseReport(bool immediate); |
| 185 | 197 |
| 186 #if defined(OS_ANDROID) | 198 #if defined(OS_ANDROID) |
| 187 // Called whenever the application transitions from foreground to background | 199 // Called whenever the application transitions from foreground to background |
| 188 // or vice versa. | 200 // or vice versa. |
| 189 void OnApplicationStateChange(base::android::ApplicationState new_state); | 201 void OnApplicationStateChange(base::android::ApplicationState new_state); |
| 190 #endif | 202 #endif |
| 191 | 203 |
| 192 // Pointer to the ExternalDataUseObserverBridge in UI thread. Not owned by | 204 // Callback to be run to get the tracking info for a tab at a particular time. |
| 193 // |this|. | 205 const base::Callback<bool(SessionID::id_type, |
|
tbansal1
2016/07/21 00:19:30
Can this be typedef'ed so there is no need to type
Raj
2016/07/21 04:09:17
Done.
| |
| 194 ExternalDataUseObserverBridge* external_data_use_observer_bridge_; | 206 const base::TimeTicks&, |
| 207 DataUseTabModel::TrackingInfo*)> | |
| 208 get_tracking_info_callback_; | |
| 195 | 209 |
| 196 // Pointer to the DataUseTabModel in UI thread, Not owned by |this|. | 210 // Callback to be run to report the data usage to the underlying platform. |
| 197 DataUseTabModel* data_use_tab_model_; | 211 const base::Callback<void(const std::string&, |
|
tbansal1
2016/07/21 00:19:30
Same here, typedefing may make it more readable.
Raj
2016/07/21 04:09:16
Done.
| |
| 212 const std::string&, | |
| 213 net::NetworkChangeNotifier::ConnectionType, | |
| 214 const std::string&, | |
| 215 const base::Time&, | |
| 216 const base::Time&, | |
| 217 int64_t, | |
| 218 int64_t)> | |
| 219 report_data_use_callback_; | |
| 198 | 220 |
| 199 #if defined(OS_ANDROID) | 221 #if defined(OS_ANDROID) |
| 200 // Listens to when Chromium gets backgrounded and submits buffered data use | 222 // Listens to when Chromium gets backgrounded and submits buffered data use |
| 201 // reports. | 223 // reports. |
| 202 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_; | 224 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_; |
| 203 #endif | 225 #endif |
| 204 | 226 |
| 205 // Time when the currently pending data use report was submitted. | 227 // Time when the currently pending data use report was submitted. |
| 206 // |last_data_report_submitted_ticks_| is null if no data use report is | 228 // |last_data_report_submitted_ticks_| is null if no data use report is |
| 207 // currently pending. | 229 // currently pending. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 233 base::ThreadChecker thread_checker_; | 255 base::ThreadChecker thread_checker_; |
| 234 | 256 |
| 235 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter); | 257 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter); |
| 236 }; | 258 }; |
| 237 | 259 |
| 238 } // namespace android | 260 } // namespace android |
| 239 | 261 |
| 240 } // namespace chrome | 262 } // namespace chrome |
| 241 | 263 |
| 242 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ | 264 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ |
| OLD | NEW |