| OLD | NEW |
| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
| 14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 23 class Time; | 23 class Time; |
| 24 class TimeTicks; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace chrome { | 27 namespace chrome { |
| 27 | 28 |
| 28 namespace android { | 29 namespace android { |
| 29 | 30 |
| 30 class DataUseTabModel; | 31 class DataUseTabModel; |
| 31 class ExternalDataUseObserver; | 32 class ExternalDataUseObserver; |
| 32 | 33 |
| 33 // ExternalDataUseObserverBridge creates and owns a Java listener object | 34 // ExternalDataUseObserverBridge creates and owns a Java listener object |
| 34 // 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 |
| 35 // receives regular expressions from the Java listener object. Objects of this | 36 // receives regular expressions from the Java listener object. Objects of this |
| 36 // 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 |
| 37 // 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. |
| 38 class ExternalDataUseObserverBridge { | 39 class ExternalDataUseObserverBridge { |
| 39 public: | 40 public: |
| 40 ExternalDataUseObserverBridge(); | 41 ExternalDataUseObserverBridge(); |
| 41 ~ExternalDataUseObserverBridge(); | 42 ~ExternalDataUseObserverBridge(); |
| 42 | 43 |
| 43 // Initializes |this| on UI thread by constructing the | 44 // Initializes |this| on UI thread by constructing the |
| 44 // |j_external_data_use_observer_|, and fetches matching rules from | 45 // |j_external_data_use_observer_|, and fetches matching rules from |
| 45 // |j_external_data_use_observer_|. | 46 // |j_external_data_use_observer_|. |
| 46 void Init(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 47 void Init(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 47 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer, | 48 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer, |
| 48 DataUseTabModel* data_use_tab_model); | 49 DataUseTabModel* data_use_tab_model); |
| 49 | 50 |
| 50 // Fetches matching rules from Java. Returns result asynchronously via | 51 // Fetches matching rules from Java. Returns result asynchronously via |
| 51 // FetchMatchingRulesDone. FetchMatchingRules should not be called if a | 52 // FetchMatchingRulesDone. FetchMatchingRules should not be called if a |
| 52 // fetch to matching rules is already in progress. | 53 // fetch to matching rules is already in progress. |
| 53 void FetchMatchingRules() const; | 54 void FetchMatchingRules(); |
| 54 | 55 |
| 55 // Called by Java when new matching rules have been fetched. | 56 // Called by Java when new matching rules have been fetched. |
| 56 // |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. |
| 57 // |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 |
| 58 // 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 |
| 59 // matching rule, and must uniquely identify the matching rule. Each element | 60 // matching rule, and must uniquely identify the matching rule. Each element |
| 60 // 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 |
| 61 // 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 |
| 62 // active. | 63 // active. |
| 63 void FetchMatchingRulesDone( | 64 void FetchMatchingRulesDone( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 // reports are submitted to |j_external_data_use_observer_|. | 95 // reports are submitted to |j_external_data_use_observer_|. |
| 95 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; | 96 base::android::ScopedJavaGlobalRef<jobject> j_external_data_use_observer_; |
| 96 | 97 |
| 97 // |external_data_use_observer_| owns |this|. |external_data_use_observer_| is | 98 // |external_data_use_observer_| owns |this|. |external_data_use_observer_| is |
| 98 // notified of results from Java code by |this|. | 99 // notified of results from Java code by |this|. |
| 99 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer_; | 100 base::WeakPtr<ExternalDataUseObserver> external_data_use_observer_; |
| 100 | 101 |
| 101 // |data_use_tab_model_| is notified of the matching rules on UI thread. | 102 // |data_use_tab_model_| is notified of the matching rules on UI thread. |
| 102 base::WeakPtr<DataUseTabModel> data_use_tab_model_; | 103 base::WeakPtr<DataUseTabModel> data_use_tab_model_; |
| 103 | 104 |
| 105 // The time of request when the matching rules are fetched for the first time. |
| 106 base::TimeTicks matching_rules_first_fetch_time_; |
| 107 |
| 104 // |io_task_runner_| accesses ExternalDataUseObserver members on IO thread. | 108 // |io_task_runner_| accesses ExternalDataUseObserver members on IO thread. |
| 105 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 106 | 110 |
| 107 base::ThreadChecker thread_checker_; | 111 base::ThreadChecker thread_checker_; |
| 108 | 112 |
| 109 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverBridge); | 113 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserverBridge); |
| 110 }; | 114 }; |
| 111 | 115 |
| 112 bool RegisterExternalDataUseObserver(JNIEnv* env); | 116 bool RegisterExternalDataUseObserver(JNIEnv* env); |
| 113 | 117 |
| 114 } // namespace android | 118 } // namespace android |
| 115 | 119 |
| 116 } // namespace chrome | 120 } // namespace chrome |
| 117 | 121 |
| 118 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H
_ | 122 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_BRIDGE_H
_ |
| OLD | NEW |