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

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 nits 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 <deque> 11 #include <deque>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 14
15 #include "base/callback.h"
15 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
16 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
20 #include "net/base/network_change_notifier.h" 22 #include "net/base/network_change_notifier.h"
21 23
22 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
23 #include "base/android/application_status_listener.h" 25 #include "base/android/application_status_listener.h"
24 #endif 26 #endif
25 27
26 namespace data_usage { 28 namespace data_usage {
27 struct DataUse; 29 struct DataUse;
28 } 30 }
29 31
30 namespace chrome { 32 namespace chrome {
31 33
32 namespace android { 34 namespace android {
33 35
34 class DataUseTabModel;
35 class ExternalDataUseObserverBridge;
36
37 // This class receives data use observations from ExternalDataUseObserver, 36 // This class receives data use observations from ExternalDataUseObserver,
38 // labels the data use using DataUseTabModel, and buffers the data use report. 37 // labels the data use using DataUseTabModel, and buffers the data use report.
39 // The buffered reports are submitted to the platform when a minimum number of 38 // The buffered reports are submitted to the platform when a minimum number of
40 // data usage bytes is reached, or when Chromium goes into background, or when 39 // data usage bytes is reached, or when Chromium goes into background, or when
41 // the previous report submission times out. This class is not thread safe, and 40 // the previous report submission times out. This class is not thread safe, and
42 // must only be accessed on UI thread. 41 // must only be accessed on UI thread.
43 class ExternalDataUseReporter { 42 class ExternalDataUseReporter {
44 public: 43 public:
44 typedef base::Callback<bool(SessionID::id_type,
45 const base::TimeTicks,
46 DataUseTabModel::TrackingInfo*)>
47 GetTrackingInfoCallback;
48
49 typedef base::Callback<void(const std::string&,
50 const std::string&,
51 net::NetworkChangeNotifier::ConnectionType,
52 const std::string&,
53 const base::Time,
54 const base::Time,
55 int64_t,
56 int64_t)>
57 ReportDataUseCallback;
58
45 // Result of data usage report submission. This enum must remain synchronized 59 // Result of data usage report submission. This enum must remain synchronized
46 // with the enum of the same name in metrics/histograms/histograms.xml. 60 // with the enum of the same name in metrics/histograms/histograms.xml.
47 enum DataUsageReportSubmissionResult { 61 enum DataUsageReportSubmissionResult {
48 // Submission of data use report to the external observer was successful. 62 // Submission of data use report to the external observer was successful.
49 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0, 63 DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL = 0,
50 // Submission of data use report to the external observer returned error. 64 // Submission of data use report to the external observer returned error.
51 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1, 65 DATAUSAGE_REPORT_SUBMISSION_FAILED = 1,
52 // Submission of data use report to the external observer timed out. 66 // Submission of data use report to the external observer timed out.
53 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2, 67 DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT = 2,
54 // Data use report was lost before an attempt was made to submit it. 68 // Data use report was lost before an attempt was made to submit it.
55 DATAUSAGE_REPORT_SUBMISSION_LOST = 3, 69 DATAUSAGE_REPORT_SUBMISSION_LOST = 3,
56 DATAUSAGE_REPORT_SUBMISSION_MAX = 4 70 DATAUSAGE_REPORT_SUBMISSION_MAX = 4
57 }; 71 };
58 72
59 // The caller should guarantee that |data_use_tab_model| and 73 // The caller should guarantee that |data_use_tab_model| and
60 // |external_data_use_observer_bridge| to be non-null during the lifetime of 74 // |external_data_use_observer_bridge| to be non-null during the lifetime of
61 // |this|. |field_trial| is the field trial name to get the various 75 // |this|. |field_trial| is the field trial name to get the various
62 // paramenters from. 76 // paramenters from.
63 ExternalDataUseReporter( 77 ExternalDataUseReporter(
64 const char* field_trial, 78 const char* field_trial,
65 DataUseTabModel* data_use_tab_model, 79 const GetTrackingInfoCallback& get_tracking_info_callback,
66 ExternalDataUseObserverBridge* external_data_use_observer_bridge); 80 const ReportDataUseCallback& report_data_use_callback);
81
67 virtual ~ExternalDataUseReporter(); 82 virtual ~ExternalDataUseReporter();
68 83
69 void InitOnUIThread(); 84 void InitOnUIThread();
70 85
71 // Notifies the ExternalDataUseReporter of data usage. The data use is labeled 86 // Notifies the ExternalDataUseReporter of data usage. The data use is labeled
72 // using |data_use_tab_model_|, buffered and then reported to 87 // using |data_use_tab_model_|, buffered and then reported to
73 // |external_data_use_observer_bridge_| later. 88 // |external_data_use_observer_bridge_| later.
74 void OnDataUse(std::unique_ptr<const std::deque<const data_usage::DataUse>> 89 void OnDataUse(std::unique_ptr<const std::deque<const data_usage::DataUse>>
75 data_use_list); 90 data_use_list);
76 91
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // submit the report immediately or to wait until |data_use_report_min_bytes_| 199 // submit the report immediately or to wait until |data_use_report_min_bytes_|
185 // unreported bytes are buffered. 200 // unreported bytes are buffered.
186 void SubmitBufferedDataUseReport(bool immediate); 201 void SubmitBufferedDataUseReport(bool immediate);
187 202
188 #if defined(OS_ANDROID) 203 #if defined(OS_ANDROID)
189 // Called whenever the application transitions from foreground to background 204 // Called whenever the application transitions from foreground to background
190 // or vice versa. 205 // or vice versa.
191 void OnApplicationStateChange(base::android::ApplicationState new_state); 206 void OnApplicationStateChange(base::android::ApplicationState new_state);
192 #endif 207 #endif
193 208
194 // Pointer to the ExternalDataUseObserverBridge in UI thread. Not owned by 209 // Callback to be run to get the tracking info for a tab at a particular time.
195 // |this|. 210 const GetTrackingInfoCallback get_tracking_info_callback_;
196 ExternalDataUseObserverBridge* external_data_use_observer_bridge_;
197 211
198 // Pointer to the DataUseTabModel in UI thread, Not owned by |this|. 212 // Callback to be run to report the data usage to the underlying platform.
199 DataUseTabModel* data_use_tab_model_; 213 const ReportDataUseCallback report_data_use_callback_;
200 214
201 #if defined(OS_ANDROID) 215 #if defined(OS_ANDROID)
202 // Listens to when Chromium gets backgrounded and submits buffered data use 216 // Listens to when Chromium gets backgrounded and submits buffered data use
203 // reports. 217 // reports.
204 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_; 218 std::unique_ptr<base::android::ApplicationStatusListener> app_state_listener_;
205 #endif 219 #endif
206 220
207 // Time when the currently pending data use report was submitted. 221 // Time when the currently pending data use report was submitted.
208 // |last_data_report_submitted_ticks_| is null if no data use report is 222 // |last_data_report_submitted_ticks_| is null if no data use report is
209 // currently pending. 223 // currently pending.
(...skipping 25 matching lines...) Expand all
235 base::ThreadChecker thread_checker_; 249 base::ThreadChecker thread_checker_;
236 250
237 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter); 251 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseReporter);
238 }; 252 };
239 253
240 } // namespace android 254 } // namespace android
241 255
242 } // namespace chrome 256 } // namespace chrome
243 257
244 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_ 258 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698