OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H_ | |
6 #define CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H_ | |
7 | |
8 #include <jni.h> | |
9 #include <vector> | |
10 | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/macros.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "components/data_usage/core/data_use.h" | |
16 #include "components/data_usage/core/data_use_aggregator.h" | |
17 | |
18 namespace chrome { | |
19 | |
20 namespace android { | |
21 | |
22 // This class defines a data use observer external to Chromium. It creates and | |
23 // owns a Java listener object that listens to data use observations. Native | |
24 // code receives regular expressions from the Java listener. This class also | |
25 // registers as a data use observer with DataUseAggregator, applies the regular | |
26 // expressions to the received observations, and reports the matching data use | |
27 // reports to the Java listener. | |
28 class ExternalDataUseObserverAndroid | |
29 : public data_usage::DataUseAggregator::Observer { | |
30 public: | |
31 explicit ExternalDataUseObserverAndroid( | |
32 data_usage::DataUseAggregator* data_use_aggregator); | |
33 ~ExternalDataUseObserverAndroid() override; | |
34 | |
35 private: | |
36 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, SingleRegex); | |
37 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, TwoRegex); | |
38 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, MultipleRegex); | |
39 | |
40 // data_usage::DataUseAggregator::Observer implementation: | |
41 void OnDataUse( | |
42 const std::vector<data_usage::DataUse>& data_use_sequence) override; | |
43 | |
44 // Called by Java to register multiple regular expressions. If the url of the | |
45 // data use request matches any of the regular expression, the observation is | |
46 // passed to the Java listener. | |
47 void RegisterURLRegexes(const std::vector<std::string>& url_regexes); | |
48 | |
49 // Returns true if the |gurl| matches the registered regular expressions. | |
50 bool Matches(const GURL& gurl) const; | |
51 | |
52 // Aggregator that sends data use observations. May be nullptr. | |
sclittle
2015/10/09 22:59:28
Why can this be nullptr?
tbansal1
2015/10/12 16:47:36
Removed.
| |
53 data_usage::DataUseAggregator* data_use_aggregator_; | |
54 | |
55 // Java listener. | |
56 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; | |
57 | |
58 // Registered regular expressions. | |
59 std::vector<std::string> url_regexes_; | |
sclittle
2015/10/09 22:59:28
Could you pre-compile the RE2 patterns?
tbansal1
2015/10/12 16:47:36
Done.
| |
60 | |
61 base::ThreadChecker thread_checker_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverAndroid); | |
64 }; | |
65 | |
66 bool RegisterExternalDataUseObserverAndroid(JNIEnv* env); | |
67 | |
68 } // namespace android | |
69 | |
70 } // namespace chrome | |
71 | |
72 #endif // CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H _ | |
OLD | NEW |