1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/background_task_scheduler/background_task_scheduler_factory.h"
9 #include "base/memory/singleton.h"
10 #include "build/build_config.h"
11 #include "components/background_task_scheduler/background_task_scheduler.h"
12 #include "components/keyed_service/core/simple_dependency_manager.h"
14 #if BUILDFLAG(IS_ANDROID)
15 #include "components/background_task_scheduler/internal/android/native_task_scheduler.h"
18 namespace background_task {
21 BackgroundTaskSchedulerFactory* BackgroundTaskSchedulerFactory::GetInstance() {
22 return base::Singleton<BackgroundTaskSchedulerFactory>::get();
26 BackgroundTaskScheduler* BackgroundTaskSchedulerFactory::GetForKey(
27 SimpleFactoryKey* key) {
28 return static_cast<BackgroundTaskScheduler*>(
29 GetInstance()->GetServiceForKey(key, true));
32 BackgroundTaskSchedulerFactory::BackgroundTaskSchedulerFactory()
33 : SimpleKeyedServiceFactory("BackgroundTaskScheduler",
34 SimpleDependencyManager::GetInstance()) {}
36 BackgroundTaskSchedulerFactory::~BackgroundTaskSchedulerFactory() = default;
38 std::unique_ptr<KeyedService>
39 BackgroundTaskSchedulerFactory::BuildServiceInstanceFor(
40 SimpleFactoryKey* key) const {
41 #if BUILDFLAG(IS_ANDROID)
42 return std::make_unique<NativeTaskScheduler>();
48 SimpleFactoryKey* BackgroundTaskSchedulerFactory::GetKeyToUse(
49 SimpleFactoryKey* key) const {
53 } // namespace background_task