Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / permissions / permission_context.cc
blob17b98da6e57ff52e87eff7f4083130ad1c1e1a4b
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/notification_permission_context.h"
12 #include "chrome/browser/notifications/notification_permission_context_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 "chrome/browser/storage/durable_storage_permission_context.h"
17 #include "chrome/browser/storage/durable_storage_permission_context_factory.h"
18 #include "content/public/browser/permission_type.h"
20 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
21 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
22 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
23 #endif
25 using content::PermissionType;
27 // static
28 PermissionContextBase* PermissionContext::Get(Profile* profile,
29 PermissionType permission_type) {
30 // NOTE: the factories used in this method have to stay in sync with
31 // ::GetFactories() below.
32 switch (permission_type) {
33 case PermissionType::GEOLOCATION:
34 return GeolocationPermissionContextFactory::GetForProfile(profile);
35 case PermissionType::MIDI_SYSEX:
36 return MidiPermissionContextFactory::GetForProfile(profile);
37 case PermissionType::NOTIFICATIONS:
38 return NotificationPermissionContextFactory::GetForProfile(profile);
39 case PermissionType::PUSH_MESSAGING:
40 return PushMessagingPermissionContextFactory::GetForProfile(profile);
41 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
42 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
43 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
44 profile);
45 #endif
46 case content::PermissionType::DURABLE_STORAGE:
47 return DurableStoragePermissionContextFactory::GetForProfile(profile);
48 case PermissionType::MIDI:
49 // PermissionType::MIDI is a valid permission but does not have a
50 // permission context. It has a constant value instead.
51 break;
52 default:
53 NOTREACHED() << "No PermissionContext associated with "
54 << static_cast<int>(permission_type);
55 break;
58 return nullptr;
61 // static
62 const std::list<KeyedServiceBaseFactory*>& PermissionContext::GetFactories() {
63 // NOTE: this list has to stay in sync with the factories used by ::Get().
64 CR_DEFINE_STATIC_LOCAL(std::list<KeyedServiceBaseFactory*>, factories, ());
66 if (factories.empty()) {
67 factories.push_back(GeolocationPermissionContextFactory::GetInstance());
68 factories.push_back(MidiPermissionContextFactory::GetInstance());
69 factories.push_back(NotificationPermissionContextFactory::GetInstance());
70 factories.push_back(PushMessagingPermissionContextFactory::GetInstance());
71 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
72 factories.push_back(
73 ProtectedMediaIdentifierPermissionContextFactory::GetInstance());
74 #endif
75 factories.push_back(DurableStoragePermissionContextFactory::GetInstance());
78 return factories;