Chromium Code Reviews| Index: chrome/browser/android/datausage/external_data_use_observer_android.h |
| diff --git a/chrome/browser/android/datausage/external_data_use_observer_android.h b/chrome/browser/android/datausage/external_data_use_observer_android.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9c2a6cf62b9e2928c458f3f3e5eb9a9ad8d1c01e |
| --- /dev/null |
| +++ b/chrome/browser/android/datausage/external_data_use_observer_android.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H_ |
| +#define CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H_ |
| + |
| +#include <jni.h> |
| +#include <vector> |
| + |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/macros.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "components/data_usage/core/data_use.h" |
| +#include "components/data_usage/core/data_use_aggregator.h" |
| + |
| +namespace chrome { |
| + |
| +namespace android { |
| + |
| +// This class defines a data use observer external to Chromium. It creates and |
| +// owns a Java listener object that listens to data use observations. Native |
| +// code receives regular expressions from the Java listener. This class also |
| +// registers as a data use observer with DataUseAggregator, applies the regular |
| +// expressions to the received observations, and reports the matching data use |
| +// reports to the Java listener. |
| +class ExternalDataUseObserverAndroid |
| + : public data_usage::DataUseAggregator::Observer { |
| + public: |
| + explicit ExternalDataUseObserverAndroid( |
| + data_usage::DataUseAggregator* data_use_aggregator); |
| + ~ExternalDataUseObserverAndroid() override; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, SingleRegex); |
| + FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, TwoRegex); |
| + FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, MultipleRegex); |
| + |
| + // data_usage::DataUseAggregator::Observer implementation: |
| + void OnDataUse( |
| + const std::vector<data_usage::DataUse>& data_use_sequence) override; |
| + |
| + // Called by Java to register multiple regular expressions. If the url of the |
| + // data use request matches any of the regular expression, the observation is |
| + // passed to the Java listener. |
| + void RegisterURLRegexes(const std::vector<std::string>& url_regexes); |
| + |
| + // Returns true if the |gurl| matches the registered regular expressions. |
| + bool Matches(const GURL& gurl) const; |
| + |
| + // 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.
|
| + data_usage::DataUseAggregator* data_use_aggregator_; |
| + |
| + // Java listener. |
| + base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; |
| + |
| + // Registered regular expressions. |
| + 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.
|
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverAndroid); |
| +}; |
| + |
| +bool RegisterExternalDataUseObserverAndroid(JNIEnv* env); |
| + |
| +} // namespace android |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H_ |