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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "base/time/time.h" |
19 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" | 20 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" |
20 #include "components/data_usage/core/data_use.h" | 21 #include "components/data_usage/core/data_use.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace chrome { | 24 namespace chrome { |
24 | 25 |
25 namespace android { | 26 namespace android { |
26 | 27 |
27 class ExternalDataUseObserver; | 28 class ExternalDataUseObserver; |
28 | 29 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // Notification callback when tab tracking sessions are started and ended. | 71 // Notification callback when tab tracking sessions are started and ended. |
71 // The callback will be received on the same thread AddObserver was called | 72 // The callback will be received on the same thread AddObserver was called |
72 // from. | 73 // from. |
73 virtual void NotifyTrackingStarting(int32_t tab_id) = 0; | 74 virtual void NotifyTrackingStarting(int32_t tab_id) = 0; |
74 virtual void NotifyTrackingEnding(int32_t tab_id) = 0; | 75 virtual void NotifyTrackingEnding(int32_t tab_id) = 0; |
75 }; | 76 }; |
76 | 77 |
77 DataUseTabModel(const ExternalDataUseObserver* data_use_observer, | 78 DataUseTabModel(const ExternalDataUseObserver* data_use_observer, |
78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
79 | 80 |
80 ~DataUseTabModel(); | 81 virtual ~DataUseTabModel(); |
81 | 82 |
82 base::WeakPtr<DataUseTabModel> GetWeakPtr(); | 83 base::WeakPtr<DataUseTabModel> GetWeakPtr(); |
83 | 84 |
84 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source | 85 // Notifies the DataUseTabModel of navigation events. |tab_id| is the source |
85 // tab of the generated event, |transition| indicates the type of the UI | 86 // tab of the generated event, |transition| indicates the type of the UI |
86 // event/transition, |url| is the URL in the source tab, |package| indicates | 87 // event/transition, |url| is the URL in the source tab, |package| indicates |
87 // the android package name of external application that initiated the event. | 88 // the android package name of external application that initiated the event. |
88 void OnNavigationEvent(int32_t tab_id, | 89 void OnNavigationEvent(int32_t tab_id, |
89 TransitionType transition, | 90 TransitionType transition, |
90 const GURL& url, | 91 const GURL& url, |
(...skipping 12 matching lines...) Expand all Loading... |
103 std::string* output_label) const; | 104 std::string* output_label) const; |
104 | 105 |
105 // Adds or removes observers from the observer list. These functions are | 106 // Adds or removes observers from the observer list. These functions are |
106 // thread-safe and can be called from any thread. | 107 // thread-safe and can be called from any thread. |
107 void AddObserver(TabDataUseObserver* observer); | 108 void AddObserver(TabDataUseObserver* observer); |
108 void RemoveObserver(TabDataUseObserver* observer); | 109 void RemoveObserver(TabDataUseObserver* observer); |
109 | 110 |
110 private: | 111 private: |
111 friend class DataUseTabModelTest; | 112 friend class DataUseTabModelTest; |
112 friend class MockTabDataUseEntryTest; | 113 friend class MockTabDataUseEntryTest; |
113 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, SingleTabTracking); | |
114 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, MultipleTabTracking); | |
115 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverStartEndEvents); | |
116 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverNotNotifiedAfterRemove); | |
117 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | |
118 MultipleObserverMultipleStartEndEvents); | |
119 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent); | 114 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent); |
120 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); | 115 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEventEndsTracking); |
121 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, | 116 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
122 CompactTabEntriesWithinMaxLimit); | 117 CompactTabEntriesWithinMaxLimit); |
| 118 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
| 119 UnexpiredTabEntryRemovaltimeHistogram); |
| 120 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
| 121 ExpiredInactiveTabEntryRemovaltimeHistogram); |
| 122 FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, |
| 123 ExpiredActiveTabEntryRemovaltimeHistogram); |
123 | 124 |
124 typedef base::hash_map<int32_t, TabDataUseEntry> TabEntryMap; | 125 typedef base::hash_map<int32_t, TabDataUseEntry> TabEntryMap; |
125 | 126 |
| 127 // Virtualized for unit test support. |
| 128 virtual base::TimeTicks Now() const; |
| 129 |
126 // Returns the maximum number of tab entries to maintain session information | 130 // Returns the maximum number of tab entries to maintain session information |
127 // about. | 131 // about. |
128 static size_t GetMaxTabEntriesForTests(); | 132 static size_t GetMaxTabEntriesForTests(); |
129 | 133 |
130 // Notifies the observers that a data usage tracking session started for | 134 // Notifies the observers that a data usage tracking session started for |
131 // |tab_id|. | 135 // |tab_id|. |
132 void NotifyObserversOfTrackingStarting(int32_t tab_id); | 136 void NotifyObserversOfTrackingStarting(int32_t tab_id); |
133 | 137 |
134 // Notifies the observers that an active data usage tracking session ended for | 138 // Notifies the observers that an active data usage tracking session ended for |
135 // |tab_id|. | 139 // |tab_id|. |
(...skipping 29 matching lines...) Expand all Loading... |
165 base::WeakPtrFactory<DataUseTabModel> weak_factory_; | 169 base::WeakPtrFactory<DataUseTabModel> weak_factory_; |
166 | 170 |
167 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); | 171 DISALLOW_COPY_AND_ASSIGN(DataUseTabModel); |
168 }; | 172 }; |
169 | 173 |
170 } // namespace android | 174 } // namespace android |
171 | 175 |
172 } // namespace chrome | 176 } // namespace chrome |
173 | 177 |
174 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ | 178 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_ |
OLD | NEW |