Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_reporter.h

Issue 2165123002: Make ExternalDataUseReporter independent of other data use classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
36 // This class receives data use observations from ExternalDataUseObserver, 35 // This class receives data use observations from ExternalDataUseObserver,
37 // labels the data use using DataUseTabModel, and buffers the data use report. 36 // 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 37 // 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 38 // 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 39 // the previous report submission times out. This class is not thread safe, and
41 // must only be accessed on UI thread. 40 // must only be accessed on UI thread.
42 class ExternalDataUseReporter { 41 class ExternalDataUseReporter {
43 public: 42 public:
43 typedef base::Callback<bool(SessionID::id_type,
44 const base::TimeTicks,
45 DataUseTabModel::TrackingInfo*)>
46 GetTrackingInfoCallback;
47
48 typedef base::Callback<void(const std::string&,
49 const std::string&,
50 net::NetworkChangeNotifier::ConnectionType,
51 const std::string&,
52 const base::Time,
53 const base::Time,
54 int64_t,
55 int64_t)>
56 ReportDataUseCallback;
57
44 // Result of data usage report submission. This enum must remain synchronized 58 // Result of data usage report submission. This enum must remain synchronized
45 // with the enum of the same name in metrics/histograms/histograms.xml. 59 // with the enum of the same name in metrics/histograms/histograms.xml.
46 enum DataUsageReportSubmissionResult { 60 enum DataUsageReportSubmissionResult {
47 // Submission of data use report to the external observer was successful. 61 // Submission of data use report to the external observer was successful.
48 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0, 62 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0,
49 // Submission of data use report to the external observer returned error. 63 // Submission of data use report to the external observer returned error.
50 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1, 64 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1,
51 // Submission of data use report to the external observer timed out. 65 // Submission of data use report to the external observer timed out.
52 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2, 66 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2,
53 // Data use report was lost before an attempt was made to submit it. 67 // Data use report was lost before an attempt was made to submit it.
54 DATAUSAGE_REPORT_SUBMISSION_LOST = 3, 68 DATAUSAGE_REPORT_SUBMISSION_LOST = 3,
55 DATAUSAGE_REPORT_SUBMISSION_MAX = 4 69 DATAUSAGE_REPORT_SUBMISSION_MAX = 4
56 }; 70 };
57 71
58 // The caller should guarantee that |data_use_tab_model| and 72 // The caller should guarantee that |data_use_tab_model| and
59 // |external_data_use_observer_bridge| to be non-null during the lifetime of 73 // |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 74 // |this|. |field_trial| is the field trial name to get the various
61 // paramenters from. 75 // paramenters from.
62 ExternalDataUseReporter( 76 ExternalDataUseReporter(
63 const char* field_trial, 77 const char* field_trial,
64 DataUseTabModel* data_use_tab_model, 78 const GetTrackingInfoCallback& get_tracking_info_callback,
65 ExternalDataUseObserverBridge* external_data_use_observer_bridge); 79 const ReportDataUseCallback& report_data_use_callback);
80
66 virtual ~ExternalDataUseReporter(); 81 virtual ~ExternalDataUseReporter();
67 82
68 void InitOnUIThread(); 83 void InitOnUIThread();
69 84
70 // Notifies the ExternalDataUseReporter of data usage. The data use is 85 // Notifies the ExternalDataUseReporter of data usage. The data use is
71 // labeled using |data_use_tab_model_|, buffered and then reported to 86 // labeled using |data_use_tab_model_|, buffered and then reported to
72 // |external_data_use_observer_bridge_| later. 87 // |external_data_use_observer_bridge_| later.
73 void OnDataUse(const data_usage::DataUse& data_use); 88 void OnDataUse(const data_usage::DataUse& data_use);
74 89
75 void OnReportDataUseDone(bool success); 90 void OnReportDataUseDone(bool success);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // submit the report immediately or to wait until |data_use_report_min_bytes_| 197 // submit the report immediately or to wait until |data_use_report_min_bytes_|
183 // unreported bytes are buffered. 198 // unreported bytes are buffered.
184 void SubmitBufferedDataUseReport(bool immediate); 199 void SubmitBufferedDataUseReport(bool immediate);
185 200
186 #if defined(OS_ANDROID) 201 #if defined(OS_ANDROID)
187 // Called whenever the application transitions from foreground to background 202 // Called whenever the application transitions from foreground to background
188 // or vice versa. 203 // or vice versa.
189 void OnApplicationStateChange(base::android::ApplicationState new_state); 204 void OnApplicationStateChange(base::android::ApplicationState new_state);
190 #endif 205 #endif
191 206
192 // Pointer to the ExternalDataUseObserverBridge in UI thread. Not owned by 207 // Callback to be run to get the tracking info for a tab at a particular time.
193 // |this|. 208 const GetTrackingInfoCallback get_tracking_info_callback_;
194 ExternalDataUseObserverBridge* external_data_use_observer_bridge_;
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 ReportDataUseCallback report_data_use_callback_;
198 212
199 #if defined(OS_ANDROID) 213 #if defined(OS_ANDROID)
200 // Listens to when Chromium gets backgrounded and submits buffered data use 214 // Listens to when Chromium gets backgrounded and submits buffered data use
201 // reports. 215 // reports.
202 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_; 216 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_;
203 #endif 217 #endif
204 218
205 // Time when the currently pending data use report was submitted. 219 // Time when the currently pending data use report was submitted.
206 // |last_data_report_submitted_ticks_| is null if no data use report is 220 // |last_data_report_submitted_ticks_| is null if no data use report is
207 // currently pending. 221 // currently pending.
(...skipping 25 matching lines...) Expand all
233 base::ThreadChecker thread_checker_; 247 base::ThreadChecker thread_checker_;
234 248
235 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter); 249 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter);
236 }; 250 };
237 251
238 } // namespace android 252 } // namespace android
239 253
240 } // namespace chrome 254 } // namespace chrome
241 255
242 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ 256 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698