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

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_observer_bridge.h

Issue 1772273002: Remove one thread hop while fetching matching rules (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H_ 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H_
6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H_ 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 21 matching lines...) Expand all
32 class ExternalDataUseObserver; 32 class ExternalDataUseObserver;
33 33
34 // ExternalDataUseObserverBridge creates and owns a Java listener object 34 // ExternalDataUseObserverBridge creates and owns a Java listener object
35 // that is notified of the data usage observations of Chromium. This class 35 // that is notified of the data usage observations of Chromium. This class
36 // receives regular expressions from the Java listener object. Objects of this 36 // receives regular expressions from the Java listener object. Objects of this
37 // class may may be constructed on any thread safe but are immediately moved to 37 // class may may be constructed on any thread safe but are immediately moved to
38 // the UI thread, and afterwards are accessible only on the UI thread. 38 // the UI thread, and afterwards are accessible only on the UI thread.
39 class ExternalDataUseObserverBridge { 39 class ExternalDataUseObserverBridge {
40 public: 40 public:
41 ExternalDataUseObserverBridge(); 41 ExternalDataUseObserverBridge();
42 ~ExternalDataUseObserverBridge(); 42 virtual ~ExternalDataUseObserverBridge();
43 43
44 // Initializes |this| on UI thread by constructing the 44 // Initializes |this| on UI thread by constructing the
45 // |j_external_data_use_observer_|, and fetches matching rules from 45 // |j_external_data_use_observer_|, and fetches matching rules from
46 // |j_external_data_use_observer_|. 46 // |j_external_data_use_observer_|.
47 void Init(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 47 void Init(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
48 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer, 48 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer,
49 DataUseTabModel* data_use_tab_model); 49 DataUseTabModel* data_use_tab_model);
50 50
51 // Fetches matching rules from Java. Returns result asynchronously via 51 // Fetches matching rules from Java. Returns result asynchronously via
52 // FetchMatchingRulesDone. FetchMatchingRules should not be called if a 52 // FetchMatchingRulesDone. FetchMatchingRules should not be called if a
53 // fetch to matching rules is already in progress. 53 // fetch to matching rules is already in progress.
54 void FetchMatchingRules() const; 54 virtual void FetchMatchingRules() const;
55 55
56 // Called by Java when new matching rules have been fetched. 56 // Called by Java when new matching rules have been fetched.
57 // |app_package_name| is the package name of the app that should be matched. 57 // |app_package_name| is the package name of the app that should be matched.
58 // |domain_path_regex| is the regex to be used for matching URLs. |label| is 58 // |domain_path_regex| is the regex to be used for matching URLs. |label| is
59 // the label that must be applied to data reports corresponding to the 59 // the label that must be applied to data reports corresponding to the
60 // matching rule, and must uniquely identify the matching rule. Each element 60 // matching rule, and must uniquely identify the matching rule. Each element
61 // in |label| must have non-zero length. The three vectors should have equal 61 // in |label| must have non-zero length. The three vectors should have equal
62 // length. The vectors may be empty which implies that no matching rules are 62 // length. The vectors may be empty which implies that no matching rules are
63 // active. 63 // active.
64 void FetchMatchingRulesDone( 64 void FetchMatchingRulesDone(
(...skipping 21 matching lines...) Expand all
86 const base::android::JavaParamRef<jobject>& obj, 86 const base::android::JavaParamRef<jobject>& obj,
87 bool success); 87 bool success);
88 88
89 // Notifies the ExternalDataUseObserverBridge that the external control app is 89 // Notifies the ExternalDataUseObserverBridge that the external control app is
90 // installed or uninstalled. |is_control_app_installed| is true if app is 90 // installed or uninstalled. |is_control_app_installed| is true if app is
91 // installed. 91 // installed.
92 void OnControlAppInstallStateChange(JNIEnv* env, 92 void OnControlAppInstallStateChange(JNIEnv* env,
93 jobject obj, 93 jobject obj,
94 bool is_control_app_installed) const; 94 bool is_control_app_installed) const;
95 95
96 // Called by DataUseMatcher to notify |external_data_use_observer_| if it
97 // should register as a data use observer.
98 virtual void ShouldRegisterAsDataUseObserver(bool should_register) const;
99
96 private: 100 private:
97 // Java listener that provides regular expressions to |this|. Data use 101 // Java listener that provides regular expressions to |this|. Data use
98 // reports are submitted to |j_external_data_use_observer_|. 102 // reports are submitted to |j_external_data_use_observer_|.
99 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; 103 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_;
100 104
101 // |external_data_use_observer_| owns |this|. |external_data_use_observer_| is 105 // |external_data_use_observer_| owns |this|. |external_data_use_observer_| is
102 // notified of results from Java code by |this|. 106 // notified of results from Java code by |this|.
103 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer_; 107 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer_;
104 108
105 // |data_use_tab_model_| is notified of the matching rules on UI thread. 109 // |data_use_tab_model_| is notified of the matching rules on UI thread.
110 // |data_use_tab_model_| may be null if Init has not been called yet.
tbansal1 2016/03/10 19:37:58 |data_use_tab_model_| could also be null because i
106 base::WeakPtr<DataUseTabModel> data_use_tab_model_; 111 base::WeakPtr<DataUseTabModel> data_use_tab_model_;
107 112
108 // The construction time of |this|. 113 // The construction time of |this|.
109 const base::TimeTicks construct_time_; 114 const base::TimeTicks construct_time_;
110 115
111 // True if matching rules are fetched for the first time. 116 // True if matching rules are fetched for the first time.
112 bool is_first_matching_rule_fetch_; 117 bool is_first_matching_rule_fetch_;
113 118
114 // |io_task_runner_| accesses ExternalDataUseObserver members on IO thread. 119 // |io_task_runner_| accesses ExternalDataUseObserver members on IO thread.
115 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 120 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
116 121
117 base::ThreadChecker thread_checker_; 122 base::ThreadChecker thread_checker_;
118 123
119 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverBridge); 124 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverBridge);
120 }; 125 };
121 126
122 bool RegisterExternalDataUseObserver(JNIEnv* env); 127 bool RegisterExternalDataUseObserver(JNIEnv* env);
123 128
124 } // namespace android 129 } // namespace android
125 130
126 } // namespace chrome 131 } // namespace chrome
127 132
128 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H _ 133 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698