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/browser_context_keyed_service/browser_context_dependency_manager.h"
12 #include "components/user_prefs/pref_registry_syncable.h"
16 class Service
: public BrowserContextKeyedService
{
18 explicit Service(Profile
* profile
) {
19 context_
= new ProtectedMediaIdentifierPermissionContext(profile
);
22 ProtectedMediaIdentifierPermissionContext
* context() {
23 return context_
.get();
26 virtual void Shutdown() OVERRIDE
{
27 context()->ShutdownOnUIThread();
31 scoped_refptr
<ProtectedMediaIdentifierPermissionContext
> context_
;
33 DISALLOW_COPY_AND_ASSIGN(Service
);
39 ProtectedMediaIdentifierPermissionContext
*
40 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
42 return static_cast<Service
*>(
43 GetInstance()->GetServiceForBrowserContext(profile
, true))->context();
47 ProtectedMediaIdentifierPermissionContextFactory
*
48 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
50 ProtectedMediaIdentifierPermissionContextFactory
>::get();
53 ProtectedMediaIdentifierPermissionContextFactory::
54 ProtectedMediaIdentifierPermissionContextFactory()
55 : BrowserContextKeyedServiceFactory(
56 "ProtectedMediaIdentifierPermissionContext",
57 BrowserContextDependencyManager::GetInstance()) {
60 ProtectedMediaIdentifierPermissionContextFactory::
61 ~ProtectedMediaIdentifierPermissionContextFactory() {
64 BrowserContextKeyedService
*
65 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
66 content::BrowserContext
* profile
) const {
67 return new Service(static_cast<Profile
*>(profile
));
71 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
72 user_prefs::PrefRegistrySyncable
* registry
) {
73 registry
->RegisterBooleanPref(
74 prefs::kProtectedMediaIdentifierEnabled
,
76 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
79 content::BrowserContext
*
80 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
81 content::BrowserContext
* context
) const {
82 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);