blob: 999fa9b6bd165fa2f2b7e333e371a53402808dd3 [file] [log] [blame]
Mei Liangda912622018-07-19 20:17:121// 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 Liang2efb9d132019-01-16 05:39:285#ifndef CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_
6#define CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_
Mei Liangda912622018-07-19 20:17:127
8#include <map>
9
10#include "base/macros.h"
David Maunder445c72b2019-05-02 16:14:2011#include "build/build_config.h"
Mei Liangda912622018-07-19 20:17:1212#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 Maunder445c72b2019-05-02 16:14:2016namespace sessions {
17class ContextRecordTaskId;
18}
19
Mei Liangda912622018-07-19 20:17:1220namespace tasks {
21
Mei Liang2efb9d132019-01-16 05:39:2822// This is a tab helper that collects navigation state information of a
23// complex task.
Mei Liangda912622018-07-19 20:17:1224class 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 Maunder445c72b2019-05-02 16:14:2034 static sessions::ContextRecordTaskId* GetContextRecordTaskId(
35 content::WebContents* web_contents);
Mei Liangda912622018-07-19 20:17:1236
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 Maunder445c72b2019-05-02 16:14:2054#if defined(OS_ANDROID)
55 int64_t GetParentTaskId();
56 int64_t GetParentRootTaskId();
57#endif // defined(OS_ANDROID)
58
Mei Liangda912622018-07-19 20:17:1259 int last_pruned_navigation_entry_index_;
60 std::map<int, int> entry_index_to_spoke_count_map_;
61
François Doray4f51d5d2018-12-03 22:26:2462 WEB_CONTENTS_USER_DATA_KEY_DECL();
63
Mei Liangda912622018-07-19 20:17:1264 DISALLOW_COPY_AND_ASSIGN(TaskTabHelper);
65};
66
67} // namespace tasks
68
Mei Liang2efb9d132019-01-16 05:39:2869#endif // CHROME_BROWSER_COMPLEX_TASKS_TASK_TAB_HELPER_H_