Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / protected_media_identifier_permission_context_factory.cc
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/keyed_service/core/keyed_service.h"
13 #include "components/pref_registry/pref_registry_syncable.h"
14
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
40 ProtectedMediaIdentifierPermissionContext*
41 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
42     Profile* profile) {
43   return static_cast<Service*>(
44       GetInstance()->GetServiceForBrowserContext(profile, true))->context();
45 }
46
47 // static
48 ProtectedMediaIdentifierPermissionContextFactory*
49 ProtectedMediaIdentifierPermissionContextFactory::GetInstance() {
50   return Singleton<
51       ProtectedMediaIdentifierPermissionContextFactory>::get();
52 }
53
54 ProtectedMediaIdentifierPermissionContextFactory::
55 ProtectedMediaIdentifierPermissionContextFactory()
56     : BrowserContextKeyedServiceFactory(
57           "ProtectedMediaIdentifierPermissionContext",
58           BrowserContextDependencyManager::GetInstance()) {
59 }
60
61 ProtectedMediaIdentifierPermissionContextFactory::
62 ~ProtectedMediaIdentifierPermissionContextFactory() {
63 }
64
65 KeyedService*
66 ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
67     content::BrowserContext* profile) const {
68   return new Service(static_cast<Profile*>(profile));
69 }
70
71 void
72 ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
73     user_prefs::PrefRegistrySyncable* registry) {
74   registry->RegisterBooleanPref(
75       prefs::kProtectedMediaIdentifierEnabled,
76       true,
77       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
78 }
79
80 content::BrowserContext*
81 ProtectedMediaIdentifierPermissionContextFactory::GetBrowserContextToUse(
82     content::BrowserContext* context) const {
83   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
84 }