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/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 const re2::RE2* pattern = matching_rules_[i]->pattern(); | 390 const re2::RE2* pattern = matching_rules_[i]->pattern(); |
391 if (re2::RE2::FullMatch(gurl.spec(), *pattern)) { | 391 if (re2::RE2::FullMatch(gurl.spec(), *pattern)) { |
392 *label = matching_rules_[i]->label(); | 392 *label = matching_rules_[i]->label(); |
393 return true; | 393 return true; |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 return false; | 397 return false; |
398 } | 398 } |
399 | 399 |
400 bool ExternalDataUseObserver::MatchesAppPackageName( | |
401 const std::string& app_package_name, | |
402 std::string* label) const { | |
403 DCHECK(thread_checker_.CalledOnValidThread()); | |
404 *label = ""; | |
405 | |
406 if (app_package_name.empty()) | |
407 return false; | |
408 | |
409 for (size_t i = 0; i < matching_rules_.size(); ++i) { | |
sclittle
2015/11/18 22:17:07
nit: use range-based for loop, e.g. something like
tbansal1
2015/11/18 23:46:43
Done.
| |
410 if (app_package_name == matching_rules_[i]->app_package_name()) { | |
411 *label = matching_rules_[i]->label(); | |
412 return true; | |
413 } | |
414 } | |
415 | |
416 return false; | |
417 } | |
418 | |
400 ExternalDataUseObserver::DataUseReportKey::DataUseReportKey( | 419 ExternalDataUseObserver::DataUseReportKey::DataUseReportKey( |
401 const std::string& label, | 420 const std::string& label, |
402 net::NetworkChangeNotifier::ConnectionType connection_type, | 421 net::NetworkChangeNotifier::ConnectionType connection_type, |
403 const std::string& mcc_mnc) | 422 const std::string& mcc_mnc) |
404 : label(label), connection_type(connection_type), mcc_mnc(mcc_mnc) {} | 423 : label(label), connection_type(connection_type), mcc_mnc(mcc_mnc) {} |
405 | 424 |
406 bool ExternalDataUseObserver::DataUseReportKey::operator==( | 425 bool ExternalDataUseObserver::DataUseReportKey::operator==( |
407 const DataUseReportKey& other) const { | 426 const DataUseReportKey& other) const { |
408 return label == other.label && connection_type == other.connection_type && | 427 return label == other.label && connection_type == other.connection_type && |
409 mcc_mnc == other.mcc_mnc; | 428 mcc_mnc == other.mcc_mnc; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 : app_package_name_(app_package_name), | 462 : app_package_name_(app_package_name), |
444 pattern_(pattern.Pass()), | 463 pattern_(pattern.Pass()), |
445 label_(label) {} | 464 label_(label) {} |
446 | 465 |
447 ExternalDataUseObserver::MatchingRule::~MatchingRule() {} | 466 ExternalDataUseObserver::MatchingRule::~MatchingRule() {} |
448 | 467 |
449 const re2::RE2* ExternalDataUseObserver::MatchingRule::pattern() const { | 468 const re2::RE2* ExternalDataUseObserver::MatchingRule::pattern() const { |
450 return pattern_.get(); | 469 return pattern_.get(); |
451 } | 470 } |
452 | 471 |
472 const std::string& ExternalDataUseObserver::MatchingRule::app_package_name() | |
473 const { | |
474 return app_package_name_; | |
475 } | |
476 | |
453 const std::string& ExternalDataUseObserver::MatchingRule::label() const { | 477 const std::string& ExternalDataUseObserver::MatchingRule::label() const { |
454 return label_; | 478 return label_; |
455 } | 479 } |
456 | 480 |
457 bool RegisterExternalDataUseObserver(JNIEnv* env) { | 481 bool RegisterExternalDataUseObserver(JNIEnv* env) { |
458 return RegisterNativesImpl(env); | 482 return RegisterNativesImpl(env); |
459 } | 483 } |
460 | 484 |
461 } // namespace android | 485 } // namespace android |
462 | 486 |
463 } // namespace chrome | 487 } // namespace chrome |
OLD | NEW |