| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 base::Bind(&DataUseTabModel::GetTrackingInfoForTabAtTime, | 72 base::Bind(&DataUseTabModel::GetTrackingInfoForTabAtTime, |
| 73 base::Unretained(data_use_tab_model_)), | 73 base::Unretained(data_use_tab_model_)), |
| 74 base::Bind(&ExternalDataUseObserverBridge::ReportDataUse, | 74 base::Bind(&ExternalDataUseObserverBridge::ReportDataUse, |
| 75 base::Unretained(external_data_use_observer_bridge_)))), | 75 base::Unretained(external_data_use_observer_bridge_)))), |
| 76 io_task_runner_(io_task_runner), | 76 io_task_runner_(io_task_runner), |
| 77 ui_task_runner_(ui_task_runner), | 77 ui_task_runner_(ui_task_runner), |
| 78 last_matching_rules_fetch_time_(base::TimeTicks::Now()), | 78 last_matching_rules_fetch_time_(base::TimeTicks::Now()), |
| 79 fetch_matching_rules_duration_( | 79 fetch_matching_rules_duration_( |
| 80 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), | 80 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), |
| 81 registered_as_data_use_observer_(false), | 81 registered_as_data_use_observer_(false), |
| 82 profile_signin_status_(false), |
| 82 weak_factory_(this) { | 83 weak_factory_(this) { |
| 83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 84 DCHECK(data_use_aggregator_); | 85 DCHECK(data_use_aggregator_); |
| 85 DCHECK(io_task_runner_); | 86 DCHECK(io_task_runner_); |
| 86 DCHECK(ui_task_runner_); | 87 DCHECK(ui_task_runner_); |
| 87 | 88 |
| 88 // Initialize the ExternalDataUseReporter object. It is okay to use | 89 // Initialize the ExternalDataUseReporter object. It is okay to use |
| 89 // base::Unretained here since |external_data_use_reporter_| is owned by | 90 // base::Unretained here since |external_data_use_reporter_| is owned by |
| 90 // |this|, and is destroyed on UI thread when |this| is destroyed. | 91 // |this|, and is destroyed on UI thread when |this| is destroyed. |
| 91 ui_task_runner_->PostTask( | 92 ui_task_runner_->PostTask( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (registered_as_data_use_observer_ == should_register) | 185 if (registered_as_data_use_observer_ == should_register) |
| 185 return; | 186 return; |
| 186 | 187 |
| 187 if (!registered_as_data_use_observer_ && should_register) | 188 if (!registered_as_data_use_observer_ && should_register) |
| 188 data_use_aggregator_->AddObserver(this); | 189 data_use_aggregator_->AddObserver(this); |
| 189 | 190 |
| 190 if (registered_as_data_use_observer_ && !should_register) | 191 if (registered_as_data_use_observer_ && !should_register) |
| 191 data_use_aggregator_->RemoveObserver(this); | 192 data_use_aggregator_->RemoveObserver(this); |
| 192 | 193 |
| 193 registered_as_data_use_observer_ = should_register; | 194 registered_as_data_use_observer_ = should_register; |
| 195 |
| 196 // It is okay to use base::Unretained here since |
| 197 // |external_data_use_observer_bridge_| is owned by |this|, and is destroyed |
| 198 // on UI thread when |this| is destroyed. |
| 199 ui_task_runner_->PostTask( |
| 200 FROM_HERE, |
| 201 base::Bind(&ExternalDataUseObserverBridge::RegisterGoogleVariationID, |
| 202 base::Unretained(external_data_use_observer_bridge_), |
| 203 registered_as_data_use_observer_ && profile_signin_status_)); |
| 194 } | 204 } |
| 195 | 205 |
| 196 void ExternalDataUseObserver::FetchMatchingRules() { | 206 void ExternalDataUseObserver::FetchMatchingRules() { |
| 197 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
| 198 | 208 |
| 199 last_matching_rules_fetch_time_ = base::TimeTicks::Now(); | 209 last_matching_rules_fetch_time_ = base::TimeTicks::Now(); |
| 200 | 210 |
| 201 // It is okay to use base::Unretained here since | 211 // It is okay to use base::Unretained here since |
| 202 // |external_data_use_observer_bridge_| is owned by |this|, and is destroyed | 212 // |external_data_use_observer_bridge_| is owned by |this|, and is destroyed |
| 203 // on UI thread when |this| is destroyed. | 213 // on UI thread when |this| is destroyed. |
| 204 ui_task_runner_->PostTask( | 214 ui_task_runner_->PostTask( |
| 205 FROM_HERE, | 215 FROM_HERE, |
| 206 base::Bind(&ExternalDataUseObserverBridge::FetchMatchingRules, | 216 base::Bind(&ExternalDataUseObserverBridge::FetchMatchingRules, |
| 207 base::Unretained(external_data_use_observer_bridge_))); | 217 base::Unretained(external_data_use_observer_bridge_))); |
| 208 } | 218 } |
| 209 | 219 |
| 210 base::WeakPtr<ExternalDataUseObserver> ExternalDataUseObserver::GetWeakPtr() { | 220 base::WeakPtr<ExternalDataUseObserver> ExternalDataUseObserver::GetWeakPtr() { |
| 211 DCHECK(thread_checker_.CalledOnValidThread()); | 221 DCHECK(thread_checker_.CalledOnValidThread()); |
| 212 return weak_factory_.GetWeakPtr(); | 222 return weak_factory_.GetWeakPtr(); |
| 213 } | 223 } |
| 214 | 224 |
| 215 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const { | 225 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const { |
| 216 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
| 217 return data_use_tab_model_; | 227 return data_use_tab_model_; |
| 218 } | 228 } |
| 219 | 229 |
| 220 void ExternalDataUseObserver::SetRegisterGoogleVariationID( | 230 void ExternalDataUseObserver::SetProfileSigninStatus(bool signin_status) { |
| 221 bool register_google_variation_id) { | |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
| 232 profile_signin_status_ = signin_status; |
| 233 |
| 223 // It is okay to use base::Unretained here since | 234 // It is okay to use base::Unretained here since |
| 224 // |external_data_use_observer_bridge_| is owned by |this|, and is destroyed | 235 // |external_data_use_observer_bridge_| is owned by |this|, and is destroyed |
| 225 // on UI thread when |this| is destroyed. | 236 // on UI thread when |this| is destroyed. |
| 226 ui_task_runner_->PostTask( | 237 ui_task_runner_->PostTask( |
| 227 FROM_HERE, | 238 FROM_HERE, |
| 228 base::Bind(&ExternalDataUseObserverBridge::SetRegisterGoogleVariationID, | 239 base::Bind(&ExternalDataUseObserverBridge::RegisterGoogleVariationID, |
| 229 base::Unretained(external_data_use_observer_bridge_), | 240 base::Unretained(external_data_use_observer_bridge_), |
| 230 register_google_variation_id)); | 241 registered_as_data_use_observer_ && profile_signin_status_)); |
| 231 } | 242 } |
| 232 | 243 |
| 233 } // namespace android | 244 } // namespace android |
| 234 | 245 |
| 235 } // namespace chrome | 246 } // namespace chrome |
| OLD | NEW |