-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
tab_search_page_handler.h
133 lines (110 loc) · 5.12 KB
/
tab_search_page_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_TAB_SEARCH_TAB_SEARCH_PAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_TAB_SEARCH_TAB_SEARCH_PAGE_HANDLER_H_
#include "chrome/browser/ui/browser_tab_strip_tracker.h"
#include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_group_theme.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/webui/tab_search/tab_search.mojom.h"
#include "components/sessions/core/tab_restore_service.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ui/webui/mojo_bubble_web_ui_controller.h"
class Browser;
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class TabSearchCloseAction {
kNoAction = 0,
kTabSwitch = 1,
kMaxValue = kTabSwitch,
};
class TabSearchPageHandler : public tab_search::mojom::PageHandler,
public TabStripModelObserver,
public BrowserTabStripTrackerDelegate,
public content::WebContentsObserver {
public:
TabSearchPageHandler(
mojo::PendingReceiver<tab_search::mojom::PageHandler> receiver,
mojo::PendingRemote<tab_search::mojom::Page> page,
content::WebUI* web_ui,
ui::MojoBubbleWebUIController* webui_controller);
TabSearchPageHandler(const TabSearchPageHandler&) = delete;
TabSearchPageHandler& operator=(const TabSearchPageHandler&) = delete;
~TabSearchPageHandler() override;
// tab_search::mojom::PageHandler:
void CloseTab(int32_t tab_id) override;
void GetProfileData(GetProfileDataCallback callback) override;
void GetTabGroups(GetTabGroupsCallback callback) override;
void ShowFeedbackPage() override;
void SwitchToTab(
tab_search::mojom::SwitchToTabInfoPtr switch_to_tab_info) override;
void ShowUI() override;
// TODO(tluk): Remove this once all uses of the CloseUI() interface are
// removed from the Tab Search WebUI code.
void CloseUI() override {}
// TabStripModelObserver:
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void TabChangedAt(content::WebContents* contents,
int index,
TabChangeType change_type) override;
// BrowserTabStripTrackerDelegate:
bool ShouldTrackBrowser(Browser* browser) override;
// content::WebContentsObserver:
void OnVisibilityChanged(content::Visibility visibility) override;
protected:
void SetTimerForTesting(std::unique_ptr<base::RetainingOneShotTimer> timer);
private:
// Encapsulates tab details to facilitate performing an action on a tab.
struct TabDetails {
TabDetails(Browser* browser, TabStripModel* tab_strip_model, int index)
: browser(browser), tab_strip_model(tab_strip_model), index(index) {}
Browser* browser;
TabStripModel* tab_strip_model;
int index;
};
tab_search::mojom::ProfileDataPtr CreateProfileData();
void CreateRecentlyClosedTabs(
std::vector<tab_search::mojom::RecentlyClosedTabPtr>&
recently_closed_tabs);
tab_search::mojom::TabPtr GetTab(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index);
tab_search::mojom::RecentlyClosedTabPtr GetRecentlyClosedTab(
sessions::TabRestoreService::Tab* tab);
// Returns tab details required to perform an action on the tab.
base::Optional<TabDetails> GetTabDetails(int32_t tab_id);
// Schedule a timer to call TabsChanged() when it times out
// in order to reduce numbers of RPC.
void ScheduleDebounce();
// Call TabsChanged() and stop the timer if it's running.
void NotifyTabsChanged();
mojo::Receiver<tab_search::mojom::PageHandler> receiver_;
mojo::Remote<tab_search::mojom::Page> page_;
Browser* const browser_;
content::WebUI* const web_ui_;
ui::MojoBubbleWebUIController* const webui_controller_;
BrowserTabStripTracker browser_tab_strip_tracker_{this, this};
std::unique_ptr<base::RetainingOneShotTimer> debounce_timer_;
bool webui_hidden_ = false;
// Tracks how many times |CloseTab()| has been evoked for the currently open
// instance of Tab Search for logging in UMA.
int num_tabs_closed_ = 0;
// Tracks whether or not we have sent the initial payload to the Tab Search
// UI for metric collection purposes.
bool sent_initial_payload_ = false;
// Tracks whether the user has evoked |SwitchToTab()| for metric collection
// purposes.
bool called_switch_to_tab_ = false;
};
#endif // CHROME_BROWSER_UI_WEBUI_TAB_SEARCH_TAB_SEARCH_PAGE_HANDLER_H_