blob: 7a623f659d7091605f474d338b8c155612bc9a79 [file] [log] [blame]
Abigail Klein4a4ac272020-04-07 17:47:151// Copyright 2020 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
5#include "chrome/browser/accessibility/caption_controller_factory.h"
6
7#include "build/build_config.h"
8#include "chrome/browser/accessibility/caption_controller.h"
9#include "chrome/browser/profiles/incognito_helpers.h"
10#include "chrome/browser/profiles/profile.h"
11#include "components/keyed_service/content/browser_context_dependency_manager.h"
12
13namespace captions {
14
15// static
16CaptionController* CaptionControllerFactory::GetForProfile(Profile* profile) {
17 return static_cast<CaptionController*>(
18 GetInstance()->GetServiceForBrowserContext(profile, true));
19}
20
21// static
22CaptionController* CaptionControllerFactory::GetForProfileIfExists(
23 Profile* profile) {
24 return static_cast<CaptionController*>(
25 GetInstance()->GetServiceForBrowserContext(profile, /*create=*/false));
26}
27
28// static
29CaptionControllerFactory* CaptionControllerFactory::GetInstance() {
30 static base::NoDestructor<CaptionControllerFactory> factory;
31 return factory.get();
32}
33
34CaptionControllerFactory::CaptionControllerFactory()
35 : BrowserContextKeyedServiceFactory(
36 "CaptionController",
37 BrowserContextDependencyManager::GetInstance()) {}
38
39CaptionControllerFactory::~CaptionControllerFactory() = default;
40
41content::BrowserContext* CaptionControllerFactory::GetBrowserContextToUse(
42 content::BrowserContext* context) const {
43 return chrome::GetBrowserContextRedirectedInIncognito(context);
44}
45
46KeyedService* CaptionControllerFactory::BuildServiceInstanceFor(
47 content::BrowserContext* context) const {
48 return new CaptionController(Profile::FromBrowserContext(context));
49}
50
51} // namespace captions