| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/protected_media_identifier_permission_context_fac
tory.h" | 5 #include "chrome/browser/media/protected_media_identifier_permission_context_fac
tory.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media/protected_media_identifier_permission_context.h" | 7 #include "chrome/browser/media/protected_media_identifier_permission_context.h" |
| 8 #include "chrome/browser/profiles/incognito_helpers.h" | 8 #include "chrome/browser/profiles/incognito_helpers.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/keyed_service/content/browser_context_dependency_manager.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" | 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 14 | 13 |
| 15 namespace { | |
| 16 | |
| 17 class Service : public KeyedService { | |
| 18 public: | |
| 19 explicit Service(Profile* profile) { | |
| 20 context_ = new ProtectedMediaIdentifierPermissionContext(profile); | |
| 21 } | |
| 22 | |
| 23 ProtectedMediaIdentifierPermissionContext* context() { | |
| 24 return context_.get(); | |
| 25 } | |
| 26 | |
| 27 virtual void Shutdown() override { | |
| 28 context()->ShutdownOnUIThread(); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 scoped_refptr<ProtectedMediaIdentifierPermissionContext> context_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(Service); | |
| 35 }; | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 // static | 14 // static |
| 40 ProtectedMediaIdentifierPermissionContext* | 15 ProtectedMediaIdentifierPermissionContext* |
| 41 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile( | 16 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile( |
| 42 Profile* profile) { | 17 Profile* profile) { |
| 43 return static_cast<Service*>( | 18 return static_cast<ProtectedMediaIdentifierPermissionContext*>( |
| 44 GetInstance()->GetServiceForBrowserContext(profile, true))->context(); | 19 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 45 } | 20 } |
| 46 | 21 |
| 47 // static | 22 // static |
| 48 ProtectedMediaIdentifierPermissionContextFactory* | 23 ProtectedMediaIdentifierPermissionContextFactory* |
| 49 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() { | 24 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() { |
| 50 return Singleton< | 25 return Singleton< |
| 51 ProtectedMediaIdentifierPermissionContextFactory>::get(); | 26 ProtectedMediaIdentifierPermissionContextFactory>::get(); |
| 52 } | 27 } |
| 53 | 28 |
| 54 ProtectedMediaIdentifierPermissionContextFactory:: | 29 ProtectedMediaIdentifierPermissionContextFactory:: |
| 55 ProtectedMediaIdentifierPermissionContextFactory() | 30 ProtectedMediaIdentifierPermissionContextFactory() |
| 56 : BrowserContextKeyedServiceFactory( | 31 : BrowserContextKeyedServiceFactory( |
| 57 "ProtectedMediaIdentifierPermissionContext", | 32 "ProtectedMediaIdentifierPermissionContext", |
| 58 BrowserContextDependencyManager::GetInstance()) { | 33 BrowserContextDependencyManager::GetInstance()) { |
| 59 } | 34 } |
| 60 | 35 |
| 61 ProtectedMediaIdentifierPermissionContextFactory:: | 36 ProtectedMediaIdentifierPermissionContextFactory:: |
| 62 ~ProtectedMediaIdentifierPermissionContextFactory() { | 37 ~ProtectedMediaIdentifierPermissionContextFactory() { |
| 63 } | 38 } |
| 64 | 39 |
| 65 KeyedService* | 40 KeyedService* |
| 66 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor( | 41 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor( |
| 67 content::BrowserContext* profile) const { | 42 content::BrowserContext* profile) const { |
| 68 return new Service(static_cast<Profile*>(profile)); | 43 return new ProtectedMediaIdentifierPermissionContext( |
| 44 static_cast<Profile*>(profile)); |
| 69 } | 45 } |
| 70 | 46 |
| 71 void | 47 void |
| 72 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs( | 48 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs( |
| 73 user_prefs::PrefRegistrySyncable* registry) { | 49 user_prefs::PrefRegistrySyncable* registry) { |
| 74 registry->RegisterBooleanPref( | 50 registry->RegisterBooleanPref( |
| 75 prefs::kProtectedMediaIdentifierEnabled, | 51 prefs::kProtectedMediaIdentifierEnabled, |
| 76 true, | 52 true, |
| 77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 53 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 78 } | 54 } |
| 79 | 55 |
| 80 content::BrowserContext* | 56 content::BrowserContext* |
| 81 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse( | 57 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse( |
| 82 content::BrowserContext* context) const { | 58 content::BrowserContext* context) const { |
| 83 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 59 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 84 } | 60 } |
| OLD | NEW |