Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: chrome/browser/android/data_usage/data_use_matcher.h

Issue 2158913002: Make DataUseTabModel and DataUseMatcher more independent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/data_usage/data_use_matcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
19
20 namespace base { 19 namespace base {
21 class TickClock; 20 class TickClock;
22 } 21 }
23 22
24 namespace re2 { 23 namespace re2 {
25 class RE2; 24 class RE2;
26 } 25 }
27 26
28 class GURL; 27 class GURL;
29 28
30 namespace chrome { 29 namespace chrome {
31 30
32 namespace android { 31 namespace android {
33 32
34 class ExternalDataUseObserverBridge;
35
36 // DataUseMatcher stores the matching URL patterns and package names along with 33 // DataUseMatcher stores the matching URL patterns and package names along with
37 // the labels. It also provides functionality to get the matching label for a 34 // the labels. It also provides functionality to get the matching label for a
38 // given URL or package. DataUseMatcher is not thread safe. 35 // given URL or package. DataUseMatcher is not thread safe. It is created on IO
36 // thread, but immediately moved to the UI thread, and afterwards accessible
37 // only on the UI thread.
39 class DataUseMatcher { 38 class DataUseMatcher {
40 public: 39 public:
40 // |on_tracking_label_removed_callback| is the callback to be run when a
41 // tracking label is removed from the list of matching rules.
42 // |on_matching_rules_fetched_callback| is the callback to be run after
43 // matching rules are fetched, indicating if at least one valid matching rule
44 // is available.
41 DataUseMatcher( 45 DataUseMatcher(
42 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, 46 const base::Callback<void(const std::string&)>&
43 const ExternalDataUseObserverBridge* external_data_use_observer_bridge, 47 on_tracking_label_removed_callback,
48 const base::Callback<void(bool)>& on_matching_rules_fetched_callback,
44 const base::TimeDelta& default_matching_rule_expiration_duration); 49 const base::TimeDelta& default_matching_rule_expiration_duration);
45 50
46 ~DataUseMatcher(); 51 ~DataUseMatcher();
47 52
48 // Called by FetchMatchingRulesDoneOnIOThread to register multiple 53 // Called by FetchMatchingRulesDoneOnIOThread to register multiple
49 // case-insensitive regular expressions. If the url of the data use request 54 // case-insensitive regular expressions. If the url of the data use request
50 // matches any of the regular expression, the observation is passed to the 55 // matches any of the regular expression, the observation is passed to the
51 // Java listener. 56 // Java listener.
52 void RegisterURLRegexes(const std::vector<std::string>& app_package_names, 57 void RegisterURLRegexes(const std::vector<std::string>& app_package_names,
53 const std::vector<std::string>& domain_path_regexes, 58 const std::vector<std::string>& domain_path_regexes,
54 const std::vector<std::string>& labels); 59 const std::vector<std::string>& labels);
55 60
56 // Returns true if the |url| matches the registered regular expressions. 61 // Returns true if the |url| matches the registered regular expressions.
57 // |label| must not be null. If a match is found, the |label| is set to the 62 // |label| must not be null. If a match is found, the |label| is set to the
58 // matching rule's label. 63 // matching rule's label.
59 bool MatchesURL(const GURL& url, std::string* label) const WARN_UNUSED_RESULT; 64 bool MatchesURL(const GURL& url, std::string* label) const WARN_UNUSED_RESULT;
60 65
61 // Returns true if the |app_package_name| matches the registered package 66 // Returns true if the |app_package_name| matches the registered package
62 // names. |label| must not be null. If a match is found, the |label| is set 67 // names. |label| must not be null. If a match is found, the |label| is set
63 // to the matching rule's label. 68 // to the matching rule's label.
64 bool MatchesAppPackageName(const std::string& app_package_name, 69 bool MatchesAppPackageName(const std::string& app_package_name,
65 std::string* label) const WARN_UNUSED_RESULT; 70 std::string* label) const WARN_UNUSED_RESULT;
66 71
67 // Fetches the matching rules asynchronously from
68 // |external_data_use_observer_bridge_|.
69 void FetchMatchingRules();
70
71 // Returns true if there is any matching rule. HasRules may return true even 72 // Returns true if there is any matching rule. HasRules may return true even
72 // if all rules are expired. 73 // if all rules are expired.
73 bool HasRules() const; 74 bool HasRules() const;
74 75
75 // Returns true if there is any valid matching rule with label |label|. 76 // Returns true if there is any valid matching rule with label |label|.
76 bool HasValidRuleWithLabel(const std::string& label) const; 77 bool HasValidRuleWithLabel(const std::string& label) const;
77 78
78 private: 79 private:
79 friend class DataUseMatcherTest; 80 friend class DataUseMatcherTest;
80 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest, 81 FRIEND_TEST_ALL_PREFIXES(DataUseMatcherTest,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // expected format, |expiration| will be set to default expiration duration 123 // expected format, |expiration| will be set to default expiration duration
123 // from now, and |new_app_package_name| will be set to the |app_package_name|. 124 // from now, and |new_app_package_name| will be set to the |app_package_name|.
124 void ParsePackageField(const std::string& app_package_name, 125 void ParsePackageField(const std::string& app_package_name,
125 std::string* new_app_package_name, 126 std::string* new_app_package_name,
126 base::TimeTicks* expiration) const; 127 base::TimeTicks* expiration) const;
127 128
128 base::ThreadChecker thread_checker_; 129 base::ThreadChecker thread_checker_;
129 130
130 std::vector<std::unique_ptr<MatchingRule>> matching_rules_; 131 std::vector<std::unique_ptr<MatchingRule>> matching_rules_;
131 132
132 // |data_use_tab_model_| is notified if a label is removed from the set of
133 // matching labels.
134 base::WeakPtr<DataUseTabModel> data_use_tab_model_;
135
136 // Default expiration duration of a matching rule, if expiration is not 133 // Default expiration duration of a matching rule, if expiration is not
137 // specified in the rule. 134 // specified in the rule.
138 const base::TimeDelta default_matching_rule_expiration_duration_; 135 const base::TimeDelta default_matching_rule_expiration_duration_;
139 136
140 // TickClock used for obtaining the current time. 137 // TickClock used for obtaining the current time.
141 std::unique_ptr<base::TickClock> tick_clock_; 138 std::unique_ptr<base::TickClock> tick_clock_;
142 139
143 // Pointer to the ExternalDataUseObserverBridge owned by 140 // Callback to be run when a label is removed from the set of matching labels.
144 // ExternalDataUseObserver. DataUseTabModel (owner of |this|) and 141 const base::Callback<void(const std::string&)>
145 // ExternalDataUseObserverBridge are owned by ExternalDataUseObserver, and are 142 on_tracking_label_removed_callback_;
146 // destroyed in that order. So |external_data_use_observer_bridge_| is 143
147 // guaranteed to be non-null. 144 // Callback to be run when matching rules are fetched.
148 const ExternalDataUseObserverBridge* external_data_use_observer_bridge_; 145 const base::Callback<void(bool)> on_matching_rules_fetched_callback_;
149 146
150 DISALLOW_COPY_AND_ASSIGN(DataUseMatcher); 147 DISALLOW_COPY_AND_ASSIGN(DataUseMatcher);
151 }; 148 };
152 149
153 } // namespace android 150 } // namespace android
154 151
155 } // namespace chrome 152 } // namespace chrome
156 153
157 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_ 154 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_MATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/data_usage/data_use_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698