blob: 473ae62045294ec680a810b235b9103c25f1bf0d [file] [log] [blame]
// Copyright 2018 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.
#include <memory>
#include "base/macros.h"
#include "base/time/tick_clock.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/in_product_help/active_tab_tracker.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_trigger.h"
#include "components/keyed_service/core/keyed_service.h"
namespace base {
class TickClock;
namespace feature_engagement {
class Tracker;
class TabStripModel;
// Listens for the triggering conditions for the reopen tab in-product help and
// starts the IPH flow at the appropriate time. This is a |Profile|-keyed
// service since we track interactions per user profile. Hooks throughout the
// browser UI code will fetch this service and notify it of interesting user
// actions.
class ReopenTabInProductHelp : public BrowserListObserver, public KeyedService {
ReopenTabInProductHelp(Profile* profile, const base::TickClock* clock);
~ReopenTabInProductHelp() override;
// Should be called when the user opens a blank new tab. Possibly triggers
// IPH.
void NewTabOpened();
// Should be called when the user reopens a previously closed tab, either
// through CTRL+SHIFT+T or through the recent tabs menu.
void TabReopened();
// Must be called when IPH promo finishes showing, whether by use of the
// feature or by timing out.
void HelpDismissed();
// BrowserListObserver:
void OnBrowserAdded(Browser* browser) override;
void OnBrowserRemoved(Browser* browser) override;
feature_engagement::Tracker* GetTracker();
// Callback passed to the |ActiveTabTracker|.
void OnActiveTabClosed(TabStripModel* tab_strip_model,
base::TimeDelta active_duration);
// Callback passed to |ReopenTabInProductHelpTrigger|.
void OnShowHelp();
Profile* const profile_;
const base::TickClock* const clock_;
// Tracks active tab durations and notifies us when an active tab is closed.
ActiveTabTracker active_tab_tracker_;
// Manages the triggering logic for this IPH. This object calls into the IPH
// backend.
ReopenTabInProductHelpTrigger trigger_;