OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/router/media_router_mojo_impl_factory.h" | 5 #include "chrome/browser/media/router/media_router_factory.h" |
6 | 6 |
| 7 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 8 #if defined(OS_ANDROID) |
| 9 #include "chrome/browser/media/android/router/media_router_android.h" |
| 10 #else |
7 #include "chrome/browser/media/router/media_router_mojo_impl.h" | 11 #include "chrome/browser/media/router/media_router_mojo_impl.h" |
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" | |
9 #include "extensions/browser/process_manager.h" | 12 #include "extensions/browser/process_manager.h" |
10 #include "extensions/browser/process_manager_factory.h" | 13 #include "extensions/browser/process_manager_factory.h" |
| 14 #endif |
11 | 15 |
12 using content::BrowserContext; | 16 using content::BrowserContext; |
13 | 17 |
14 namespace media_router { | 18 namespace media_router { |
15 | 19 |
16 namespace { | 20 namespace { |
17 | 21 |
18 base::LazyInstance<MediaRouterMojoImplFactory> service_factory = | 22 base::LazyInstance<MediaRouterFactory> service_factory = |
19 LAZY_INSTANCE_INITIALIZER; | 23 LAZY_INSTANCE_INITIALIZER; |
20 | 24 |
21 } // namespace | 25 } // namespace |
22 | 26 |
23 // static | 27 // static |
24 MediaRouterMojoImpl* MediaRouterMojoImplFactory::GetApiForBrowserContext( | 28 MediaRouter* MediaRouterFactory::GetApiForBrowserContext( |
25 BrowserContext* context) { | 29 BrowserContext* context) { |
26 DCHECK(context); | 30 DCHECK(context); |
27 | 31 // GetServiceForBrowserContext returns a KeyedService hence the static_cast<> |
28 return static_cast<MediaRouterMojoImpl*>( | 32 // to return a pointer to MediaRouter. |
| 33 return static_cast<MediaRouter*>( |
29 service_factory.Get().GetServiceForBrowserContext(context, true)); | 34 service_factory.Get().GetServiceForBrowserContext(context, true)); |
30 } | 35 } |
31 | 36 |
32 MediaRouterMojoImplFactory::MediaRouterMojoImplFactory() | 37 MediaRouterFactory::MediaRouterFactory() |
33 : BrowserContextKeyedServiceFactory( | 38 : BrowserContextKeyedServiceFactory( |
34 "MediaRouterMojoImpl", | 39 "MediaRouter", |
35 BrowserContextDependencyManager::GetInstance()) { | 40 BrowserContextDependencyManager::GetInstance()) { |
36 // MediaRouterMojoImpl depends on ProcessManager. | 41 #if !defined(OS_ANDROID) |
| 42 // On desktop platforms, MediaRouter depends on ProcessManager. |
37 DependsOn(extensions::ProcessManagerFactory::GetInstance()); | 43 DependsOn(extensions::ProcessManagerFactory::GetInstance()); |
| 44 #endif |
38 } | 45 } |
39 | 46 |
40 MediaRouterMojoImplFactory::~MediaRouterMojoImplFactory() { | 47 MediaRouterFactory::~MediaRouterFactory() { |
41 } | 48 } |
42 | 49 |
43 KeyedService* MediaRouterMojoImplFactory::BuildServiceInstanceFor( | 50 KeyedService* MediaRouterFactory::BuildServiceInstanceFor( |
44 BrowserContext* context) const { | 51 BrowserContext* context) const { |
| 52 #if defined(OS_ANDROID) |
| 53 return new MediaRouterAndroid(context); |
| 54 #else |
45 return new MediaRouterMojoImpl(extensions::ProcessManager::Get(context)); | 55 return new MediaRouterMojoImpl(extensions::ProcessManager::Get(context)); |
| 56 #endif |
46 } | 57 } |
47 | 58 |
48 BrowserContext* MediaRouterMojoImplFactory::GetBrowserContextToUse( | 59 BrowserContext* MediaRouterFactory::GetBrowserContextToUse( |
49 BrowserContext* context) const { | 60 BrowserContext* context) const { |
50 // Always use the input context. This means that an incognito context will | 61 // Always use the input context. This means that an incognito context will |
51 // have its own MediaRouterMojoImpl service, rather than sharing it with its | 62 // have its own MediaRouter service, rather than sharing it with its |
52 // original non-incognito context. | 63 // original non-incognito context. |
53 return context; | 64 return context; |
54 } | 65 } |
55 | 66 |
56 } // namespace media_router | 67 } // namespace media_router |
OLD | NEW |