Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Mei Liang | 2efb9d13 | 2019-01-16 05:39:28 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_ |
| 6 | #define CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_ |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "base/macros.h" |
David Maunder | 445c72b | 2019-05-02 16:14:20 | [diff] [blame^] | 11 | #include "build/build_config.h" |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 12 | #include "content/public/browser/navigation_details.h" |
| 13 | #include "content/public/browser/web_contents_observer.h" |
| 14 | #include "content/public/browser/web_contents_user_data.h" |
| 15 | |
David Maunder | 445c72b | 2019-05-02 16:14:20 | [diff] [blame^] | 16 | namespace sessions { |
| 17 | class ContextRecordTaskId; |
| 18 | } |
| 19 | |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 20 | namespace tasks { |
| 21 | |
Mei Liang | 2efb9d13 | 2019-01-16 05:39:28 | [diff] [blame] | 22 | // This is a tab helper that collects navigation state information of a |
| 23 | // complex task. |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 24 | class TaskTabHelper : public content::WebContentsObserver, |
| 25 | public content::WebContentsUserData<TaskTabHelper> { |
| 26 | public: |
| 27 | ~TaskTabHelper() override; |
| 28 | |
| 29 | // WebContentsObserver |
| 30 | void NavigationEntryCommitted( |
| 31 | const content::LoadCommittedDetails& load_details) override; |
| 32 | void NavigationListPruned( |
| 33 | const content::PrunedDetails& pruned_details) override; |
David Maunder | 445c72b | 2019-05-02 16:14:20 | [diff] [blame^] | 34 | static sessions::ContextRecordTaskId* GetContextRecordTaskId( |
| 35 | content::WebContents* web_contents); |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | explicit TaskTabHelper(content::WebContents* web_contents); |
| 39 | |
| 40 | enum class HubType { DEFAULT_SEARCH_ENGINE, FORM_SUBMIT, OTHER }; |
| 41 | |
| 42 | virtual HubType GetSpokeEntryHubType() const; |
| 43 | |
| 44 | // For testing |
| 45 | int GetSpokesForTesting(int id) { |
| 46 | return entry_index_to_spoke_count_map_[id]; |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | friend class content::WebContentsUserData<TaskTabHelper>; |
| 51 | |
| 52 | void RecordHubAndSpokeNavigationUsage(int sample); |
| 53 | |
David Maunder | 445c72b | 2019-05-02 16:14:20 | [diff] [blame^] | 54 | #if defined(OS_ANDROID) |
| 55 | int64_t GetParentTaskId(); |
| 56 | int64_t GetParentRootTaskId(); |
| 57 | #endif // defined(OS_ANDROID) |
| 58 | |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 59 | int last_pruned_navigation_entry_index_; |
| 60 | std::map<int, int> entry_index_to_spoke_count_map_; |
| 61 | |
François Doray | 4f51d5d | 2018-12-03 22:26:24 | [diff] [blame] | 62 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 63 | |
Mei Liang | da91262 | 2018-07-19 20:17:12 | [diff] [blame] | 64 | DISALLOW_COPY_AND_ASSIGN(TaskTabHelper); |
| 65 | }; |
| 66 | |
| 67 | } // namespace tasks |
| 68 | |
Mei Liang | 2efb9d13 | 2019-01-16 05:39:28 | [diff] [blame] | 69 | #endif // CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_ |