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/media/router/media_router_factory.h"
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"
11 #include "chrome/browser/media/router/media_router_mojo_impl.h"
12 #include "extensions/browser/process_manager.h"
13 #include "extensions/browser/process_manager_factory.h"
16 using content::BrowserContext
;
18 namespace media_router
{
22 base::LazyInstance
<MediaRouterFactory
> service_factory
=
23 LAZY_INSTANCE_INITIALIZER
;
28 MediaRouter
* MediaRouterFactory::GetApiForBrowserContext(
29 BrowserContext
* context
) {
31 // GetServiceForBrowserContext returns a KeyedService hence the static_cast<>
32 // to return a pointer to MediaRouter.
33 return static_cast<MediaRouter
*>(
34 service_factory
.Get().GetServiceForBrowserContext(context
, true));
37 MediaRouterFactory::MediaRouterFactory()
38 : BrowserContextKeyedServiceFactory(
40 BrowserContextDependencyManager::GetInstance()) {
41 #if !defined(OS_ANDROID)
42 // On desktop platforms, MediaRouter depends on ProcessManager.
43 DependsOn(extensions::ProcessManagerFactory::GetInstance());
47 MediaRouterFactory::~MediaRouterFactory() {
50 KeyedService
* MediaRouterFactory::BuildServiceInstanceFor(
51 BrowserContext
* context
) const {
52 #if defined(OS_ANDROID)
53 return new MediaRouterAndroid(context
);
55 return new MediaRouterMojoImpl(extensions::ProcessManager::Get(context
));
59 BrowserContext
* MediaRouterFactory::GetBrowserContextToUse(
60 BrowserContext
* context
) const {
61 // Always use the input context. This means that an incognito context will
62 // have its own MediaRouter service, rather than sharing it with its
63 // original non-incognito context.
67 } // namespace media_router