Chromium Code Reviews| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, TabCloseEvent); | 190 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent); |
| 191 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); | 191 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); |
| 192 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 192 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
| 193 UnexpiredTabEntryRemovaltimeHistogram); | 193 UnexpiredTabEntryRemovaltimeHistogram); |
| 194 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | 194 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, |
| 195 MatchingRuleFetchOnControlAppInstall); | 195 MatchingRuleFetchOnControlAppInstall); |
| 196 FRIEND_TEST_ALL_PREFIXES(ExternalDataUseObserverTest, | |
| 197 ProcessBufferedNavigationEvents); | |
| 196 | 198 |
| 197 typedef base::hash_map<SessionID::id_type, TabDataUseEntry> TabEntryMap; | 199 typedef base::hash_map<SessionID::id_type, TabDataUseEntry> TabEntryMap; |
| 198 | 200 |
| 201 // Contains the details of a single UI navigation event. | |
| 202 struct DataUseUINavigationEvent { | |
|
tbansal1
2016/03/29 16:20:41
Methods should come before fields.
Raj
2016/03/29 18:03:21
Done.
| |
| 203 SessionID::id_type tab_id; | |
|
tbansal1
2016/03/29 16:20:41
can these fields be all const?
Raj
2016/03/29 18:03:20
Done.
| |
| 204 TransitionType transition_type; | |
| 205 GURL url; | |
| 206 std::string package; | |
| 207 DataUseUINavigationEvent(SessionID::id_type tab_id, | |
| 208 TransitionType transition_type, | |
| 209 GURL url, | |
| 210 std::string package) | |
| 211 : tab_id(tab_id), | |
| 212 transition_type(transition_type), | |
| 213 url(url), | |
| 214 package(package) {} | |
| 215 }; | |
| 216 | |
| 199 // Gets the current label of a tab, and the new label if a navigation event | 217 // 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, | 218 // 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 | 219 // |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 | 220 // URL in the source tab, |package| indicates the android package name of |
| 203 // external application that initiated the event. |current_label|, |new_label| | 221 // 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 | 222 // 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 | 223 // 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 | 224 // 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. | 225 // 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 | 226 // |is_package_match| will be set to true if a tracking session will start due |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 224 | 242 |
| 225 // Ends the current tracking session for tab with id |tab_id|. | 243 // Ends the current tracking session for tab with id |tab_id|. |
| 226 void EndTrackingDataUse(SessionID::id_type tab_id); | 244 void EndTrackingDataUse(SessionID::id_type tab_id); |
| 227 | 245 |
| 228 // Compacts the tab entry map |active_tabs_| by removing expired tab entries. | 246 // 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 | 247 // After removing expired tab entries, if the size of |active_tabs_| exceeds |
| 230 // |kMaxTabEntries|, oldest unexpired tab entries will be removed until its | 248 // |kMaxTabEntries|, oldest unexpired tab entries will be removed until its |
| 231 // size is |kMaxTabEntries|. | 249 // size is |kMaxTabEntries|. |
| 232 void CompactTabEntries(); | 250 void CompactTabEntries(); |
| 233 | 251 |
| 252 void ProcessBufferedNavigationEvents(); | |
|
tbansal1
2016/03/29 16:20:41
function comments please.
Raj
2016/03/29 18:03:21
Done.
| |
| 253 | |
| 234 // Collection of observers that receive tracking session start and end | 254 // Collection of observers that receive tracking session start and end |
| 235 // notifications. Notifications are posted on UI thread. | 255 // notifications. Notifications are posted on UI thread. |
| 236 base::ObserverList<TabDataUseObserver> observers_; | 256 base::ObserverList<TabDataUseObserver> observers_; |
| 237 | 257 |
| 238 // Maintains the tracking sessions of multiple tabs. | 258 // Maintains the tracking sessions of multiple tabs. |
| 239 TabEntryMap active_tabs_; | 259 TabEntryMap active_tabs_; |
| 240 | 260 |
| 241 // Maximum number of tab entries to maintain session information about. | 261 // Maximum number of tab entries to maintain session information about. |
| 242 const size_t max_tab_entries_; | 262 const size_t max_tab_entries_; |
| 243 | 263 |
| 244 // Maximum number of tracking sessions to maintain per tab. | 264 // Maximum number of tracking sessions to maintain per tab. |
| 245 const size_t max_sessions_per_tab_; | 265 const size_t max_sessions_per_tab_; |
| 246 | 266 |
| 247 // Expiration duration for a closed tab entry and an open tab entry | 267 // Expiration duration for a closed tab entry and an open tab entry |
| 248 // respectively. | 268 // respectively. |
| 249 const base::TimeDelta closed_tab_expiration_duration_; | 269 const base::TimeDelta closed_tab_expiration_duration_; |
| 250 const base::TimeDelta open_tab_expiration_duration_; | 270 const base::TimeDelta open_tab_expiration_duration_; |
| 251 | 271 |
| 252 // TickClock used for obtaining the current time. | 272 // TickClock used for obtaining the current time. |
| 253 scoped_ptr<base::TickClock> tick_clock_; | 273 scoped_ptr<base::TickClock> tick_clock_; |
| 254 | 274 |
| 255 // Stores the matching patterns. | 275 // Stores the matching patterns. |
| 256 scoped_ptr<DataUseMatcher> data_use_matcher_; | 276 scoped_ptr<DataUseMatcher> data_use_matcher_; |
| 257 | 277 |
| 258 // True if the external control app is installed. | 278 // True if the external control app is installed. |
| 259 bool is_control_app_installed_; | 279 bool is_control_app_installed_; |
| 260 | 280 |
| 281 // Buffers the list of UI navigation events that occurred until the first rule | |
|
tbansal1
2016/03/29 16:20:41
s/Buffers the list of/Buffer of/?
Raj
2016/03/29 18:03:21
Done.
| |
| 282 // fetch is complete or the control app not installed callback was received or | |
| 283 // until |kDefaultMaxNavigationEventsBuffered| navigation events were | |
| 284 // buffered, whichever occurs first. Existence of the vector in scoped_ptr | |
| 285 // indicates if the UI navigation events need to be buffered. If the | |
| 286 // scoped_ptr contains a vector all navigation events will be added to it. | |
| 287 // Otherwise all navigation events will be processed immediately. | |
| 288 scoped_ptr<std::vector<DataUseUINavigationEvent>> data_use_ui_navigations_; | |
| 289 | |
| 261 base::ThreadChecker thread_checker_; | 290 base::ThreadChecker thread_checker_; |
| 262 | 291 |
| 263 base::WeakPtrFactory<DataUseTabModel> weak_factory_; | 292 base::WeakPtrFactory<DataUseTabModel> weak_factory_; |
| 264 | 293 |
| 265 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); | 294 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); |
| 266 }; | 295 }; |
| 267 | 296 |
| 268 } // namespace android | 297 } // namespace android |
| 269 | 298 |
| 270 } // namespace chrome | 299 } // namespace chrome |
| 271 | 300 |
| 272 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ | 301 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
| OLD | NEW |