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

Side by Side Diff: chrome/browser/android/datausage/external_data_use_observer_android.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 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 unified diff | Download patch
OLDNEW
(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 <string>
10 #include <vector>
11
12 #include "base/android/scoped_java_ref.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h"
15 #include "base/threading/thread_checker.h"
16 #include "cc/base/scoped_ptr_vector.h"
17 #include "components/data_usage/core/data_use.h"
18 #include "components/data_usage/core/data_use_aggregator.h"
19
20 namespace re2 {
21 class RE2;
22 }
23
24 namespace chrome {
25
26 namespace android {
27
28 // This class allows platform APIs that are external to Chromium to observe how
29 // much data is used by Chromium on the current Android device. It creates and
30 // owns a Java listener object that is notified of the data usage observations
31 // of Chromium. This class receives regular expressions from the Java listener
32 // object. It also registers as a data use observer with DataUseAggregator,
33 // filters the received observations by applying the regex matching to the URLs
34 // of the requests, and notifies the filtered data use to the Java listener. The
35 // Java object in turn may notify the platform APIs of the data usage
36 // observations.
37 class ExternalDataUseObserverAndroid
38 : public data_usage::DataUseAggregator::Observer {
39 public:
40 explicit ExternalDataUseObserverAndroid(
41 data_usage::DataUseAggregator* data_use_aggregator);
42 ~ExternalDataUseObserverAndroid() override;
43
44 private:
45 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, SingleRegex);
46 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, TwoRegex);
47 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, MultipleRegex);
48 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, ChangeRegex);
49
50 // data_usage::DataUseAggregator::Observer implementation:
51 void OnDataUse(
52 const std::vector<data_usage::DataUse>& data_use_sequence) override;
53
54 // Called by Java to register multiple case-insensitive regular expressions.
55 // If the url of the data use request matches any of the regular expression,
56 // the observation is passed to the Java listener.
57 void RegisterURLRegexes(const std::vector<std::string>& url_regexes);
58
59 // Returns true if the |gurl| matches the registered regular expressions.
60 bool Matches(const GURL& gurl) const;
61
62 // Aggregator that sends data use observations.
63 data_usage::DataUseAggregator* data_use_aggregator_;
64
65 // Java listener.
66 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_;
67
68 // Registered RE2 patterns that are matched against the URLs.
69 cc::ScopedPtrVector<re2::RE2> url_patterns_;
70
71 base::ThreadChecker thread_checker_;
72
73 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverAndroid);
74 };
75
76 bool RegisterExternalDataUseObserverAndroid(JNIEnv* env);
77
78 } // namespace android
79
80 } // namespace chrome
81
82 #endif // CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698