| 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 <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" |
| 15 #include "base/callback_forward.h" |
| 14 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 15 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 18 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 18 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 19 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 20 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 21 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" | 23 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" |
| 22 #include "components/sessions/core/session_id.h" | 24 #include "components/sessions/core/session_id.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Notification callback that DataUseTabModel is ready to process the UI | 100 // Notification callback that DataUseTabModel is ready to process the UI |
| 99 // navigation events. | 101 // navigation events. |
| 100 virtual void OnDataUseTabModelReady() = 0; | 102 virtual void OnDataUseTabModelReady() = 0; |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 // The tags to report for data usage from a default chrome tab, and a chrome | 105 // The tags to report for data usage from a default chrome tab, and a chrome |
| 104 // custom tab. | 106 // custom tab. |
| 105 static const char kDefaultTag[]; | 107 static const char kDefaultTag[]; |
| 106 static const char kCustomTabTag[]; | 108 static const char kCustomTabTag[]; |
| 107 | 109 |
| 108 DataUseTabModel(); | 110 // |force_fetch_matching_rules_callback| is the callback to be run to initiate |
| 109 | 111 // fetching matching rules and |on_matching_rules_fetched_callback| |
| 110 // Initializes |this| on UI thread. |external_data_use_observer_bridge| is the | 112 // is the callback to be run after matching rules are fetched. |
| 111 // pointer to ExternalDataUseObserverBridge object. DataUseTabModel and | 113 DataUseTabModel( |
| 112 // ExternalDataUseObserverBridge objects are owned by ExternalDataUseObserver | 114 const base::Closure& force_fetch_matching_rules_callback, |
| 113 // and DataUseTabModel is destroyed first followed by | 115 const base::Callback<void(bool)>& on_matching_rules_fetched_callback); |
| 114 // ExternalDataUseObserverBridge. | |
| 115 void InitOnUIThread( | |
| 116 const ExternalDataUseObserverBridge* external_data_use_observer_bridge); | |
| 117 | 116 |
| 118 virtual ~DataUseTabModel(); | 117 virtual ~DataUseTabModel(); |
| 119 | 118 |
| 120 base::WeakPtr<DataUseTabModel> GetWeakPtr(); | 119 base::WeakPtr<DataUseTabModel> GetWeakPtr(); |
| 121 | 120 |
| 122 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source | 121 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source |
| 123 // tab of the generated event, |transition| indicates the type of the UI | 122 // tab of the generated event, |transition| indicates the type of the UI |
| 124 // event/transition, |url| is the URL in the source tab, |package| indicates | 123 // event/transition, |url| is the URL in the source tab, |package| indicates |
| 125 // the android package name of external application that initiated the event. | 124 // the android package name of external application that initiated the event. |
| 126 // |navigation_entry| corresponds to the navigation entry of the current | 125 // |navigation_entry| corresponds to the navigation entry of the current |
| 127 // navigation in back-forward navigation history, and is used to save the | 126 // navigation in back-forward navigation history, and is used to save the |
| 128 // current tracking label to be used for back-forward navigations. | 127 // current tracking label to be used for back-forward navigations. |
| 129 // |navigation_entry| can be null in some cases where it cannot be retrieved | 128 // |navigation_entry| can be null in some cases where it cannot be retrieved |
| 130 // such as buffered navigation events or when support for back-forward | 129 // such as buffered navigation events or when support for back-forward |
| 131 // navigations is not needed such as custom tab navigation. | 130 // navigations is not needed such as custom tab navigation. |
| 132 void OnNavigationEvent(SessionID::id_type tab_id, | 131 void OnNavigationEvent(SessionID::id_type tab_id, |
| 133 TransitionType transition, | 132 TransitionType transition, |
| 134 const GURL& url, | 133 const GURL& url, |
| 135 const std::string& package, | 134 const std::string& package, |
| 136 content::NavigationEntry* navigation_entry); | 135 content::NavigationEntry* navigation_entry); |
| 137 | 136 |
| 138 // Notifies the DataUseTabModel that tab with |tab_id| is closed. Any active | 137 // Notifies the DataUseTabModel that tab with |tab_id| is closed. Any active |
| 139 // tracking sessions for the tab are terminated, and the tab is marked as | 138 // tracking sessions for the tab are terminated, and the tab is marked as |
| 140 // closed. | 139 // closed. |
| 141 void OnTabCloseEvent(SessionID::id_type tab_id); | 140 void OnTabCloseEvent(SessionID::id_type tab_id); |
| 142 | 141 |
| 143 // Notifies the DataUseTabModel that tracking label |label| is removed. Any | 142 // Notifies the DataUseTabModel that tracking label |label| is removed. Any |
| 144 // active tracking sessions with the label are ended, without notifying any of | 143 // active tracking sessions with the label are ended, without notifying any of |
| 145 // the TabDataUseObserver. | 144 // the TabDataUseObserver. |
| 146 virtual void OnTrackingLabelRemoved(std::string label); | 145 virtual void OnTrackingLabelRemoved(const std::string& label); |
| 147 | 146 |
| 148 // Gets the tracking information for the tab with id |tab_id| at time | 147 // Gets the tracking information for the tab with id |tab_id| at time |
| 149 // |timestamp|. |output_info| must not be null. If a tab tracking session is | 148 // |timestamp|. |output_info| must not be null. If a tab tracking session is |
| 150 // found that was active at |timestamp|, returns true and | 149 // found that was active at |timestamp|, returns true and |
| 151 // |output_tracking_info| is populated with its information. Otherwise, | 150 // |output_tracking_info| is populated with its information. Otherwise, |
| 152 // returns false. | 151 // returns false. |
| 153 virtual bool GetTrackingInfoForTabAtTime( | 152 virtual bool GetTrackingInfoForTabAtTime( |
| 154 SessionID::id_type tab_id, | 153 SessionID::id_type tab_id, |
| 155 base::TimeTicks timestamp, | 154 base::TimeTicks timestamp, |
| 156 TrackingInfo* output_tracking_info) const; | 155 TrackingInfo* output_tracking_info) const; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // respectively. | 298 // respectively. |
| 300 const base::TimeDelta closed_tab_expiration_duration_; | 299 const base::TimeDelta closed_tab_expiration_duration_; |
| 301 const base::TimeDelta open_tab_expiration_duration_; | 300 const base::TimeDelta open_tab_expiration_duration_; |
| 302 | 301 |
| 303 // TickClock used for obtaining the current time. | 302 // TickClock used for obtaining the current time. |
| 304 std::unique_ptr<base::TickClock> tick_clock_; | 303 std::unique_ptr<base::TickClock> tick_clock_; |
| 305 | 304 |
| 306 // Stores the matching patterns. | 305 // Stores the matching patterns. |
| 307 std::unique_ptr<DataUseMatcher> data_use_matcher_; | 306 std::unique_ptr<DataUseMatcher> data_use_matcher_; |
| 308 | 307 |
| 308 // Callback to be run to initiate fetching the matching rules. |
| 309 const base::Closure force_fetch_matching_rules_callback_; |
| 310 |
| 309 // True if DataUseTabModel is ready to process UI navigation events. | 311 // True if DataUseTabModel is ready to process UI navigation events. |
| 310 // DataUseTabModel will be considered ready when the first rule fetch is | 312 // DataUseTabModel will be considered ready when the first rule fetch is |
| 311 // complete or the control app not installed callback was received, whichever | 313 // complete or the control app not installed callback was received, whichever |
| 312 // is sooner. | 314 // is sooner. |
| 313 bool is_ready_for_navigation_event_; | 315 bool is_ready_for_navigation_event_; |
| 314 | 316 |
| 315 // True if the external control app is installed. | 317 // True if the external control app is installed. |
| 316 bool is_control_app_installed_; | 318 bool is_control_app_installed_; |
| 317 | 319 |
| 318 base::ThreadChecker thread_checker_; | 320 base::ThreadChecker thread_checker_; |
| 319 | 321 |
| 320 base::WeakPtrFactory<DataUseTabModel> weak_factory_; | 322 base::WeakPtrFactory<DataUseTabModel> weak_factory_; |
| 321 | 323 |
| 322 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); | 324 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); |
| 323 }; | 325 }; |
| 324 | 326 |
| 325 } // namespace android | 327 } // namespace android |
| 326 | 328 |
| 327 } // namespace chrome | 329 } // namespace chrome |
| 328 | 330 |
| 329 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ | 331 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
| OLD | NEW |