crx_downloader_factory.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/update_client/crx_downloader_factory.h"
  5. #include "build/build_config.h"
  6. #if BUILDFLAG(IS_WIN)
  7. #include "components/update_client/background_downloader_win.h"
  8. #endif
  9. #include "components/update_client/crx_downloader.h"
  10. #include "components/update_client/network.h"
  11. #include "components/update_client/url_fetcher_downloader.h"
  12. namespace update_client {
  13. namespace {
  14. class CrxDownloaderFactoryChromium : public CrxDownloaderFactory {
  15. public:
  16. explicit CrxDownloaderFactoryChromium(
  17. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory)
  18. : network_fetcher_factory_(network_fetcher_factory) {}
  19. // Overrides for CrxDownloaderFactory.
  20. scoped_refptr<CrxDownloader> MakeCrxDownloader(
  21. bool background_download_enabled) const override;
  22. private:
  23. ~CrxDownloaderFactoryChromium() override = default;
  24. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory_;
  25. };
  26. scoped_refptr<CrxDownloader> CrxDownloaderFactoryChromium::MakeCrxDownloader(
  27. bool background_download_enabled) const {
  28. scoped_refptr<CrxDownloader> url_fetcher_downloader =
  29. base::MakeRefCounted<UrlFetcherDownloader>(nullptr,
  30. network_fetcher_factory_);
  31. #if BUILDFLAG(IS_WIN)
  32. // If background downloads are allowed, then apply the BITS service
  33. // background downloader first.
  34. if (background_download_enabled) {
  35. return base::MakeRefCounted<BackgroundDownloader>(url_fetcher_downloader);
  36. }
  37. #endif
  38. return url_fetcher_downloader;
  39. }
  40. } // namespace
  41. scoped_refptr<CrxDownloaderFactory> MakeCrxDownloaderFactory(
  42. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory) {
  43. return base::MakeRefCounted<CrxDownloaderFactoryChromium>(
  44. network_fetcher_factory);
  45. }
  46. } // namespace update_client