1 // Copyright 2019 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/media/history/media_history_keyed_service_factory.h"
6 
7 #include "chrome/browser/history/history_service_factory.h"
8 #include "chrome/browser/media/history/media_history_keyed_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
11 #include "content/public/browser/browser_context.h"
12 
13 namespace media_history {
14 
15 // static
GetForProfile(Profile * profile)16 MediaHistoryKeyedService* MediaHistoryKeyedServiceFactory::GetForProfile(
17     Profile* profile) {
18   return static_cast<MediaHistoryKeyedService*>(
19       GetInstance()->GetServiceForBrowserContext(profile, true));
20 }
21 
22 // static
23 MediaHistoryKeyedServiceFactory*
GetInstance()24 MediaHistoryKeyedServiceFactory::GetInstance() {
25   return base::Singleton<MediaHistoryKeyedServiceFactory>::get();
26 }
27 
MediaHistoryKeyedServiceFactory()28 MediaHistoryKeyedServiceFactory::MediaHistoryKeyedServiceFactory()
29     : BrowserContextKeyedServiceFactory(
30           "MediaHistoryKeyedService",
31           BrowserContextDependencyManager::GetInstance()) {
32   DependsOn(HistoryServiceFactory::GetInstance());
33 }
34 
35 MediaHistoryKeyedServiceFactory::~MediaHistoryKeyedServiceFactory() = default;
36 
ServiceIsCreatedWithBrowserContext() const37 bool MediaHistoryKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
38     const {
39   return true;
40 }
41 
BuildServiceInstanceFor(content::BrowserContext * context) const42 KeyedService* MediaHistoryKeyedServiceFactory::BuildServiceInstanceFor(
43     content::BrowserContext* context) const {
44   return new MediaHistoryKeyedService(Profile::FromBrowserContext(context));
45 }
46 
47 content::BrowserContext*
GetBrowserContextToUse(content::BrowserContext * context) const48 MediaHistoryKeyedServiceFactory::GetBrowserContextToUse(
49     content::BrowserContext* context) const {
50   // Enable incognito profiles.
51   return context;
52 }
53 
54 }  // namespace media_history
55