Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: chrome/browser/android/data_usage/data_use_tab_model.h

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

Powered by Google App Engine
This is Rietveld 408576698