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 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" | 5 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | |
| 14 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" | |
| 15 #include "components/data_usage/core/data_use.h" | 13 #include "components/data_usage/core/data_use.h" |
| 16 #include "components/variations/variations_associated_data.h" | 14 #include "components/variations/variations_associated_data.h" |
| 17 | 15 |
| 18 namespace chrome { | 16 namespace chrome { |
| 19 | 17 |
| 20 namespace android { | 18 namespace android { |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 // Default duration after which a pending data use report is considered timed | 22 // Default duration after which a pending data use report is considered timed |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return kDefaultDataUseReportMinBytes; | 91 return kDefaultDataUseReportMinBytes; |
| 94 } | 92 } |
| 95 | 93 |
| 96 } // namespace | 94 } // namespace |
| 97 | 95 |
| 98 // static | 96 // static |
| 99 const size_t ExternalDataUseReporter::kMaxBufferSize = 100; | 97 const size_t ExternalDataUseReporter::kMaxBufferSize = 100; |
| 100 | 98 |
| 101 ExternalDataUseReporter::ExternalDataUseReporter( | 99 ExternalDataUseReporter::ExternalDataUseReporter( |
| 102 const char* field_trial, | 100 const char* field_trial, |
| 103 DataUseTabModel* data_use_tab_model, | 101 const base::Callback<bool(SessionID::id_type, |
|
tbansal1
2016/07/21 00:19:30
You can use typedef here too.
Raj
2016/07/21 04:09:16
Done.
| |
| 104 ExternalDataUseObserverBridge* external_data_use_observer_bridge) | 102 const base::TimeTicks&, |
| 105 : external_data_use_observer_bridge_(external_data_use_observer_bridge), | 103 DataUseTabModel::TrackingInfo*)>& |
| 106 data_use_tab_model_(data_use_tab_model), | 104 get_tracking_info_callback, |
| 105 const base::Callback<void(const std::string&, | |
| 106 const std::string&, | |
| 107 net::NetworkChangeNotifier::ConnectionType, | |
| 108 const std::string&, | |
| 109 const base::Time&, | |
| 110 const base::Time&, | |
| 111 int64_t, | |
| 112 int64_t)>& report_data_use_callback) | |
| 113 : get_tracking_info_callback_(get_tracking_info_callback), | |
| 114 report_data_use_callback_(report_data_use_callback), | |
| 107 last_data_report_submitted_ticks_(base::TimeTicks()), | 115 last_data_report_submitted_ticks_(base::TimeTicks()), |
| 108 pending_report_bytes_(0), | 116 pending_report_bytes_(0), |
| 109 previous_report_time_(base::Time::Now()), | 117 previous_report_time_(base::Time::Now()), |
| 110 total_bytes_buffered_(0), | 118 total_bytes_buffered_(0), |
| 111 data_use_report_min_bytes_(GetMinBytes(field_trial)), | 119 data_use_report_min_bytes_(GetMinBytes(field_trial)), |
| 112 data_report_submit_timeout_(base::TimeDelta::FromMilliseconds( | 120 data_report_submit_timeout_(base::TimeDelta::FromMilliseconds( |
| 113 GetDataReportSubmitTimeoutMsec(field_trial))) { | 121 GetDataReportSubmitTimeoutMsec(field_trial))) { |
| 122 DCHECK(get_tracking_info_callback_); | |
| 123 DCHECK(report_data_use_callback_); | |
| 114 DCHECK(last_data_report_submitted_ticks_.is_null()); | 124 DCHECK(last_data_report_submitted_ticks_.is_null()); |
| 115 // Detach from current thread since rest of ExternalDataUseReporter lives on | 125 // Detach from current thread since rest of ExternalDataUseReporter lives on |
| 116 // the UI thread and the current thread may not be UI thread.. | 126 // the UI thread and the current thread may not be UI thread.. |
| 117 thread_checker_.DetachFromThread(); | 127 thread_checker_.DetachFromThread(); |
| 118 } | 128 } |
| 119 | 129 |
| 120 void ExternalDataUseReporter::InitOnUIThread() { | 130 void ExternalDataUseReporter::InitOnUIThread() { |
| 121 DCHECK(thread_checker_.CalledOnValidThread()); | 131 DCHECK(thread_checker_.CalledOnValidThread()); |
| 122 #if defined(OS_ANDROID) | 132 #if defined(OS_ANDROID) |
| 123 app_state_listener_.reset(new base::android::ApplicationStatusListener( | 133 app_state_listener_.reset(new base::android::ApplicationStatusListener( |
| 124 base::Bind(&ExternalDataUseReporter::OnApplicationStateChange, | 134 base::Bind(&ExternalDataUseReporter::OnApplicationStateChange, |
| 125 base::Unretained(this)))); | 135 base::Unretained(this)))); |
| 126 #endif | 136 #endif |
| 127 } | 137 } |
| 128 | 138 |
| 129 ExternalDataUseReporter::~ExternalDataUseReporter() { | 139 ExternalDataUseReporter::~ExternalDataUseReporter() { |
| 130 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
| 131 } | 141 } |
| 132 | 142 |
| 133 void ExternalDataUseReporter::OnDataUse(const data_usage::DataUse& data_use) { | 143 void ExternalDataUseReporter::OnDataUse(const data_usage::DataUse& data_use) { |
| 134 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
| 135 | 145 |
| 136 const base::Time now_time = base::Time::Now(); | 146 const base::Time now_time = base::Time::Now(); |
| 137 DataUseTabModel::TrackingInfo tracking_info; | 147 DataUseTabModel::TrackingInfo tracking_info; |
| 138 | 148 |
| 139 if (!data_use_tab_model_->GetTrackingInfoForTabAtTime( | 149 if (!get_tracking_info_callback_.Run(data_use.tab_id, data_use.request_start, |
| 140 data_use.tab_id, data_use.request_start, &tracking_info)) { | 150 &tracking_info)) { |
| 141 return; | 151 return; |
| 142 } | 152 } |
| 143 | 153 |
| 144 BufferDataUseReport(data_use, tracking_info.label, tracking_info.tag, | 154 BufferDataUseReport(data_use, tracking_info.label, tracking_info.tag, |
| 145 previous_report_time_, now_time); | 155 previous_report_time_, now_time); |
| 146 SubmitBufferedDataUseReport(false); | 156 SubmitBufferedDataUseReport(false); |
| 147 previous_report_time_ = now_time; | 157 previous_report_time_ = now_time; |
| 148 } | 158 } |
| 149 | 159 |
| 150 void ExternalDataUseReporter::OnReportDataUseDone(bool success) { | 160 void ExternalDataUseReporter::OnReportDataUseDone(bool success) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 276 |
| 267 DCHECK_EQ(0, pending_report_bytes_); | 277 DCHECK_EQ(0, pending_report_bytes_); |
| 268 DCHECK(last_data_report_submitted_ticks_.is_null()); | 278 DCHECK(last_data_report_submitted_ticks_.is_null()); |
| 269 pending_report_bytes_ = report.bytes_downloaded + report.bytes_uploaded; | 279 pending_report_bytes_ = report.bytes_downloaded + report.bytes_uploaded; |
| 270 last_data_report_submitted_ticks_ = ticks_now; | 280 last_data_report_submitted_ticks_ = ticks_now; |
| 271 | 281 |
| 272 // Remove the entry from the map. | 282 // Remove the entry from the map. |
| 273 buffered_data_reports_.erase(it); | 283 buffered_data_reports_.erase(it); |
| 274 total_bytes_buffered_ -= (report.bytes_downloaded + report.bytes_uploaded); | 284 total_bytes_buffered_ -= (report.bytes_downloaded + report.bytes_uploaded); |
| 275 | 285 |
| 276 external_data_use_observer_bridge_->ReportDataUse( | 286 report_data_use_callback_.Run(key.label, key.tag, key.connection_type, |
| 277 key.label, key.tag, key.connection_type, key.mcc_mnc, report.start_time, | 287 key.mcc_mnc, report.start_time, report.end_time, |
| 278 report.end_time, report.bytes_downloaded, report.bytes_uploaded); | 288 report.bytes_downloaded, report.bytes_uploaded); |
| 279 } | 289 } |
| 280 | 290 |
| 281 ExternalDataUseReporter::DataUseReportKey::DataUseReportKey( | 291 ExternalDataUseReporter::DataUseReportKey::DataUseReportKey( |
| 282 const std::string& label, | 292 const std::string& label, |
| 283 const std::string& tag, | 293 const std::string& tag, |
| 284 net::NetworkChangeNotifier::ConnectionType connection_type, | 294 net::NetworkChangeNotifier::ConnectionType connection_type, |
| 285 const std::string& mcc_mnc) | 295 const std::string& mcc_mnc) |
| 286 : label(label), | 296 : label(label), |
| 287 tag(tag), | 297 tag(tag), |
| 288 connection_type(connection_type), | 298 connection_type(connection_type), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 hash = hash * 23 + hash_function(k.label); | 331 hash = hash * 23 + hash_function(k.label); |
| 322 hash = hash * 31 + hash_function(k.tag); | 332 hash = hash * 31 + hash_function(k.tag); |
| 323 hash = hash * 43 + k.connection_type; | 333 hash = hash * 43 + k.connection_type; |
| 324 hash = hash * 83 + hash_function(k.mcc_mnc); | 334 hash = hash * 83 + hash_function(k.mcc_mnc); |
| 325 return hash; | 335 return hash; |
| 326 } | 336 } |
| 327 | 337 |
| 328 } // namespace android | 338 } // namespace android |
| 329 | 339 |
| 330 } // namespace chrome | 340 } // namespace chrome |
| OLD | NEW |