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.
4
5#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
6
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/pref_registry/pref_registry_syncable.h"
13
14namespace {
15
16class Service : public KeyedService {
17 public:
18  explicit Service(Profile* profile) {
19    context_ = new ProtectedMediaIdentifierPermissionContext(profile);
20  }
21
22  ProtectedMediaIdentifierPermissionContext* context() {
23    return context_.get();
24  }
25
26  virtual void Shutdown() OVERRIDE {
27    context()->ShutdownOnUIThread();
28  }
29
30 private:
31  scoped_refptr<ProtectedMediaIdentifierPermissionContext> context_;
32
33  DISALLOW_COPY_AND_ASSIGN(Service);
34};
35
36}  // namespace
37
38// static
39ProtectedMediaIdentifierPermissionContext*
40ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
41    Profile* profile) {
42  return static_cast<Service*>(
43      GetInstance()->GetServiceForBrowserContext(profile, true))->context();
44}
45
46// static
47ProtectedMediaIdentifierPermissionContextFactory*
48ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
49  return Singleton<
50      ProtectedMediaIdentifierPermissionContextFactory>::get();
51}
52
53ProtectedMediaIdentifierPermissionContextFactory::
54ProtectedMediaIdentifierPermissionContextFactory()
55    : BrowserContextKeyedServiceFactory(
56          "ProtectedMediaIdentifierPermissionContext",
57          BrowserContextDependencyManager::GetInstance()) {
58}
59
60ProtectedMediaIdentifierPermissionContextFactory::
61~ProtectedMediaIdentifierPermissionContextFactory() {
62}
63
64KeyedService*
65ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
66    content::BrowserContext* profile) const {
67  return new Service(static_cast<Profile*>(profile));
68}
69
70void
71ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
72    user_prefs::PrefRegistrySyncable* registry) {
73  registry->RegisterBooleanPref(
74      prefs::kProtectedMediaIdentifierEnabled,
75      true,
76      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
77}
78
79content::BrowserContext*
80ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
81    content::BrowserContext* context) const {
82  return chrome::GetBrowserContextOwnInstanceInIncognito(context);
83}
84