Commit 817e3919 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Implement factory for ReopenTabInProductHelp keyed service

This will allow the per-profile instance to be fetched from any code
that has a Profile*.

Bug: 887991
Change-Id: I8394c07033b8e2940cf2a76bb6a697ca09ada452
Reviewed-on: https://chromium-review.googlesource.com/c/1306788
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604266}
parent 671ccdfe
...@@ -3306,6 +3306,8 @@ jumbo_split_static_library("ui") { ...@@ -3306,6 +3306,8 @@ jumbo_split_static_library("ui") {
"in_product_help/active_tab_tracker.h", "in_product_help/active_tab_tracker.h",
"in_product_help/reopen_tab_in_product_help.cc", "in_product_help/reopen_tab_in_product_help.cc",
"in_product_help/reopen_tab_in_product_help.h", "in_product_help/reopen_tab_in_product_help.h",
"in_product_help/reopen_tab_in_product_help_factory.cc",
"in_product_help/reopen_tab_in_product_help_factory.h",
"in_product_help/reopen_tab_in_product_help_trigger.cc", "in_product_help/reopen_tab_in_product_help_trigger.cc",
"in_product_help/reopen_tab_in_product_help_trigger.h", "in_product_help/reopen_tab_in_product_help_trigger.h",
] ]
......
// 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 "chrome/browser/ui/in_product_help/reopen_tab_in_product_help_factory.h"
#include <memory>
#include "base/memory/singleton.h"
#include "base/time/default_tick_clock.h"
#include "chrome/browser/feature_engagement/tracker_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/in_product_help/reopen_tab_in_product_help.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace in_product_help {
ReopenTabInProductHelpFactory::ReopenTabInProductHelpFactory()
: BrowserContextKeyedServiceFactory(
"ReopenTabInProductHelp",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(feature_engagement::TrackerFactory::GetInstance());
}
ReopenTabInProductHelpFactory::~ReopenTabInProductHelpFactory() {}
// static
ReopenTabInProductHelpFactory* ReopenTabInProductHelpFactory::GetInstance() {
return base::Singleton<ReopenTabInProductHelpFactory>::get();
}
// static
ReopenTabInProductHelp* ReopenTabInProductHelpFactory::GetForProfile(
Profile* profile) {
return static_cast<ReopenTabInProductHelp*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
KeyedService* ReopenTabInProductHelpFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new ReopenTabInProductHelp(Profile::FromBrowserContext(context),
base::DefaultTickClock::GetInstance());
}
content::BrowserContext* ReopenTabInProductHelpFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
} // namespace in_product_help
// 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.
#ifndef CHROME_BROWSER_UI_IN_PRODUCT_HELP_REOPEN_TAB_IN_PRODUCT_HELP_FACTORY_H_
#define CHROME_BROWSER_UI_IN_PRODUCT_HELP_REOPEN_TAB_IN_PRODUCT_HELP_FACTORY_H_
#include "base/macros.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace content {
class BrowserContext;
} // namespace content
namespace in_product_help {
class ReopenTabInProductHelp;
class ReopenTabInProductHelpFactory : public BrowserContextKeyedServiceFactory {
public:
static ReopenTabInProductHelpFactory* GetInstance();
static ReopenTabInProductHelp* GetForProfile(Profile* profile);
private:
ReopenTabInProductHelpFactory();
~ReopenTabInProductHelpFactory() override;
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
friend struct base::DefaultSingletonTraits<ReopenTabInProductHelpFactory>;
DISALLOW_COPY_AND_ASSIGN(ReopenTabInProductHelpFactory);
};
} // namespace in_product_help
#endif // CHROME_BROWSER_UI_IN_PRODUCT_HELP_REOPEN_TAB_IN_PRODUCT_HELP_FACTORY_H_
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