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 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | |
|
tbansal1
2016/03/08 18:15:00
Why was this include removed?
Raj
2016/03/09 02:27:35
Done.
| |
| 17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 18 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 17 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 class SingleThreadTaskRunner; | |
| 22 class TickClock; | 20 class TickClock; |
| 23 } | 21 } |
| 24 | 22 |
| 25 namespace re2 { | 23 namespace re2 { |
| 26 class RE2; | 24 class RE2; |
| 27 } | 25 } |
| 28 | 26 |
| 29 class GURL; | 27 class GURL; |
| 30 | 28 |
| 31 namespace chrome { | 29 namespace chrome { |
| 32 | 30 |
| 33 namespace android { | 31 namespace android { |
| 34 | 32 |
| 35 class ExternalDataUseObserver; | 33 class ExternalDataUseObserverBridge; |
| 36 | 34 |
| 37 // DataUseMatcher stores the matching URL patterns and package names along with | 35 // DataUseMatcher stores the matching URL patterns and package names along with |
| 38 // the labels. It also provides functionality to get the matching label for a | 36 // the labels. It also provides functionality to get the matching label for a |
| 39 // given URL or package. DataUseMatcher is not thread safe. | 37 // given URL or package. DataUseMatcher is not thread safe. |
| 40 class DataUseMatcher { | 38 class DataUseMatcher { |
| 41 public: | 39 public: |
| 42 DataUseMatcher( | 40 DataUseMatcher( |
| 43 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, | 41 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 42 const ExternalDataUseObserverBridge* external_data_use_observer_bridge, |
| 45 const base::WeakPtr<ExternalDataUseObserver>& external_data_use_observer, | |
| 46 const base::TimeDelta& default_matching_rule_expiration_duration); | 43 const base::TimeDelta& default_matching_rule_expiration_duration); |
| 47 | 44 |
| 48 ~DataUseMatcher(); | 45 ~DataUseMatcher(); |
| 49 | 46 |
| 50 // Called by FetchMatchingRulesDoneOnIOThread to register multiple | 47 // Called by FetchMatchingRulesDoneOnIOThread to register multiple |
| 51 // case-insensitive regular expressions. If the url of the data use request | 48 // case-insensitive regular expressions. If the url of the data use request |
| 52 // matches any of the regular expression, the observation is passed to the | 49 // matches any of the regular expression, the observation is passed to the |
| 53 // Java listener. | 50 // Java listener. |
| 54 void RegisterURLRegexes(const std::vector<std::string>& app_package_names, | 51 void RegisterURLRegexes(const std::vector<std::string>& app_package_names, |
| 55 const std::vector<std::string>& domain_path_regexes, | 52 const std::vector<std::string>& domain_path_regexes, |
| 56 const std::vector<std::string>& labels); | 53 const std::vector<std::string>& labels); |
| 57 | 54 |
| 58 // Returns true if the |url| matches the registered regular expressions. | 55 // Returns true if the |url| matches the registered regular expressions. |
| 59 // |label| must not be null. If a match is found, the |label| is set to the | 56 // |label| must not be null. If a match is found, the |label| is set to the |
| 60 // matching rule's label. | 57 // matching rule's label. |
| 61 bool MatchesURL(const GURL& url, std::string* label) const WARN_UNUSED_RESULT; | 58 bool MatchesURL(const GURL& url, std::string* label) const WARN_UNUSED_RESULT; |
| 62 | 59 |
| 63 // Returns true if the |app_package_name| matches the registered package | 60 // Returns true if the |app_package_name| matches the registered package |
| 64 // names. |label| must not be null. If a match is found, the |label| is set | 61 // names. |label| must not be null. If a match is found, the |label| is set |
| 65 // to the matching rule's label. | 62 // to the matching rule's label. |
| 66 bool MatchesAppPackageName(const std::string& app_package_name, | 63 bool MatchesAppPackageName(const std::string& app_package_name, |
| 67 std::string* label) const WARN_UNUSED_RESULT; | 64 std::string* label) const WARN_UNUSED_RESULT; |
| 68 | 65 |
| 69 // Fetches the matching rules asynchronously from | 66 // Fetches the matching rules asynchronously from |
| 70 // |external_data_use_observer_|. | 67 // |external_data_use_observer_bridge_|. |
| 71 void FetchMatchingRules(); | 68 void FetchMatchingRules(); |
| 72 | 69 |
| 73 // Returns true if there is any valid matching rule. | 70 // Returns true if there is any valid matching rule. |
| 74 bool HasValidRules() const; | 71 bool HasValidRules() const; |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 friend class DataUseMatcherTest; | 74 friend class DataUseMatcherTest; |
| 78 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest, | 75 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest, |
| 79 EncodeExpirationTimeInPackageName); | 76 EncodeExpirationTimeInPackageName); |
| 80 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest, | 77 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 // |data_use_tab_model_| is notified if a label is removed from the set of | 127 // |data_use_tab_model_| is notified if a label is removed from the set of |
| 131 // matching labels. | 128 // matching labels. |
| 132 base::WeakPtr<DataUseTabModel> data_use_tab_model_; | 129 base::WeakPtr<DataUseTabModel> data_use_tab_model_; |
| 133 | 130 |
| 134 // Default expiration duration of a matching rule, if expiration is not | 131 // Default expiration duration of a matching rule, if expiration is not |
| 135 // specified in the rule. | 132 // specified in the rule. |
| 136 const base::TimeDelta default_matching_rule_expiration_duration_; | 133 const base::TimeDelta default_matching_rule_expiration_duration_; |
| 137 | 134 |
| 138 // TickClock used for obtaining the current time. | 135 // TickClock used for obtaining the current time. |
| 139 scoped_ptr<base::TickClock> tick_clock_; | 136 scoped_ptr<base::TickClock> tick_clock_; |
| 140 // |io_task_runner_| is used to call ExternalDataUseObserver methods on | |
| 141 // IO thread. | |
| 142 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 143 | 137 |
| 144 // |external_data_use_observer_| is notified when matching rules are fetched. | 138 // Pointer to the ExternalDataUseObserverBridge owned by |
| 145 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer_; | 139 // ExternalDataUseObserver. DataUseTabModel(owner of |this|) and |
|
tbansal1
2016/03/08 18:15:00
nit: space before (
Raj
2016/03/09 02:27:35
Done.
| |
| 140 // ExternalDataUseObserverBridge are owned by ExternalDataUseObserver, and are | |
| 141 // destroyed in the order. | |
| 142 const ExternalDataUseObserverBridge* external_data_use_observer_bridge_; | |
| 146 | 143 |
| 147 DISALLOW_COPY_AND_ASSIGN(DataUseMatcher); | 144 DISALLOW_COPY_AND_ASSIGN(DataUseMatcher); |
| 148 }; | 145 }; |
| 149 | 146 |
| 150 } // namespace android | 147 } // namespace android |
| 151 | 148 |
| 152 } // namespace chrome | 149 } // namespace chrome |
| 153 | 150 |
| 154 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ | 151 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ |
| OLD | NEW |