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_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
7 | 7 |
| 8 #include <deque> |
| 9 #include <memory> |
| 10 |
8 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
9 #include "base/macros.h" | 12 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
13 #include "base/time/time.h" | 16 #include "base/time/time.h" |
14 #include "components/data_usage/core/data_use_aggregator.h" | 17 #include "components/data_usage/core/data_use_aggregator.h" |
15 | 18 |
16 namespace base { | 19 namespace base { |
17 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 87 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
85 PeriodicFetchMatchingRules); | 88 PeriodicFetchMatchingRules); |
86 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 89 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
87 RegisteredAsDataUseObserver); | 90 RegisteredAsDataUseObserver); |
88 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations); | 91 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, Variations); |
89 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); | 92 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); |
90 | 93 |
91 // data_usage::DataUseAggregator::Observer implementation: | 94 // data_usage::DataUseAggregator::Observer implementation: |
92 void OnDataUse(const data_usage::DataUse& data_use) override; | 95 void OnDataUse(const data_usage::DataUse& data_use) override; |
93 | 96 |
| 97 // Called when a batch of data use objects are added to |data_use_list_|. |
| 98 void OnDataUseBatchComplete(); |
| 99 |
94 // Aggregator that sends data use observations to |this|. | 100 // Aggregator that sends data use observations to |this|. |
95 data_usage::DataUseAggregator* data_use_aggregator_; | 101 data_usage::DataUseAggregator* data_use_aggregator_; |
96 | 102 |
97 // |external_data_use_observer_bridge_| is owned by |this|, and interacts with | 103 // |external_data_use_observer_bridge_| is owned by |this|, and interacts with |
98 // the Java code. It is created on IO thread but afterwards, should only be | 104 // the Java code. It is created on IO thread but afterwards, should only be |
99 // accessed on UI thread. | 105 // accessed on UI thread. |
100 ExternalDataUseObserverBridge* external_data_use_observer_bridge_; | 106 ExternalDataUseObserverBridge* external_data_use_observer_bridge_; |
101 | 107 |
102 // Maintains tab sessions and is owned by |this|. It is created on IO thread | 108 // Maintains tab sessions and is owned by |this|. It is created on IO thread |
103 // but afterwards, should only be accessed on UI thread. | 109 // but afterwards, should only be accessed on UI thread. |
104 DataUseTabModel* data_use_tab_model_; | 110 DataUseTabModel* data_use_tab_model_; |
105 | 111 |
106 // Labels, buffers and reports the data usage. It is owned by |this|. It is | 112 // Labels, buffers and reports the data usage. It is owned by |this|. It is |
107 // created on IO thread but afterwards, should only be accessed on UI thread. | 113 // created on IO thread but afterwards, should only be accessed on UI thread. |
108 ExternalDataUseReporter* external_data_use_reporter_; | 114 ExternalDataUseReporter* external_data_use_reporter_; |
109 | 115 |
| 116 // Batches the data use objects reported by DataUseAggregator. This will be |
| 117 // created when data use batching starts and released when the batching ends. |
| 118 // This will be null if there is no ongoing batching of data use objects. |
| 119 std::unique_ptr<std::deque<const data_usage::DataUse>> data_use_list_; |
| 120 |
| 121 // |io_task_runner_| is used to call methods on IO thread. |
| 122 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 123 |
110 // |ui_task_runner_| is used to call methods on UI thread. | 124 // |ui_task_runner_| is used to call methods on UI thread. |
111 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 125 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
112 | 126 |
113 // Time when the matching rules were last fetched. | 127 // Time when the matching rules were last fetched. |
114 base::TimeTicks last_matching_rules_fetch_time_; | 128 base::TimeTicks last_matching_rules_fetch_time_; |
115 | 129 |
116 // Duration after which matching rules are periodically fetched. | 130 // Duration after which matching rules are periodically fetched. |
117 const base::TimeDelta fetch_matching_rules_duration_; | 131 const base::TimeDelta fetch_matching_rules_duration_; |
118 | 132 |
119 // True if |this| is currently registered as a data use observer. | 133 // True if |this| is currently registered as a data use observer. |
120 bool registered_as_data_use_observer_; | 134 bool registered_as_data_use_observer_; |
121 | 135 |
122 base::ThreadChecker thread_checker_; | 136 base::ThreadChecker thread_checker_; |
123 | 137 |
124 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; | 138 base::WeakPtrFactory<ExternalDataUseObserver> weak_factory_; |
125 | 139 |
126 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); | 140 DISALLOW_COPY_AND_ASSIGN(ExternalDataUseObserver); |
127 }; | 141 }; |
128 | 142 |
129 } // namespace android | 143 } // namespace android |
130 | 144 |
131 } // namespace chrome | 145 } // namespace chrome |
132 | 146 |
133 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ | 147 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_EXTERNAL_DATA_USE_OBSERVER_H_ |
OLD | NEW |