network_impl.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "android_webview/nonembedded/net/network_impl.h"
  5. #include <memory>
  6. #include <string>
  7. #include <utility>
  8. #include "android_webview/nonembedded/net/network_fetcher_task.h"
  9. #include "base/callback.h"
  10. #include "base/containers/flat_map.h"
  11. #include "base/notreached.h"
  12. namespace android_webview {
  13. NetworkFetcherFactoryImpl::NetworkFetcherFactoryImpl() = default;
  14. NetworkFetcherFactoryImpl::~NetworkFetcherFactoryImpl() = default;
  15. std::unique_ptr<update_client::NetworkFetcher>
  16. NetworkFetcherFactoryImpl::Create() const {
  17. return std::make_unique<NetworkFetcherImpl>();
  18. }
  19. NetworkFetcherImpl::NetworkFetcherImpl() = default;
  20. NetworkFetcherImpl::~NetworkFetcherImpl() = default;
  21. void NetworkFetcherImpl::PostRequest(
  22. const GURL& url,
  23. const std::string& post_data,
  24. const std::string& content_type,
  25. const base::flat_map<std::string, std::string>& post_additional_headers,
  26. ResponseStartedCallback response_started_callback,
  27. ProgressCallback progress_callback,
  28. PostRequestCompleteCallback post_request_complete_callback) {
  29. // A new NetworkFetcherImpl must be created for each network operation.
  30. DCHECK(!network_task_);
  31. network_task_ = NetworkFetcherTask::CreatePostRequestTask(
  32. url, post_data, content_type, post_additional_headers,
  33. std::move(response_started_callback), progress_callback,
  34. std::move(post_request_complete_callback));
  35. }
  36. void NetworkFetcherImpl::DownloadToFile(
  37. const GURL& url,
  38. const base::FilePath& file_path,
  39. ResponseStartedCallback response_started_callback,
  40. ProgressCallback progress_callback,
  41. DownloadToFileCompleteCallback download_to_file_complete_callback) {
  42. // A new NetworkFetcherImpl must be created for each network operation.
  43. DCHECK(!network_task_);
  44. network_task_ = NetworkFetcherTask::CreateDownloadToFileTask(
  45. url, file_path, std::move(response_started_callback), progress_callback,
  46. std::move(download_to_file_complete_callback));
  47. }
  48. } // namespace android_webview