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

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: 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_forward.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 // |external_data_use_observer_bridge| is the pointer to
109 110 // ExternalDataUseObserverBridge object. DataUseTabModel and
110 // Initializes |this| on UI thread. |external_data_use_observer_bridge| is the
111 // pointer to ExternalDataUseObserverBridge object. DataUseTabModel and
112 // ExternalDataUseObserverBridge objects are owned by ExternalDataUseObserver 111 // ExternalDataUseObserverBridge objects are owned by ExternalDataUseObserver
113 // and DataUseTabModel is destroyed first followed by 112 // and DataUseTabModel is destroyed first followed by
114 // ExternalDataUseObserverBridge. 113 // ExternalDataUseObserverBridge.
115 void InitOnUIThread( 114 DataUseTabModel(
116 const ExternalDataUseObserverBridge* external_data_use_observer_bridge); 115 const base::Closure& fetch_matching_rules_callback,
116 const base::Callback<void(bool)>& on_matching_rules_fetched_callback);
117
118 // Initializes |this| on UI thread.
119 void InitOnUIThread();
117 120
118 virtual ~DataUseTabModel(); 121 virtual ~DataUseTabModel();
119 122
120 base::WeakPtr<DataUseTabModel> GetWeakPtr(); 123 base::WeakPtr<DataUseTabModel> GetWeakPtr();
121 124
122 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source 125 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source
123 // tab of the generated event, |transition| indicates the type of the UI 126 // 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 127 // event/transition, |url| is the URL in the source tab, |package| indicates
125 // the android package name of external application that initiated the event. 128 // the android package name of external application that initiated the event.
126 // |navigation_entry| corresponds to the navigation entry of the current 129 // |navigation_entry| corresponds to the navigation entry of the current
127 // navigation in back-forward navigation history, and is used to save the 130 // navigation in back-forward navigation history, and is used to save the
128 // current tracking label to be used for back-forward navigations. 131 // current tracking label to be used for back-forward navigations.
129 // |navigation_entry| can be null in some cases where it cannot be retrieved 132 // |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 133 // such as buffered navigation events or when support for back-forward
131 // navigations is not needed such as custom tab navigation. 134 // navigations is not needed such as custom tab navigation.
132 void OnNavigationEvent(SessionID::id_type tab_id, 135 void OnNavigationEvent(SessionID::id_type tab_id,
133 TransitionType transition, 136 TransitionType transition,
134 const GURL& url, 137 const GURL& url,
135 const std::string& package, 138 const std::string& package,
136 content::NavigationEntry* navigation_entry); 139 content::NavigationEntry* navigation_entry);
137 140
138 // Notifies the DataUseTabModel that tab with |tab_id| is closed. Any active 141 // 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 142 // tracking sessions for the tab are terminated, and the tab is marked as
140 // closed. 143 // closed.
141 void OnTabCloseEvent(SessionID::id_type tab_id); 144 void OnTabCloseEvent(SessionID::id_type tab_id);
142 145
143 // Notifies the DataUseTabModel that tracking label |label| is removed. Any 146 // Notifies the DataUseTabModel that tracking label |label| is removed. Any
144 // active tracking sessions with the label are ended, without notifying any of 147 // active tracking sessions with the label are ended, without notifying any of
145 // the TabDataUseObserver. 148 // the TabDataUseObserver.
146 virtual void OnTrackingLabelRemoved(std::string label); 149 virtual void OnTrackingLabelRemoved(const std::string& label);
147 150
148 // Gets the tracking information for the tab with id |tab_id| at time 151 // 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 152 // |timestamp|. |output_info| must not be null. If a tab tracking session is
150 // found that was active at |timestamp|, returns true and 153 // found that was active at |timestamp|, returns true and
151 // |output_tracking_info| is populated with its information. Otherwise, 154 // |output_tracking_info| is populated with its information. Otherwise,
152 // returns false. 155 // returns false.
153 virtual bool GetTrackingInfoForTabAtTime( 156 virtual bool GetTrackingInfoForTabAtTime(
154 SessionID::id_type tab_id, 157 SessionID::id_type tab_id,
155 base::TimeTicks timestamp, 158 base::TimeTicks timestamp,
156 TrackingInfo* output_tracking_info) const; 159 TrackingInfo* output_tracking_info) const;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // respectively. 301 // respectively.
299 const base::TimeDelta closed_tab_expiration_duration_; 302 const base::TimeDelta closed_tab_expiration_duration_;
300 const base::TimeDelta open_tab_expiration_duration_; 303 const base::TimeDelta open_tab_expiration_duration_;
301 304
302 // TickClock used for obtaining the current time. 305 // TickClock used for obtaining the current time.
303 std::unique_ptr<base::TickClock> tick_clock_; 306 std::unique_ptr<base::TickClock> tick_clock_;
304 307
305 // Stores the matching patterns. 308 // Stores the matching patterns.
306 std::unique_ptr<DataUseMatcher> data_use_matcher_; 309 std::unique_ptr<DataUseMatcher> data_use_matcher_;
307 310
311 // Callback to be run to initiate fetching the matching rules.
312 const base::Closure& fetch_matching_rules_callback_;
313
308 // True if DataUseTabModel is ready to process UI navigation events. 314 // True if DataUseTabModel is ready to process UI navigation events.
309 // DataUseTabModel will be considered ready when the first rule fetch is 315 // DataUseTabModel will be considered ready when the first rule fetch is
310 // complete or the control app not installed callback was received, whichever 316 // complete or the control app not installed callback was received, whichever
311 // is sooner. 317 // is sooner.
312 bool is_ready_for_navigation_event_; 318 bool is_ready_for_navigation_event_;
313 319
314 // True if the external control app is installed. 320 // True if the external control app is installed.
315 bool is_control_app_installed_; 321 bool is_control_app_installed_;
316 322
317 base::ThreadChecker thread_checker_; 323 base::ThreadChecker thread_checker_;
318 324
319 base::WeakPtrFactory<DataUseTabModel> weak_factory_; 325 base::WeakPtrFactory<DataUseTabModel> weak_factory_;
320 326
321 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); 327 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel);
322 }; 328 };
323 329
324 } // namespace android 330 } // namespace android
325 331
326 } // namespace chrome 332 } // namespace chrome
327 333
328 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ 334 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698