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..27b90a268adfbe9deb9f48b8330768a2c4851f88 |
--- /dev/null |
+++ b/chrome/browser/android/datausage/external_data_use_observer_android.h |
@@ -0,0 +1,82 @@ |
+// 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 <string> |
+#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 "cc/base/scoped_ptr_vector.h" |
+#include "components/data_usage/core/data_use.h" |
+#include "components/data_usage/core/data_use_aggregator.h" |
+ |
+namespace re2 { |
+class RE2; |
+} |
+ |
+namespace chrome { |
+ |
+namespace android { |
+ |
+// This class allows platform APIs that are external to Chromium to observe how |
+// much data is used by Chromium on the current Android device. It creates and |
+// owns a Java listener object that is notified of the data usage observations |
+// of Chromium. This class receives regular expressions from the Java listener |
+// object. It also registers as a data use observer with DataUseAggregator, |
+// filters the received observations by applying the regex matching to the URLs |
+// of the requests, and notifies the filtered data use to the Java listener. The |
+// Java object in turn may notify the platform APIs of the data usage |
+// observations. |
+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); |
+ FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, ChangeRegex); |
+ |
+ // data_usage::DataUseAggregator::Observer implementation: |
+ void OnDataUse( |
+ const std::vector<data_usage::DataUse>& data_use_sequence) override; |
+ |
+ // Called by Java to register multiple case-insensitive 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. |
+ data_usage::DataUseAggregator* data_use_aggregator_; |
+ |
+ // Java listener. |
+ base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; |
+ |
+ // Registered RE2 patterns that are matched against the URLs. |
+ cc::ScopedPtrVector<re2::RE2> url_patterns_; |
+ |
+ 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_ |