Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media / protected_media_identifier_permission_context_factory.cc
blobb4a2f47065c3bda572807bfd967a4db3d7dbd669
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"
14 namespace {
16 class Service : public BrowserContextKeyedService {
17 public:
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();
30 private:
31 scoped_refptr<ProtectedMediaIdentifierPermissionContext> context_;
33 DISALLOW_COPY_AND_ASSIGN(Service);
36 } // namespace
38 // static
39 ProtectedMediaIdentifierPermissionContext*
40 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
41 Profile* profile) {
42 return static_cast<Service*>(
43 GetInstance()->GetServiceForBrowserContext(profile, true))->context();
46 // static
47 ProtectedMediaIdentifierPermissionContextFactory*
48 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
49 return Singleton<
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));
70 void
71 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
72 user_prefs::PrefRegistrySyncable* registry) {
73 registry->RegisterBooleanPref(
74 prefs::kProtectedMediaIdentifierEnabled,
75 true,
76 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
79 content::BrowserContext*
80 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
81 content::BrowserContext* context) const {
82 return chrome::GetBrowserContextOwnInstanceInIncognito(context);