url_fetcher_downloader.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 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. #ifndef COMPONENTS_UPDATE_CLIENT_URL_FETCHER_DOWNLOADER_H_
  5. #define COMPONENTS_UPDATE_CLIENT_URL_FETCHER_DOWNLOADER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/files/file_path.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "base/sequence_checker.h"
  11. #include "base/time/time.h"
  12. #include "components/update_client/crx_downloader.h"
  13. namespace update_client {
  14. class NetworkFetcher;
  15. class NetworkFetcherFactory;
  16. // Implements a CRX downloader using a NetworkFetcher object.
  17. class UrlFetcherDownloader : public CrxDownloader {
  18. public:
  19. UrlFetcherDownloader(
  20. scoped_refptr<CrxDownloader> successor,
  21. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory);
  22. UrlFetcherDownloader(const UrlFetcherDownloader&) = delete;
  23. UrlFetcherDownloader& operator=(const UrlFetcherDownloader&) = delete;
  24. private:
  25. // Overrides for CrxDownloader.
  26. ~UrlFetcherDownloader() override;
  27. void DoStartDownload(const GURL& url) override;
  28. void CreateDownloadDir();
  29. void StartURLFetch(const GURL& url);
  30. void OnNetworkFetcherComplete(int net_error, int64_t content_size);
  31. void OnResponseStarted(int response_code, int64_t content_length);
  32. void OnDownloadProgress(int64_t content_length);
  33. SEQUENCE_CHECKER(sequence_checker_);
  34. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory_;
  35. std::unique_ptr<NetworkFetcher> network_fetcher_;
  36. // Contains a temporary download directory for the downloaded file.
  37. base::FilePath download_dir_;
  38. // Contains the file path to the downloaded file.
  39. base::FilePath file_path_;
  40. base::TimeTicks download_start_time_;
  41. int response_code_ = -1;
  42. int64_t total_bytes_ = -1;
  43. };
  44. } // namespace update_client
  45. #endif // COMPONENTS_UPDATE_CLIENT_URL_FETCHER_DOWNLOADER_H_