Abigail Klein | 4a4ac27 | 2020-04-07 17:47:15 | [diff] [blame] | 1 | // 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 | |
| 13 | namespace captions { |
| 14 | |
| 15 | // static |
| 16 | CaptionController* CaptionControllerFactory::GetForProfile(Profile* profile) { |
| 17 | return static_cast<CaptionController*>( |
| 18 | GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 19 | } |
| 20 | |
| 21 | // static |
| 22 | CaptionController* CaptionControllerFactory::GetForProfileIfExists( |
| 23 | Profile* profile) { |
| 24 | return static_cast<CaptionController*>( |
| 25 | GetInstance()->GetServiceForBrowserContext(profile, /*create=*/false)); |
| 26 | } |
| 27 | |
| 28 | // static |
| 29 | CaptionControllerFactory* CaptionControllerFactory::GetInstance() { |
| 30 | static base::NoDestructor<CaptionControllerFactory> factory; |
| 31 | return factory.get(); |
| 32 | } |
| 33 | |
| 34 | CaptionControllerFactory::CaptionControllerFactory() |
| 35 | : BrowserContextKeyedServiceFactory( |
| 36 | "CaptionController", |
| 37 | BrowserContextDependencyManager::GetInstance()) {} |
| 38 | |
| 39 | CaptionControllerFactory::~CaptionControllerFactory() = default; |
| 40 | |
| 41 | content::BrowserContext* CaptionControllerFactory::GetBrowserContextToUse( |
| 42 | content::BrowserContext* context) const { |
| 43 | return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 44 | } |
| 45 | |
| 46 | KeyedService* CaptionControllerFactory::BuildServiceInstanceFor( |
| 47 | content::BrowserContext* context) const { |
| 48 | return new CaptionController(Profile::FromBrowserContext(context)); |
| 49 | } |
| 50 | |
| 51 | } // namespace captions |