background_task_scheduler_factory.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2020 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.
  4. #include "components/background_task_scheduler/background_task_scheduler_factory.h"
  5. #include <memory>
  6. #include "base/memory/singleton.h"
  7. #include "build/build_config.h"
  8. #include "components/background_task_scheduler/background_task_scheduler.h"
  9. #include "components/keyed_service/core/simple_dependency_manager.h"
  10. #if BUILDFLAG(IS_ANDROID)
  11. #include "components/background_task_scheduler/internal/android/native_task_scheduler.h"
  12. #endif
  13. namespace background_task {
  14. // static
  15. BackgroundTaskSchedulerFactory* BackgroundTaskSchedulerFactory::GetInstance() {
  16. return base::Singleton<BackgroundTaskSchedulerFactory>::get();
  17. }
  18. // static
  19. BackgroundTaskScheduler* BackgroundTaskSchedulerFactory::GetForKey(
  20. SimpleFactoryKey* key) {
  21. return static_cast<BackgroundTaskScheduler*>(
  22. GetInstance()->GetServiceForKey(key, true));
  23. }
  24. BackgroundTaskSchedulerFactory::BackgroundTaskSchedulerFactory()
  25. : SimpleKeyedServiceFactory("BackgroundTaskScheduler",
  26. SimpleDependencyManager::GetInstance()) {}
  27. BackgroundTaskSchedulerFactory::~BackgroundTaskSchedulerFactory() = default;
  28. std::unique_ptr<KeyedService>
  29. BackgroundTaskSchedulerFactory::BuildServiceInstanceFor(
  30. SimpleFactoryKey* key) const {
  31. #if BUILDFLAG(IS_ANDROID)
  32. return std::make_unique<NativeTaskScheduler>();
  33. #else
  34. return nullptr;
  35. #endif
  36. }
  37. SimpleFactoryKey* BackgroundTaskSchedulerFactory::GetKeyToUse(
  38. SimpleFactoryKey* key) const {
  39. return key;
  40. }
  41. } // namespace background_task