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

Unified Diff: chrome/browser/android/datausage/external_data_use_observer.h

Issue 1393073002: Add external data use observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@datause_accounting_scliitle_cl_do_not_edit_2
Patch Set: Addressed comments, removed android suffix Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/datausage/external_data_use_observer.h
diff --git a/chrome/browser/android/datausage/external_data_use_observer.h b/chrome/browser/android/datausage/external_data_use_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..1199ec868850b5970a36844bbf8e43003fc3960c
--- /dev/null
+++ b/chrome/browser/android/datausage/external_data_use_observer.h
@@ -0,0 +1,84 @@
+// 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_H_
+#define CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_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/memory/scoped_vector.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 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 ExternalDataUseObserver : public data_usage::DataUseAggregator::Observer {
+ public:
+ explicit ExternalDataUseObserver(
+ data_usage::DataUseAggregator* data_use_aggregator);
+ ~ExternalDataUseObserver() override;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, SingleRegex);
+ FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, TwoRegex);
+ FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, MultipleRegex);
+ FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, ChangeRegex);
+
+ // data_usage::DataUseAggregator::Observer implementation:
+ void OnDataUse(
+ const std::vector<data_usage::DataUse>& data_use_sequence) override;
+
+ // Called by |j_external_data_use_observer_| 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 that provides regular expressions to this class. The
+ // regular expressions are applied to the request URLs, and filtered
+ // data use is notified to |j_external_data_use_observer_|.
+ base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_;
+
+ // Registered RE2 patterns that are matched against the URLs.
+ ScopedVector<re2::RE2> url_patterns_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver);
+};
+
+bool RegisterExternalDataUseObserver(JNIEnv* env);
+
+} // namespace android
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698