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

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: More tests 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.
newt (away) 2015/10/12 18:01:18 Since this class is already inside an "android" fo
tbansal1 2015/10/12 22:39:14 In the past, I did this and later had to add a bas
newt (away) 2015/10/13 19:05:20 If it seems likely that you'll need to add a base
tbansal1 2015/10/13 21:30:20 OK, for now I don't forecast any platform independ
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"
sclittle 2015/10/12 20:10:15 Why "cc/base/scoped_ptr_vector.h" instead of "base
tbansal1 2015/10/12 22:39:14 scoped_vector requires creating raw pointers and t
sclittle 2015/10/13 19:46:56 ScopedVectors can also take scoped_ptrs: https://c
tbansal1 2015/10/13 21:30:20 Done.
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 defines a data use observer external to Chromium. It creates and
newt (away) 2015/10/12 18:01:18 This comment should be much clearer. Imagine that
tbansal1 2015/10/12 22:39:14 Added more documentation.
29 // owns a Java listener object that listens to data use observations. Native
30 // code receives regular expressions from the Java listener. This class also
31 // registers as a data use observer with DataUseAggregator, applies the regular
32 // expressions to the received observations, and reports the matching data use
33 // reports to the Java listener.
34 class ExternalDataUseObserverAndroid
35 : public data_usage::DataUseAggregator::Observer {
36 public:
37 explicit ExternalDataUseObserverAndroid(
38 data_usage::DataUseAggregator* data_use_aggregator);
39 ~ExternalDataUseObserverAndroid() override;
40
41 private:
42 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, SingleRegex);
43 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, TwoRegex);
44 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, MultipleRegex);
45 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverAndroidTest, ChangeRegex);
46
47 // data_usage::DataUseAggregator::Observer implementation:
48 void OnDataUse(
49 const std::vector<data_usage::DataUse>& data_use_sequence) override;
50
51 // Called by Java to register multiple regular expressions. If the url of the
52 // data use request matches any of the regular expression, the observation is
53 // passed to the Java listener.
54 void RegisterURLRegexes(const std::vector<std::string>& url_regexes);
55
56 // Returns true if the |gurl| matches the registered regular expressions.
57 bool Matches(const GURL& gurl) const;
58
59 // Aggregator that sends data use observations.
60 data_usage::DataUseAggregator* data_use_aggregator_;
61
62 // Java listener.
63 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_;
64
65 // Registered RE2 patterns that are matched against the URLs.
66 cc::ScopedPtrVector<re2::RE2> url_patterns_;
67
68 base::ThreadChecker thread_checker_;
69
70 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverAndroid);
71 };
72
73 bool RegisterExternalDataUseObserverAndroid(JNIEnv* env);
74
75 } // namespace android
76
77 } // namespace chrome
78
79 #endif // CHROME_BROWSER_ANDROID_DATAUSAGE_EXTERNAL_DATA_USE_OBSERVER_ANDROID_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698