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 #include "chrome/browser/android/data_usage/external_data_use_observer.h" | 5 #include "chrome/browser/android/data_usage/external_data_use_observer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | |
10 #include "base/callback.h" | |
9 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram_base.h" | 14 #include "base/metrics/histogram_base.h" |
13 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
14 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
16 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
17 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" | 19 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" |
18 #include "components/data_usage/core/data_use.h" | 20 #include "components/data_usage/core/data_use.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 128 |
127 // static | 129 // static |
128 const size_t ExternalDataUseObserver::kMaxBufferSize = 100; | 130 const size_t ExternalDataUseObserver::kMaxBufferSize = 100; |
129 | 131 |
130 ExternalDataUseObserver::ExternalDataUseObserver( | 132 ExternalDataUseObserver::ExternalDataUseObserver( |
131 data_usage::DataUseAggregator* data_use_aggregator, | 133 data_usage::DataUseAggregator* data_use_aggregator, |
132 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 134 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
133 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 135 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
134 : data_use_aggregator_(data_use_aggregator), | 136 : data_use_aggregator_(data_use_aggregator), |
135 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()), | 137 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()), |
136 data_use_tab_model_(new DataUseTabModel()), | 138 data_use_tab_model_(new DataUseTabModel( |
139 base::Bind(&ExternalDataUseObserverBridge::FetchMatchingRules, | |
140 base::Unretained(external_data_use_observer_bridge_)), | |
tbansal1
2016/07/18 17:04:38
Add comment about why it is okay to use base::Unre
Raj
2016/07/19 00:19:02
Done.
| |
141 base::Bind( | |
142 &ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver, | |
143 base::Unretained(external_data_use_observer_bridge_)))), | |
137 last_data_report_submitted_ticks_(base::TimeTicks()), | 144 last_data_report_submitted_ticks_(base::TimeTicks()), |
138 pending_report_bytes_(0), | 145 pending_report_bytes_(0), |
139 ui_task_runner_(ui_task_runner), | 146 ui_task_runner_(ui_task_runner), |
140 previous_report_time_(base::Time::Now()), | 147 previous_report_time_(base::Time::Now()), |
141 last_matching_rules_fetch_time_(base::TimeTicks::Now()), | 148 last_matching_rules_fetch_time_(base::TimeTicks::Now()), |
142 total_bytes_buffered_(0), | 149 total_bytes_buffered_(0), |
143 fetch_matching_rules_duration_( | 150 fetch_matching_rules_duration_( |
144 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), | 151 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), |
145 data_use_report_min_bytes_(GetMinBytes()), | 152 data_use_report_min_bytes_(GetMinBytes()), |
146 data_report_submit_timeout_( | 153 data_report_submit_timeout_( |
147 base::TimeDelta::FromMilliseconds(GetDataReportSubmitTimeoutMsec())), | 154 base::TimeDelta::FromMilliseconds(GetDataReportSubmitTimeoutMsec())), |
148 #if defined(OS_ANDROID) | 155 #if defined(OS_ANDROID) |
149 app_state_listener_(new base::android::ApplicationStatusListener( | 156 app_state_listener_(new base::android::ApplicationStatusListener( |
150 base::Bind(&ExternalDataUseObserver::OnApplicationStateChange, | 157 base::Bind(&ExternalDataUseObserver::OnApplicationStateChange, |
151 base::Unretained(this)))), | 158 base::Unretained(this)))), |
152 #endif | 159 #endif |
153 registered_as_data_use_observer_(false), | 160 registered_as_data_use_observer_(false), |
154 weak_factory_(this) { | 161 weak_factory_(this) { |
155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 162 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
156 DCHECK(data_use_aggregator_); | 163 DCHECK(data_use_aggregator_); |
157 DCHECK(io_task_runner); | 164 DCHECK(io_task_runner); |
158 DCHECK(ui_task_runner_); | 165 DCHECK(ui_task_runner_); |
159 DCHECK(last_data_report_submitted_ticks_.is_null()); | 166 DCHECK(last_data_report_submitted_ticks_.is_null()); |
160 | 167 |
161 ui_task_runner_->PostTask(FROM_HERE, | 168 ui_task_runner_->PostTask(FROM_HERE, |
162 base::Bind(&DataUseTabModel::InitOnUIThread, | 169 base::Bind(&DataUseTabModel::InitOnUIThread, |
tbansal1
2016/07/18 17:04:38
Is it possible that this initialization calls the
Raj
2016/07/19 00:19:02
Removed this. InitOnUIThread() is not needed.
| |
163 base::Unretained(data_use_tab_model_), | 170 base::Unretained(data_use_tab_model_))); |
164 external_data_use_observer_bridge_)); | |
165 | 171 |
166 // Initialize the ExternalDataUseObserverBridge object. It is okay to use | 172 // Initialize the ExternalDataUseObserverBridge object. It is okay to use |
167 // base::Unretained here since |external_data_use_observer_bridge_| is owned | 173 // base::Unretained here since |external_data_use_observer_bridge_| is owned |
168 // by |this|, and is destroyed on UI thread when |this| is destroyed. | 174 // by |this|, and is destroyed on UI thread when |this| is destroyed. |
169 ui_task_runner_->PostTask( | 175 ui_task_runner_->PostTask( |
170 FROM_HERE, | 176 FROM_HERE, |
171 base::Bind(&ExternalDataUseObserverBridge::Init, | 177 base::Bind(&ExternalDataUseObserverBridge::Init, |
172 base::Unretained(external_data_use_observer_bridge_), | 178 base::Unretained(external_data_use_observer_bridge_), |
173 io_task_runner, GetWeakPtr(), data_use_tab_model_)); | 179 io_task_runner, GetWeakPtr(), data_use_tab_model_)); |
174 } | 180 } |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 hash = hash * 23 + hash_function(k.label); | 458 hash = hash * 23 + hash_function(k.label); |
453 hash = hash * 31 + hash_function(k.tag); | 459 hash = hash * 31 + hash_function(k.tag); |
454 hash = hash * 43 + k.connection_type; | 460 hash = hash * 43 + k.connection_type; |
455 hash = hash * 83 + hash_function(k.mcc_mnc); | 461 hash = hash * 83 + hash_function(k.mcc_mnc); |
456 return hash; | 462 return hash; |
457 } | 463 } |
458 | 464 |
459 } // namespace android | 465 } // namespace android |
460 | 466 |
461 } // namespace chrome | 467 } // namespace chrome |
OLD | NEW |