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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 11 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
11 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" | 12 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" |
12 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" | 13 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" |
13 #include "components/data_usage/core/data_use.h" | 14 #include "components/data_usage/core/data_use.h" |
14 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 | 17 |
(...skipping 27 matching lines...) Expand all Loading... |
44 // static | 45 // static |
45 const char ExternalDataUseObserver::kExternalDataUseObserverFieldTrial[] = | 46 const char ExternalDataUseObserver::kExternalDataUseObserverFieldTrial[] = |
46 "ExternalDataUseObserver"; | 47 "ExternalDataUseObserver"; |
47 | 48 |
48 ExternalDataUseObserver::ExternalDataUseObserver( | 49 ExternalDataUseObserver::ExternalDataUseObserver( |
49 data_usage::DataUseAggregator* data_use_aggregator, | 50 data_usage::DataUseAggregator* data_use_aggregator, |
50 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 52 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
52 : data_use_aggregator_(data_use_aggregator), | 53 : data_use_aggregator_(data_use_aggregator), |
53 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()), | 54 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()), |
54 data_use_tab_model_(new DataUseTabModel()), | 55 // It is okay to use base::Unretained for the callbacks, since |
| 56 // |external_data_use_observer_bridge_| is owned by |this|, and is |
| 57 // destroyed on UI thread after |this| and |data_use_tab_model_| are |
| 58 // destroyed. |
| 59 data_use_tab_model_(new DataUseTabModel( |
| 60 base::Bind(&ExternalDataUseObserverBridge::FetchMatchingRules, |
| 61 base::Unretained(external_data_use_observer_bridge_)), |
| 62 base::Bind( |
| 63 &ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver, |
| 64 base::Unretained(external_data_use_observer_bridge_)))), |
55 external_data_use_reporter_( | 65 external_data_use_reporter_( |
56 new ExternalDataUseReporter(kExternalDataUseObserverFieldTrial, | 66 new ExternalDataUseReporter(kExternalDataUseObserverFieldTrial, |
57 data_use_tab_model_, | 67 data_use_tab_model_, |
58 external_data_use_observer_bridge_)), | 68 external_data_use_observer_bridge_)), |
59 ui_task_runner_(ui_task_runner), | 69 ui_task_runner_(ui_task_runner), |
60 last_matching_rules_fetch_time_(base::TimeTicks::Now()), | 70 last_matching_rules_fetch_time_(base::TimeTicks::Now()), |
61 fetch_matching_rules_duration_( | 71 fetch_matching_rules_duration_( |
62 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), | 72 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), |
63 registered_as_data_use_observer_(false), | 73 registered_as_data_use_observer_(false), |
64 weak_factory_(this) { | 74 weak_factory_(this) { |
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
66 DCHECK(data_use_aggregator_); | 76 DCHECK(data_use_aggregator_); |
67 DCHECK(io_task_runner); | 77 DCHECK(io_task_runner); |
68 DCHECK(ui_task_runner_); | 78 DCHECK(ui_task_runner_); |
69 | 79 |
70 // Initialize the ExternalDataUseReporter object. It is okay to use | 80 // Initialize the ExternalDataUseReporter object. It is okay to use |
71 // base::Unretained here since |external_data_use_reporter_| is owned by | 81 // base::Unretained here since |external_data_use_reporter_| is owned by |
72 // |this|, and is destroyed on UI thread when |this| is destroyed. | 82 // |this|, and is destroyed on UI thread when |this| is destroyed. |
73 ui_task_runner_->PostTask( | 83 ui_task_runner_->PostTask( |
74 FROM_HERE, base::Bind(&ExternalDataUseReporter::InitOnUIThread, | 84 FROM_HERE, base::Bind(&ExternalDataUseReporter::InitOnUIThread, |
75 base::Unretained(external_data_use_reporter_))); | 85 base::Unretained(external_data_use_reporter_))); |
76 | 86 |
77 ui_task_runner_->PostTask(FROM_HERE, | |
78 base::Bind(&DataUseTabModel::InitOnUIThread, | |
79 base::Unretained(data_use_tab_model_), | |
80 external_data_use_observer_bridge_)); | |
81 | |
82 // Initialize the ExternalDataUseObserverBridge object. It is okay to use | 87 // Initialize the ExternalDataUseObserverBridge object. It is okay to use |
83 // base::Unretained here since |external_data_use_observer_bridge_| is owned | 88 // base::Unretained here since |external_data_use_observer_bridge_| is owned |
84 // by |this|, and is destroyed on UI thread when |this| is destroyed. | 89 // by |this|, and is destroyed on UI thread when |this| is destroyed. |
85 ui_task_runner_->PostTask( | 90 ui_task_runner_->PostTask( |
86 FROM_HERE, | 91 FROM_HERE, |
87 base::Bind(&ExternalDataUseObserverBridge::Init, | 92 base::Bind(&ExternalDataUseObserverBridge::Init, |
88 base::Unretained(external_data_use_observer_bridge_), | 93 base::Unretained(external_data_use_observer_bridge_), |
89 io_task_runner, GetWeakPtr(), data_use_tab_model_)); | 94 io_task_runner, GetWeakPtr(), data_use_tab_model_)); |
90 } | 95 } |
91 | 96 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 188 } |
184 | 189 |
185 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const { | 190 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const { |
186 DCHECK(thread_checker_.CalledOnValidThread()); | 191 DCHECK(thread_checker_.CalledOnValidThread()); |
187 return data_use_tab_model_; | 192 return data_use_tab_model_; |
188 } | 193 } |
189 | 194 |
190 } // namespace android | 195 } // namespace android |
191 | 196 |
192 } // namespace chrome | 197 } // namespace chrome |
OLD | NEW |