Chromium Code Reviews| 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/data_use_matcher.h" | 5 #include "chrome/browser/android/data_usage/data_use_matcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
| 16 #include "base/time/tick_clock.h" | 16 #include "base/time/tick_clock.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/android/data_usage/external_data_use_observer.h" | 18 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" |
| 19 #include "third_party/re2/src/re2/re2.h" | 19 #include "third_party/re2/src/re2/re2.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 namespace chrome { | 22 namespace chrome { |
| 23 | 23 |
| 24 namespace android { | 24 namespace android { |
| 25 | 25 |
| 26 DataUseMatcher::DataUseMatcher( | 26 DataUseMatcher::DataUseMatcher( |
| 27 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, | 27 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 28 const ExternalDataUseObserverBridge* external_data_use_observer_bridge, |
|
Raj
2016/03/08 06:33:07
ExternalDataUseObserverBridge lives in UI thread,
tbansal1
2016/03/08 18:15:00
I am confused. Is this related to the buffering of
Raj
2016/03/09 02:27:35
Sorry. Will split into 3 CLs.
| |
| 29 const base::WeakPtr<ExternalDataUseObserver>& external_data_use_observer, | |
| 30 const base::TimeDelta& default_matching_rule_expiration_duration) | 29 const base::TimeDelta& default_matching_rule_expiration_duration) |
| 31 : data_use_tab_model_(data_use_tab_model), | 30 : data_use_tab_model_(data_use_tab_model), |
| 32 default_matching_rule_expiration_duration_( | 31 default_matching_rule_expiration_duration_( |
| 33 default_matching_rule_expiration_duration), | 32 default_matching_rule_expiration_duration), |
| 34 tick_clock_(new base::DefaultTickClock()), | 33 tick_clock_(new base::DefaultTickClock()), |
| 35 io_task_runner_(io_task_runner), | 34 external_data_use_observer_bridge_(external_data_use_observer_bridge) { |
| 36 external_data_use_observer_(external_data_use_observer) { | 35 DCHECK(external_data_use_observer_bridge_); |
| 37 DCHECK(io_task_runner_); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 DataUseMatcher::~DataUseMatcher() {} | 38 DataUseMatcher::~DataUseMatcher() {} |
| 41 | 39 |
| 42 void DataUseMatcher::RegisterURLRegexes( | 40 void DataUseMatcher::RegisterURLRegexes( |
| 43 const std::vector<std::string>& app_package_names, | 41 const std::vector<std::string>& app_package_names, |
| 44 const std::vector<std::string>& domain_path_regexes, | 42 const std::vector<std::string>& domain_path_regexes, |
| 45 const std::vector<std::string>& labels) { | 43 const std::vector<std::string>& labels) { |
| 46 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 DCHECK_EQ(app_package_names.size(), domain_path_regexes.size()); | 45 DCHECK_EQ(app_package_names.size(), domain_path_regexes.size()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 83 |
| 86 for (const std::string& label : removed_matching_rule_labels) { | 84 for (const std::string& label : removed_matching_rule_labels) { |
| 87 if (data_use_tab_model_) | 85 if (data_use_tab_model_) |
| 88 data_use_tab_model_->OnTrackingLabelRemoved(label); | 86 data_use_tab_model_->OnTrackingLabelRemoved(label); |
| 89 } | 87 } |
| 90 UMA_HISTOGRAM_COUNTS_100("DataUsage.MatchingRulesCount.Valid", | 88 UMA_HISTOGRAM_COUNTS_100("DataUsage.MatchingRulesCount.Valid", |
| 91 matching_rules_.size()); | 89 matching_rules_.size()); |
| 92 UMA_HISTOGRAM_COUNTS_100("DataUsage.MatchingRulesCount.Invalid", | 90 UMA_HISTOGRAM_COUNTS_100("DataUsage.MatchingRulesCount.Invalid", |
| 93 invalid_rules); | 91 invalid_rules); |
| 94 | 92 |
| 95 DCHECK(io_task_runner_); | 93 DCHECK(external_data_use_observer_bridge_); |
| 96 | 94 external_data_use_observer_bridge_->ShouldRegisterAsDataUseObserver( |
| 97 // Notify |external_data_use_observer_| if it should register as a data use | 95 !matching_rules_.empty()); |
| 98 // observer. | |
| 99 io_task_runner_->PostTask( | |
| 100 FROM_HERE, | |
| 101 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, | |
| 102 external_data_use_observer_, !matching_rules_.empty())); | |
| 103 } | 96 } |
| 104 | 97 |
| 105 bool DataUseMatcher::MatchesURL(const GURL& url, std::string* label) const { | 98 bool DataUseMatcher::MatchesURL(const GURL& url, std::string* label) const { |
| 106 const base::TimeTicks now_ticks = tick_clock_->NowTicks(); | 99 const base::TimeTicks now_ticks = tick_clock_->NowTicks(); |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
| 108 *label = ""; | 101 *label = ""; |
| 109 | 102 |
| 110 if (!url.is_valid() || url.is_empty()) | 103 if (!url.is_valid() || url.is_empty()) |
| 111 return false; | 104 return false; |
| 112 | 105 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 142 *label = matching_rule->label(); | 135 *label = matching_rule->label(); |
| 143 return true; | 136 return true; |
| 144 } | 137 } |
| 145 } | 138 } |
| 146 | 139 |
| 147 return false; | 140 return false; |
| 148 } | 141 } |
| 149 | 142 |
| 150 void DataUseMatcher::FetchMatchingRules() { | 143 void DataUseMatcher::FetchMatchingRules() { |
| 151 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
| 152 DCHECK(io_task_runner_); | 145 DCHECK(external_data_use_observer_bridge_); |
| 153 | 146 external_data_use_observer_bridge_->FetchMatchingRules(); |
| 154 // Notify |external_data_use_observer_| to fetch the rules. | |
| 155 io_task_runner_->PostTask( | |
| 156 FROM_HERE, base::Bind(&ExternalDataUseObserver::FetchMatchingRules, | |
| 157 external_data_use_observer_)); | |
| 158 } | 147 } |
| 159 | 148 |
| 160 bool DataUseMatcher::HasValidRules() const { | 149 bool DataUseMatcher::HasValidRules() const { |
| 161 return !matching_rules_.empty(); | 150 return !matching_rules_.empty(); |
| 162 } | 151 } |
| 163 | 152 |
| 164 void DataUseMatcher::ParsePackageField(const std::string& app_package_name, | 153 void DataUseMatcher::ParsePackageField(const std::string& app_package_name, |
| 165 std::string* new_app_package_name, | 154 std::string* new_app_package_name, |
| 166 base::TimeTicks* expiration) const { | 155 base::TimeTicks* expiration) const { |
| 167 const char separator = '|'; | 156 const char separator = '|'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 return label_; | 193 return label_; |
| 205 } | 194 } |
| 206 | 195 |
| 207 const base::TimeTicks& DataUseMatcher::MatchingRule::expiration() const { | 196 const base::TimeTicks& DataUseMatcher::MatchingRule::expiration() const { |
| 208 return expiration_; | 197 return expiration_; |
| 209 } | 198 } |
| 210 | 199 |
| 211 } // namespace android | 200 } // namespace android |
| 212 | 201 |
| 213 } // namespace chrome | 202 } // namespace chrome |
| OLD | NEW |