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/chrome_midi_permission_context_factory.h" | 5 #include "chrome/browser/media/chrome_midi_permission_context_factory.h" |
6 | 6 |
7 #include "chrome/browser/media/chrome_midi_permission_context.h" | 7 #include "chrome/browser/media/chrome_midi_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 "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 10 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
11 | 11 |
| 12 namespace { |
| 13 |
| 14 class Service : public BrowserContextKeyedService { |
| 15 public: |
| 16 explicit Service(Profile* profile) { |
| 17 context_ = new ChromeMIDIPermissionContext(profile); |
| 18 } |
| 19 |
| 20 ChromeMIDIPermissionContext* context() { |
| 21 return context_.get(); |
| 22 } |
| 23 |
| 24 virtual void Shutdown() OVERRIDE { |
| 25 context()->ShutdownOnUIThread(); |
| 26 } |
| 27 |
| 28 private: |
| 29 scoped_refptr<ChromeMIDIPermissionContext> context_; |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(Service); |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
12 // static | 36 // static |
13 ChromeMIDIPermissionContext* | 37 ChromeMIDIPermissionContext* |
14 ChromeMIDIPermissionContextFactory::GetForProfile(Profile* profile) { | 38 ChromeMIDIPermissionContextFactory::GetForProfile(Profile* profile) { |
15 return static_cast<ChromeMIDIPermissionContext*>( | 39 return static_cast<Service*>( |
16 GetInstance()->GetServiceForBrowserContext(profile, true)); | 40 GetInstance()->GetServiceForBrowserContext(profile, true))->context(); |
17 } | 41 } |
18 | 42 |
19 // static | 43 // static |
20 ChromeMIDIPermissionContextFactory* | 44 ChromeMIDIPermissionContextFactory* |
21 ChromeMIDIPermissionContextFactory::GetInstance() { | 45 ChromeMIDIPermissionContextFactory::GetInstance() { |
22 return Singleton<ChromeMIDIPermissionContextFactory>::get(); | 46 return Singleton<ChromeMIDIPermissionContextFactory>::get(); |
23 } | 47 } |
24 | 48 |
25 ChromeMIDIPermissionContextFactory:: | 49 ChromeMIDIPermissionContextFactory:: |
26 ChromeMIDIPermissionContextFactory() | 50 ChromeMIDIPermissionContextFactory() |
27 : BrowserContextKeyedServiceFactory( | 51 : BrowserContextKeyedServiceFactory( |
28 "ChromeMIDIPermissionContext", | 52 "ChromeMIDIPermissionContext", |
29 BrowserContextDependencyManager::GetInstance()) { | 53 BrowserContextDependencyManager::GetInstance()) { |
30 } | 54 } |
31 | 55 |
32 ChromeMIDIPermissionContextFactory:: | 56 ChromeMIDIPermissionContextFactory:: |
33 ~ChromeMIDIPermissionContextFactory() { | 57 ~ChromeMIDIPermissionContextFactory() { |
34 } | 58 } |
35 | 59 |
36 BrowserContextKeyedService* | 60 BrowserContextKeyedService* |
37 ChromeMIDIPermissionContextFactory::BuildServiceInstanceFor( | 61 ChromeMIDIPermissionContextFactory::BuildServiceInstanceFor( |
38 content::BrowserContext* profile) const { | 62 content::BrowserContext* profile) const { |
39 return new ChromeMIDIPermissionContext(static_cast<Profile*>(profile)); | 63 return new Service(static_cast<Profile*>(profile)); |
40 } | 64 } |
41 | 65 |
42 content::BrowserContext* | 66 content::BrowserContext* |
43 ChromeMIDIPermissionContextFactory::GetBrowserContextToUse( | 67 ChromeMIDIPermissionContextFactory::GetBrowserContextToUse( |
44 content::BrowserContext* context) const { | 68 content::BrowserContext* context) const { |
45 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 69 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
46 } | 70 } |
OLD | NEW |