1 // Copyright 2015 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/permissions/permission_context.h"
7 #include "chrome/browser/geolocation/geolocation_permission_context.h"
8 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
9 #include "chrome/browser/media/midi_permission_context.h"
10 #include "chrome/browser/media/midi_permission_context_factory.h"
11 #include "chrome/browser/notifications/desktop_notification_service.h"
12 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/push_messaging/push_messaging_permission_context.h"
15 #include "chrome/browser/push_messaging/push_messaging_permission_context_factory.h"
16 #include "content/public/browser/permission_type.h"
18 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
19 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
20 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
24 PermissionContextBase
* PermissionContext::Get(
26 content::PermissionType permission_type
) {
27 // NOTE: the factories used in this method have to stay in sync with
28 // ::GetFactories() below.
29 switch (permission_type
) {
30 case content::PermissionType::GEOLOCATION
:
31 return GeolocationPermissionContextFactory::GetForProfile(profile
);
32 case content::PermissionType::NOTIFICATIONS
:
33 return DesktopNotificationServiceFactory::GetForProfile(profile
);
34 case content::PermissionType::MIDI_SYSEX
:
35 return MidiPermissionContextFactory::GetForProfile(profile
);
36 case content::PermissionType::PUSH_MESSAGING
:
37 return PushMessagingPermissionContextFactory::GetForProfile(profile
);
38 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
39 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER
:
40 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
44 NOTREACHED() << "No PermissionContext associated with "
45 << static_cast<int>(permission_type
);
53 const std::list
<KeyedServiceBaseFactory
*>& PermissionContext::GetFactories() {
54 // NOTE: this list has to stay in sync with the factories used by ::Get().
55 CR_DEFINE_STATIC_LOCAL(std::list
<KeyedServiceBaseFactory
*>, factories
, ());
57 if (factories
.empty()) {
58 factories
.push_back(GeolocationPermissionContextFactory::GetInstance());
59 factories
.push_back(DesktopNotificationServiceFactory::GetInstance());
60 factories
.push_back(MidiPermissionContextFactory::GetInstance());
61 factories
.push_back(PushMessagingPermissionContextFactory::GetInstance());
62 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
64 ProtectedMediaIdentifierPermissionContextFactory::GetInstance());