Commit 4a639c2f authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Insert UI hooks for reopen tab in-product help

ReopenTabInProductHelp watches for certain user interactions and
possibly triggers in-product help in response to them. These hooks
call into this when such user events happen.

Bug: 887991
Change-Id: I8f07626f07375a902f87f62dd662d51e8dbfc2ca
Reviewed-on: https://chromium-review.googlesource.com/c/1306791
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604294}
parent d3772f77
......@@ -46,6 +46,8 @@
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
......@@ -599,6 +601,14 @@ void NewTab(Browser* browser) {
UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_COMMAND,
TabStripModel::NEW_TAB_ENUM_COUNT);
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
// Notify IPH that new tab was opened.
auto* reopen_tab_iph =
in_product_help::ReopenTabInProductHelpFactory::GetForProfile(
browser->profile());
reopen_tab_iph->NewTabOpened();
#endif
if (browser->is_type_tabbed()) {
AddTabAt(browser, GURL(), -1, true);
browser->tab_strip_model()->GetActiveWebContents()->RestoreFocus();
......
......@@ -14,6 +14,9 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_live_tab_context.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include "components/feature_engagement/buildflags.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/sessions/core/tab_restore_service_observer.h"
......@@ -100,6 +103,13 @@ void BrowserTabRestorer::OnBrowserRemoved(Browser* browser) {
void RestoreTab(Browser* browser) {
base::RecordAction(base::UserMetricsAction("RestoreTab"));
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
auto* reopen_tab_iph =
in_product_help::ReopenTabInProductHelpFactory::GetForProfile(
browser->profile());
reopen_tab_iph->TabReopened();
#endif
sessions::TabRestoreService* service =
TabRestoreServiceFactory::GetForProfile(browser->profile());
if (!service)
......
......@@ -22,6 +22,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_live_tab_context.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/grit/browser_resources.h"
......@@ -29,6 +31,7 @@
#include "chrome/grit/theme_resources.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/favicon_base/favicon_types.h"
#include "components/feature_engagement/buildflags.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/strings/grit/components_strings.h"
......@@ -328,6 +331,14 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
disposition);
}
}
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
auto* reopen_tab_iph =
in_product_help::ReopenTabInProductHelpFactory::GetForProfile(
browser_->profile());
reopen_tab_iph->TabReopened();
#endif
UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.OpenRecentTab",
menu_opened_timer_.Elapsed());
UMA_HISTOGRAM_ENUMERATION("WrenchMenu.MenuAction", MENU_ACTION_RECENT_TAB,
......
......@@ -17,6 +17,8 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include "chrome/browser/ui/omnibox/clipboard_utils.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/view_ids.h"
......@@ -1060,18 +1062,24 @@ void OmniboxViewViews::OnFocus() {
if (location_bar_view_ && model()->is_keyword_hint())
location_bar_view_->Layout();
// The user must be starting a session in the same tab as a previous one
// in order to display the new tab in-product help promo.
// While focusing the omnibox is not always a precursor to starting a new
// session, we don't want to wait until the user is in the middle of editing
// or navigating, because we'd like to show them the promo at the time when
// it would be immediately useful.
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
if (location_bar_view_ &&
controller()->GetLocationBarModel()->ShouldDisplayURL()) {
feature_engagement::NewTabTrackerFactory::GetInstance()
->GetForProfile(location_bar_view_->profile())
->OnOmniboxFocused();
if (location_bar_view_) {
// The user must be starting a session in the same tab as a previous one in
// order to display the new tab in-product help promo. While focusing the
// omnibox is not always a precursor to starting a new session, we don't
// want to wait until the user is in the middle of editing or navigating,
// because we'd like to show them the promo at the time when it would be
// immediately useful.
if (controller()->GetLocationBarModel()->ShouldDisplayURL()) {
feature_engagement::NewTabTrackerFactory::GetInstance()
->GetForProfile(location_bar_view_->profile())
->OnOmniboxFocused();
}
auto* reopen_tab_iph =
in_product_help::ReopenTabInProductHelpFactory::GetForProfile(
location_bar_view_->profile());
reopen_tab_iph->OmniboxFocused();
}
#endif
......
......@@ -20,6 +20,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include "chrome/browser/ui/tab_ui_helper.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_network_state.h"
......@@ -316,7 +318,19 @@ NewTabButtonPosition BrowserTabStripController::GetNewTabButtonPosition()
}
void BrowserTabStripController::CreateNewTab() {
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
// This must be called before AddTabAt() so that OmniboxFocused is called
// after NewTabOpened. TODO(collinbaker): remove omnibox focusing from
// triggering conditions (since it is always focused for new tabs) and move
// this after AddTabAt() call.
auto* reopen_tab_iph =
in_product_help::ReopenTabInProductHelpFactory::GetForProfile(
browser_view_->browser()->profile());
reopen_tab_iph->NewTabOpened();
#endif
model_->delegate()->AddTabAt(GURL(), -1, true);
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
auto* new_tab_tracker =
feature_engagement::NewTabTrackerFactory::GetInstance()->GetForProfile(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment