chromium_url_request.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2016 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 REMOTING_BASE_CHROMIUM_URL_REQUEST_H_
  5. #define REMOTING_BASE_CHROMIUM_URL_REQUEST_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "net/traffic_annotation/network_traffic_annotation.h"
  10. #include "remoting/base/url_request.h"
  11. namespace network {
  12. class SharedURLLoaderFactory;
  13. class SimpleURLLoader;
  14. struct ResourceRequest;
  15. } // namespace network
  16. namespace remoting {
  17. // UrlRequest implementation based on network::SimpleURLLoader.
  18. class ChromiumUrlRequest : public UrlRequest {
  19. public:
  20. ChromiumUrlRequest(
  21. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  22. UrlRequest::Type type,
  23. const std::string& url,
  24. const net::NetworkTrafficAnnotationTag& traffic_annotation);
  25. ~ChromiumUrlRequest() override;
  26. // UrlRequest interface.
  27. void AddHeader(const std::string& value) override;
  28. void SetPostData(const std::string& content_type,
  29. const std::string& data) override;
  30. void Start(OnResultCallback on_result_callback) override;
  31. private:
  32. void OnURLLoadComplete(std::unique_ptr<std::string> response_body);
  33. std::unique_ptr<network::SimpleURLLoader> url_loader_;
  34. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
  35. std::unique_ptr<network::ResourceRequest> resource_request_;
  36. const net::NetworkTrafficAnnotationTag traffic_annotation_;
  37. std::string post_data_content_type_;
  38. std::string post_data_;
  39. OnResultCallback on_result_callback_;
  40. };
  41. class ChromiumUrlRequestFactory : public UrlRequestFactory {
  42. public:
  43. ChromiumUrlRequestFactory(
  44. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
  45. ~ChromiumUrlRequestFactory() override;
  46. // UrlRequestFactory interface.
  47. std::unique_ptr<UrlRequest> CreateUrlRequest(
  48. UrlRequest::Type type,
  49. const std::string& url,
  50. const net::NetworkTrafficAnnotationTag& traffic_annotation) override;
  51. private:
  52. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
  53. };
  54. } // namespace remoting
  55. #endif // REMOTING_BASE_CHROMIUM_URL_REQUEST_H_