network_impl.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 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_NET_NETWORK_IMPL_H_
  5. #define COMPONENTS_UPDATE_CLIENT_NET_NETWORK_IMPL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include "base/memory/ref_counted.h"
  10. #include "components/update_client/net/network_chromium.h"
  11. #include "components/update_client/network.h"
  12. #include "services/network/public/mojom/url_response_head.mojom-forward.h"
  13. namespace network {
  14. class SharedURLLoaderFactory;
  15. class SimpleURLLoader;
  16. } // namespace network
  17. namespace update_client {
  18. class NetworkFetcherImpl : public NetworkFetcher {
  19. public:
  20. explicit NetworkFetcherImpl(
  21. scoped_refptr<network::SharedURLLoaderFactory> shared_url_network_factory,
  22. SendCookiesPredicate cookie_predicate);
  23. NetworkFetcherImpl(const NetworkFetcherImpl&) = delete;
  24. NetworkFetcherImpl& operator=(const NetworkFetcherImpl&) = delete;
  25. ~NetworkFetcherImpl() override;
  26. // NetworkFetcher overrides.
  27. void PostRequest(
  28. const GURL& url,
  29. const std::string& post_data,
  30. const std::string& content_type,
  31. const base::flat_map<std::string, std::string>& post_additional_headers,
  32. ResponseStartedCallback response_started_callback,
  33. ProgressCallback progress_callback,
  34. PostRequestCompleteCallback post_request_complete_callback) override;
  35. void DownloadToFile(const GURL& url,
  36. const base::FilePath& file_path,
  37. ResponseStartedCallback response_started_callback,
  38. ProgressCallback progress_callback,
  39. DownloadToFileCompleteCallback
  40. download_to_file_complete_callback) override;
  41. private:
  42. void OnResponseStartedCallback(
  43. ResponseStartedCallback response_started_callback,
  44. const GURL& final_url,
  45. const network::mojom::URLResponseHead& response_head);
  46. void OnProgressCallback(ProgressCallback response_started_callback,
  47. uint64_t current);
  48. static constexpr int kMaxRetriesOnNetworkChange = 3;
  49. scoped_refptr<network::SharedURLLoaderFactory> shared_url_network_factory_;
  50. std::unique_ptr<network::SimpleURLLoader> simple_url_loader_;
  51. SendCookiesPredicate cookie_predicate_;
  52. };
  53. } // namespace update_client
  54. #endif // COMPONENTS_UPDATE_CLIENT_NET_NETWORK_IMPL_H_