1 // Copyright 2013 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.
5 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
7 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/pref_registry/pref_registry_syncable.h"
17 class Service
: public KeyedService
{
19 explicit Service(Profile
* profile
) {
20 context_
= new ProtectedMediaIdentifierPermissionContext(profile
);
23 ProtectedMediaIdentifierPermissionContext
* context() {
24 return context_
.get();
27 virtual void Shutdown() override
{
28 context()->ShutdownOnUIThread();
32 scoped_refptr
<ProtectedMediaIdentifierPermissionContext
> context_
;
34 DISALLOW_COPY_AND_ASSIGN(Service
);
40 ProtectedMediaIdentifierPermissionContext
*
41 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
43 return static_cast<Service
*>(
44 GetInstance()->GetServiceForBrowserContext(profile
, true))->context();
48 ProtectedMediaIdentifierPermissionContextFactory
*
49 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
51 ProtectedMediaIdentifierPermissionContextFactory
>::get();
54 ProtectedMediaIdentifierPermissionContextFactory::
55 ProtectedMediaIdentifierPermissionContextFactory()
56 : BrowserContextKeyedServiceFactory(
57 "ProtectedMediaIdentifierPermissionContext",
58 BrowserContextDependencyManager::GetInstance()) {
61 ProtectedMediaIdentifierPermissionContextFactory::
62 ~ProtectedMediaIdentifierPermissionContextFactory() {
66 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
67 content::BrowserContext
* profile
) const {
68 return new Service(static_cast<Profile
*>(profile
));
72 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
73 user_prefs::PrefRegistrySyncable
* registry
) {
74 registry
->RegisterBooleanPref(
75 prefs::kProtectedMediaIdentifierEnabled
,
77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
80 content::BrowserContext
*
81 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
82 content::BrowserContext
* context
) const {
83 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);