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_DATA_USE_TAB_MODEL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 friend class TestDataUseTabModel; | 180 friend class TestDataUseTabModel; |
181 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 181 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
182 CompactTabEntriesWithinMaxLimit); | 182 CompactTabEntriesWithinMaxLimit); |
183 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 183 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
184 ExpiredInactiveTabEntryRemovaltimeHistogram); | 184 ExpiredInactiveTabEntryRemovaltimeHistogram); |
185 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 185 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
186 MatchingRuleClearedOnControlAppUninstall); | 186 MatchingRuleClearedOnControlAppUninstall); |
187 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 187 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
188 MultipleObserverMultipleStartEndEvents); | 188 MultipleObserverMultipleStartEndEvents); |
189 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverStartEndEvents); | 189 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverStartEndEvents); |
190 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | |
191 ProcessBufferedNavigationEventsAfterRuleFetch); | |
190 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent); | 192 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent); |
191 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); | 193 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); |
192 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 194 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
193 UnexpiredTabEntryRemovaltimeHistogram); | 195 UnexpiredTabEntryRemovaltimeHistogram); |
194 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 196 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
195 MatchingRuleFetchOnControlAppInstall); | 197 MatchingRuleFetchOnControlAppInstall); |
198 FRIEND_TEST_ALL_PREFIXES( | |
199 ExternalDataUseObserverTest, | |
200 ProcessBufferedNavigationEventsAfterControlAppNotInstalled); | |
201 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | |
202 ProcessBufferedNavigationEventsAfterRuleFetch); | |
203 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | |
204 ProcessBufferedNavigationEventsAfterMaxLimit); | |
196 | 205 |
197 typedef base::hash_map<SessionID::id_type, TabDataUseEntry> TabEntryMap; | 206 typedef base::hash_map<SessionID::id_type, TabDataUseEntry> TabEntryMap; |
198 | 207 |
208 // Contains the details of a single UI navigation event. | |
209 struct DataUseUINavigationEvent { | |
210 DataUseUINavigationEvent(SessionID::id_type tab_id, | |
211 TransitionType transition_type, | |
212 GURL url, | |
213 std::string package) | |
214 : tab_id(tab_id), | |
215 transition_type(transition_type), | |
216 url(url), | |
217 package(package) {} | |
218 | |
219 const SessionID::id_type tab_id; | |
220 const TransitionType transition_type; | |
221 const GURL url; | |
222 const std::string package; | |
223 }; | |
224 | |
199 // Gets the current label of a tab, and the new label if a navigation event | 225 // Gets the current label of a tab, and the new label if a navigation event |
200 // occurs in the tab. |tab_id| is the source tab of the generated event, | 226 // occurs in the tab. |tab_id| is the source tab of the generated event, |
201 // |transition| indicates the type of the UI event/transition, |url| is the | 227 // |transition| indicates the type of the UI event/transition, |url| is the |
202 // URL in the source tab, |package| indicates the android package name of | 228 // URL in the source tab, |package| indicates the android package name of |
203 // external application that initiated the event. |current_label|, |new_label| | 229 // external application that initiated the event. |current_label|, |new_label| |
204 // and |is_package_match| should not be null, and are set with current and new | 230 // and |is_package_match| should not be null, and are set with current and new |
205 // labels respectively. |current_label| will be set to empty string, if there | 231 // labels respectively. |current_label| will be set to empty string, if there |
206 // is no active tracking session. |new_label| will be set to empty string if | 232 // is no active tracking session. |new_label| will be set to empty string if |
207 // there would be no active tracking session if the navigation happens. | 233 // there would be no active tracking session if the navigation happens. |
208 // |is_package_match| will be set to true if a tracking session will start due | 234 // |is_package_match| will be set to true if a tracking session will start due |
(...skipping 15 matching lines...) Expand all Loading... | |
224 | 250 |
225 // Ends the current tracking session for tab with id |tab_id|. | 251 // Ends the current tracking session for tab with id |tab_id|. |
226 void EndTrackingDataUse(SessionID::id_type tab_id); | 252 void EndTrackingDataUse(SessionID::id_type tab_id); |
227 | 253 |
228 // Compacts the tab entry map |active_tabs_| by removing expired tab entries. | 254 // Compacts the tab entry map |active_tabs_| by removing expired tab entries. |
229 // After removing expired tab entries, if the size of |active_tabs_| exceeds | 255 // After removing expired tab entries, if the size of |active_tabs_| exceeds |
230 // |kMaxTabEntries|, oldest unexpired tab entries will be removed until its | 256 // |kMaxTabEntries|, oldest unexpired tab entries will be removed until its |
231 // size is |kMaxTabEntries|. | 257 // size is |kMaxTabEntries|. |
232 void CompactTabEntries(); | 258 void CompactTabEntries(); |
233 | 259 |
260 // Processes the UI navigation events buffered in |data_use_ui_navigations_| | |
261 // and releases the vector in |data_use_ui_navigations_| so that navigation | |
tbansal1
2016/03/29 18:19:04
s/releases/deletes/
Raj
2016/03/29 19:45:54
Done.
| |
262 // events will not be buffered any more. | |
263 void ProcessBufferedNavigationEvents(); | |
264 | |
234 // Collection of observers that receive tracking session start and end | 265 // Collection of observers that receive tracking session start and end |
235 // notifications. Notifications are posted on UI thread. | 266 // notifications. Notifications are posted on UI thread. |
236 base::ObserverList<TabDataUseObserver> observers_; | 267 base::ObserverList<TabDataUseObserver> observers_; |
237 | 268 |
238 // Maintains the tracking sessions of multiple tabs. | 269 // Maintains the tracking sessions of multiple tabs. |
239 TabEntryMap active_tabs_; | 270 TabEntryMap active_tabs_; |
240 | 271 |
241 // Maximum number of tab entries to maintain session information about. | 272 // Maximum number of tab entries to maintain session information about. |
242 const size_t max_tab_entries_; | 273 const size_t max_tab_entries_; |
243 | 274 |
244 // Maximum number of tracking sessions to maintain per tab. | 275 // Maximum number of tracking sessions to maintain per tab. |
245 const size_t max_sessions_per_tab_; | 276 const size_t max_sessions_per_tab_; |
246 | 277 |
247 // Expiration duration for a closed tab entry and an open tab entry | 278 // Expiration duration for a closed tab entry and an open tab entry |
248 // respectively. | 279 // respectively. |
249 const base::TimeDelta closed_tab_expiration_duration_; | 280 const base::TimeDelta closed_tab_expiration_duration_; |
250 const base::TimeDelta open_tab_expiration_duration_; | 281 const base::TimeDelta open_tab_expiration_duration_; |
251 | 282 |
252 // TickClock used for obtaining the current time. | 283 // TickClock used for obtaining the current time. |
253 scoped_ptr<base::TickClock> tick_clock_; | 284 scoped_ptr<base::TickClock> tick_clock_; |
254 | 285 |
255 // Stores the matching patterns. | 286 // Stores the matching patterns. |
256 scoped_ptr<DataUseMatcher> data_use_matcher_; | 287 scoped_ptr<DataUseMatcher> data_use_matcher_; |
257 | 288 |
258 // True if the external control app is installed. | 289 // True if the external control app is installed. |
259 bool is_control_app_installed_; | 290 bool is_control_app_installed_; |
260 | 291 |
292 // Buffers of UI navigation events that occurred until the first rule fetch is | |
tbansal1
2016/03/29 18:19:03
s/Buffers/Buffer/
IIUC, this is a single buffer th
Raj
2016/03/29 19:45:54
Done.
| |
293 // complete or the control app not installed callback was received or until | |
294 // |kDefaultMaxNavigationEventsBuffered| navigation events were buffered, | |
295 // whichever occurs first. Existence of the vector in scoped_ptr indicates if | |
296 // the UI navigation events need to be buffered. If the scoped_ptr contains a | |
297 // vector all navigation events will be added to it. Otherwise all navigation | |
298 // events will be processed immediately. | |
299 scoped_ptr<std::vector<DataUseUINavigationEvent>> data_use_ui_navigations_; | |
300 | |
261 base::ThreadChecker thread_checker_; | 301 base::ThreadChecker thread_checker_; |
262 | 302 |
263 base::WeakPtrFactory<DataUseTabModel> weak_factory_; | 303 base::WeakPtrFactory<DataUseTabModel> weak_factory_; |
264 | 304 |
265 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); | 305 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); |
266 }; | 306 }; |
267 | 307 |
268 } // namespace android | 308 } // namespace android |
269 | 309 |
270 } // namespace chrome | 310 } // namespace chrome |
271 | 311 |
272 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ | 312 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
OLD | NEW |