background_fetch_delegate_factory.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2021 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 "weblayer/browser/background_fetch/background_fetch_delegate_factory.h"
  5. #include "base/strings/string_number_conversions.h"
  6. #include "build/build_config.h"
  7. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  8. #include "content/public/browser/background_fetch_delegate.h"
  9. #include "weblayer/browser/background_download_service_factory.h"
  10. #include "weblayer/browser/background_fetch/background_fetch_delegate_impl.h"
  11. #include "weblayer/browser/host_content_settings_map_factory.h"
  12. #if BUILDFLAG(IS_ANDROID)
  13. #include "weblayer/browser/android/application_info_helper.h"
  14. #endif
  15. namespace weblayer {
  16. // static
  17. BackgroundFetchDelegateImpl*
  18. BackgroundFetchDelegateFactory::GetForBrowserContext(
  19. content::BrowserContext* context) {
  20. return static_cast<BackgroundFetchDelegateImpl*>(
  21. GetInstance()->GetServiceForBrowserContext(context, true));
  22. }
  23. // static
  24. BackgroundFetchDelegateFactory* BackgroundFetchDelegateFactory::GetInstance() {
  25. return base::Singleton<BackgroundFetchDelegateFactory>::get();
  26. }
  27. BackgroundFetchDelegateFactory::BackgroundFetchDelegateFactory()
  28. : BrowserContextKeyedServiceFactory(
  29. "BackgroundFetchService",
  30. BrowserContextDependencyManager::GetInstance()) {
  31. DependsOn(BackgroundDownloadServiceFactory::GetInstance());
  32. DependsOn(HostContentSettingsMapFactory::GetInstance());
  33. }
  34. BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() = default;
  35. KeyedService* BackgroundFetchDelegateFactory::BuildServiceInstanceFor(
  36. content::BrowserContext* context) const {
  37. return new BackgroundFetchDelegateImpl(context);
  38. }
  39. content::BrowserContext* BackgroundFetchDelegateFactory::GetBrowserContextToUse(
  40. content::BrowserContext* context) const {
  41. return context;
  42. }
  43. } // namespace weblayer