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_UI_TAB_MODEL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 SessionID::id_type tab_id) const; | 52 SessionID::id_type tab_id) const; |
53 | 53 |
54 // Reports a tab closure for the tab with |tab_id| to the DataUseTabModel on | 54 // Reports a tab closure for the tab with |tab_id| to the DataUseTabModel on |
55 // IO thread. The tab could either have been closed or evicted from the memory | 55 // IO thread. The tab could either have been closed or evicted from the memory |
56 // by Android. | 56 // by Android. |
57 void ReportTabClosure(SessionID::id_type tab_id); | 57 void ReportTabClosure(SessionID::id_type tab_id); |
58 | 58 |
59 // Reports a custom tab navigation to the DataUseTabModel on the IO thread. | 59 // Reports a custom tab navigation to the DataUseTabModel on the IO thread. |
60 // Includes the |tab_id|, |url|, and |package_name| for the navigation. | 60 // Includes the |tab_id|, |url|, and |package_name| for the navigation. |
61 void ReportCustomTabInitialNavigation(SessionID::id_type tab_id, | 61 void ReportCustomTabInitialNavigation(SessionID::id_type tab_id, |
62 const std::string& url, | 62 const std::string& package_name, |
63 const std::string& package_name); | 63 const std::string& url); |
64 | 64 |
65 // Returns true if data use tracking has been started for the tab with id | 65 // Returns true if data use tracking has been started for the tab with id |
66 // |tab_id|. Calling this function resets the state of the tab. | 66 // |tab_id|. Calling this function resets the state of the tab. |
67 bool HasDataUseTrackingStarted(SessionID::id_type tab_id); | 67 bool HasDataUseTrackingStarted(SessionID::id_type tab_id); |
68 | 68 |
69 // Returns true if data use tracking has ended for the tab with id |tab_id|. | 69 // Returns true if data use tracking has ended for the tab with id |tab_id|. |
70 // Calling this function resets the state of the tab. | 70 // Calling this function resets the state of the tab. |
71 bool HasDataUseTrackingEnded(SessionID::id_type tab_id); | 71 bool HasDataUseTrackingEnded(SessionID::id_type tab_id); |
72 | 72 |
73 // Sets the pointer to DataUseTabModel. |data_use_tab_model| is owned by the | 73 // Sets the pointer to DataUseTabModel. |data_use_tab_model| is owned by the |
74 // caller. | 74 // caller. |
75 void SetDataUseTabModel(DataUseTabModel* data_use_tab_model); | 75 void SetDataUseTabModel(DataUseTabModel* data_use_tab_model); |
76 | 76 |
| 77 // Returns true if the tab with id |tab_id| is currently tracked, and |
| 78 // starting the navigation to |url| with transition type |page_transition| |
| 79 // would end tracking of data use. Should only be called before the navigation |
| 80 // starts. |
| 81 bool WouldDataUseTrackingEnd(const std::string& url, |
| 82 int page_transition, |
| 83 SessionID::id_type tab_id) const; |
| 84 |
| 85 // Notifies that user clicked "Continue" when the dialog box with data use |
| 86 // warning was shown. Includes the |tab_id| on which the warning was shown. |
| 87 // When the user clicks "Continue", additional UI warnings about exiting data |
| 88 // use tracking are not shown to the user. |
| 89 void UserClickedContinueOnDialogBox(SessionID::id_type tab_id); |
| 90 |
77 base::WeakPtr<DataUseUITabModel> GetWeakPtr(); | 91 base::WeakPtr<DataUseUITabModel> GetWeakPtr(); |
78 | 92 |
79 private: | 93 private: |
80 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ConvertTransitionType); | 94 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ConvertTransitionType); |
81 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntranceExitState); | 95 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntranceExitState); |
| 96 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntraceExitStateForDialog); |
82 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); | 97 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); |
83 | 98 |
84 // DataUseTrackingEvent indicates the state of a tab. | 99 // DataUseTrackingEvent indicates the state of a tab. |
85 enum DataUseTrackingEvent { | 100 enum DataUseTrackingEvent { |
86 // Indicates that data use tracking has started. | 101 // Indicates that data use tracking has started. |
87 DATA_USE_TRACKING_STARTED, | 102 DATA_USE_TRACKING_STARTED, |
88 | 103 |
89 // Indicates that data use tracking has ended. | 104 // Indicates that data use tracking has ended. |
90 DATA_USE_TRACKING_ENDED, | 105 DATA_USE_TRACKING_ENDED, |
| 106 |
| 107 // Indicates that user clicked "Continue" when the dialog box was shown. |
| 108 DATA_USE_CONTINUE_CLICKED, |
91 }; | 109 }; |
92 | 110 |
93 typedef base::hash_map<SessionID::id_type, DataUseTrackingEvent> TabEvents; | 111 typedef base::hash_map<SessionID::id_type, DataUseTrackingEvent> TabEvents; |
94 | 112 |
95 // DataUseTabModel::TabDataUseObserver implementation: | 113 // DataUseTabModel::TabDataUseObserver implementation: |
96 void NotifyTrackingStarting(SessionID::id_type tab_id) override; | 114 void NotifyTrackingStarting(SessionID::id_type tab_id) override; |
97 void NotifyTrackingEnding(SessionID::id_type tab_id) override; | 115 void NotifyTrackingEnding(SessionID::id_type tab_id) override; |
98 | 116 |
99 // Creates |event| for tab with id |tab_id| and value |event|, if there is no | 117 // Creates |event| for tab with id |tab_id| and value |event|, if there is no |
100 // existing entry for |tab_id|, and returns true. Otherwise, returns false | 118 // existing entry for |tab_id|, and returns true. Otherwise, returns false |
(...skipping 25 matching lines...) Expand all Loading... |
126 base::WeakPtrFactory<DataUseUITabModel> weak_factory_; | 144 base::WeakPtrFactory<DataUseUITabModel> weak_factory_; |
127 | 145 |
128 DISALLOW_COPY_AND_ASSIGN(DataUseUITabModel); | 146 DISALLOW_COPY_AND_ASSIGN(DataUseUITabModel); |
129 }; | 147 }; |
130 | 148 |
131 } // namespace android | 149 } // namespace android |
132 | 150 |
133 } // namespace chrome | 151 } // namespace chrome |
134 | 152 |
135 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ | 153 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
OLD | NEW |