network_fetcher_task.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef ANDROID_WEBVIEW_NONEMBEDDED_NET_NETWORK_FETCHER_TASK_H_
  5. #define ANDROID_WEBVIEW_NONEMBEDDED_NET_NETWORK_FETCHER_TASK_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/containers/flat_map.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/sequence_checker.h"
  12. #include "base/task/task_traits.h"
  13. #include "base/threading/sequenced_task_runner_handle.h"
  14. #include "components/update_client/network.h"
  15. namespace base {
  16. class GURL;
  17. class FilePath;
  18. class SequencedTaskRunner;
  19. } // namespace base
  20. namespace android_webview {
  21. class NetworkFetcherTask {
  22. public:
  23. static std::unique_ptr<NetworkFetcherTask> CreateDownloadToFileTask(
  24. const GURL& url,
  25. const base::FilePath& file_path,
  26. update_client::NetworkFetcher::ResponseStartedCallback
  27. response_started_callback,
  28. update_client::NetworkFetcher::ProgressCallback progress_callback,
  29. update_client::NetworkFetcher::DownloadToFileCompleteCallback
  30. download_to_file_complete_callback);
  31. static std::unique_ptr<NetworkFetcherTask> CreatePostRequestTask(
  32. const GURL& url,
  33. const std::string& post_data,
  34. const std::string& content_type,
  35. const base::flat_map<std::string, std::string>& post_additional_headers,
  36. update_client::NetworkFetcher::ResponseStartedCallback
  37. response_started_callback,
  38. update_client::NetworkFetcher::ProgressCallback progress_callback,
  39. update_client::NetworkFetcher::PostRequestCompleteCallback
  40. post_request_complete_callback);
  41. NetworkFetcherTask(
  42. const GURL& url,
  43. const base::FilePath& file_path,
  44. update_client::NetworkFetcher::ResponseStartedCallback
  45. response_started_callback,
  46. update_client::NetworkFetcher::ProgressCallback progress_callback,
  47. update_client::NetworkFetcher::DownloadToFileCompleteCallback);
  48. NetworkFetcherTask(
  49. const GURL& url,
  50. const std::string& post_data,
  51. const std::string& content_type,
  52. const base::flat_map<std::string, std::string>& post_additional_headers,
  53. update_client::NetworkFetcher::ResponseStartedCallback
  54. response_started_callback,
  55. update_client::NetworkFetcher::ProgressCallback progress_callback,
  56. update_client::NetworkFetcher::PostRequestCompleteCallback
  57. post_request_complete_callback);
  58. ~NetworkFetcherTask();
  59. void InvokeProgressCallback(int64_t current);
  60. void InvokeResponseStartedCallback(int response_code, int64_t content_length);
  61. void InvokeDownloadToFileCompleteCallback(int network_error,
  62. int64_t content_size);
  63. void InvokePostRequestCompleteCallback(
  64. std::unique_ptr<std::string> response_body,
  65. int net_error,
  66. const std::string& header_etag,
  67. const std::string& header_x_cup_server_proof,
  68. int64_t xheader_retry_after_sec);
  69. private:
  70. SEQUENCE_CHECKER(sequence_checker_);
  71. scoped_refptr<base::SequencedTaskRunner> task_runner_ =
  72. base::SequencedTaskRunnerHandle::Get();
  73. update_client::NetworkFetcher::ResponseStartedCallback
  74. response_started_callback_;
  75. update_client::NetworkFetcher::ProgressCallback progress_callback_;
  76. update_client::NetworkFetcher::DownloadToFileCompleteCallback
  77. download_to_file_complete_callback_;
  78. update_client::NetworkFetcher::PostRequestCompleteCallback
  79. post_request_complete_callback_;
  80. base::WeakPtrFactory<NetworkFetcherTask> weak_ptr_factory_{this};
  81. };
  82. } // namespace android_webview
  83. #endif // ANDROID_WEBVIEW_NONEMBEDDED_NET_NETWORK_FETCHER_TASK_H_