• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 namespace {
15 
16 class Service : public KeyedService {
17  public:
Service(Profile * profile)18   explicit Service(Profile* profile) {
19     context_ = new ProtectedMediaIdentifierPermissionContext(profile);
20   }
21 
context()22   ProtectedMediaIdentifierPermissionContext* context() {
23     return context_.get();
24   }
25 
Shutdown()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
39 ProtectedMediaIdentifierPermissionContext*
GetForProfile(Profile * profile)40 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
41     Profile* profile) {
42   return static_cast<Service*>(
43       GetInstance()->GetServiceForBrowserContext(profile, true))->context();
44 }
45 
46 // static
47 ProtectedMediaIdentifierPermissionContextFactory*
GetInstance()48 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
49   return Singleton<
50       ProtectedMediaIdentifierPermissionContextFactory>::get();
51 }
52 
53 ProtectedMediaIdentifierPermissionContextFactory::
ProtectedMediaIdentifierPermissionContextFactory()54 ProtectedMediaIdentifierPermissionContextFactory()
55     : BrowserContextKeyedServiceFactory(
56           "ProtectedMediaIdentifierPermissionContext",
57           BrowserContextDependencyManager::GetInstance()) {
58 }
59 
60 ProtectedMediaIdentifierPermissionContextFactory::
~ProtectedMediaIdentifierPermissionContextFactory()61 ~ProtectedMediaIdentifierPermissionContextFactory() {
62 }
63 
64 KeyedService*
BuildServiceInstanceFor(content::BrowserContext * profile) const65 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
66     content::BrowserContext* profile) const {
67   return new Service(static_cast<Profile*>(profile));
68 }
69 
70 void
RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)71 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
72     user_prefs::PrefRegistrySyncable* registry) {
73   registry->RegisterBooleanPref(
74       prefs::kProtectedMediaIdentifierEnabled,
75       true,
76       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
77 }
78 
79 content::BrowserContext*
GetBrowserContextToUse(content::BrowserContext * context) const80 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
81     content::BrowserContext* context) const {
82   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
83 }
84