url_loader_wrapper_impl.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 PDF_URL_LOADER_WRAPPER_IMPL_H_
  5. #define PDF_URL_LOADER_WRAPPER_IMPL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback_forward.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "base/timer/timer.h"
  13. #include "pdf/url_loader_wrapper.h"
  14. #include "ui/gfx/range/range.h"
  15. namespace chrome_pdf {
  16. class UrlLoader;
  17. class URLLoaderWrapperImpl : public URLLoaderWrapper {
  18. public:
  19. explicit URLLoaderWrapperImpl(std::unique_ptr<UrlLoader> url_loader);
  20. URLLoaderWrapperImpl(const URLLoaderWrapperImpl&) = delete;
  21. URLLoaderWrapperImpl& operator=(const URLLoaderWrapperImpl&) = delete;
  22. ~URLLoaderWrapperImpl() override;
  23. // URLLoaderWrapper overrides:
  24. int GetContentLength() const override;
  25. bool IsAcceptRangesBytes() const override;
  26. bool IsContentEncoded() const override;
  27. std::string GetContentType() const override;
  28. std::string GetContentDisposition() const override;
  29. int GetStatusCode() const override;
  30. bool IsMultipart() const override;
  31. bool GetByteRangeStart(int* start) const override;
  32. void Close() override;
  33. void OpenRange(const std::string& url,
  34. const std::string& referrer_url,
  35. uint32_t position,
  36. uint32_t size,
  37. base::OnceCallback<void(int)> callback) override;
  38. void ReadResponseBody(char* buffer,
  39. int buffer_size,
  40. base::OnceCallback<void(int)> callback) override;
  41. private:
  42. void SetHeadersFromLoader();
  43. void ParseHeaders(const std::string& response_headers);
  44. void DidOpen(base::OnceCallback<void(int)> callback, int32_t result);
  45. void DidRead(base::OnceCallback<void(int)> callback, int32_t result);
  46. void ReadResponseBodyImpl(base::OnceCallback<void(int)> callback);
  47. std::unique_ptr<UrlLoader> url_loader_;
  48. int content_length_ = -1;
  49. bool accept_ranges_bytes_ = false;
  50. bool content_encoded_ = false;
  51. std::string content_type_;
  52. std::string content_disposition_;
  53. std::string multipart_boundary_;
  54. gfx::Range byte_range_ = gfx::Range::InvalidRange();
  55. bool is_multipart_ = false;
  56. raw_ptr<char> buffer_ = nullptr;
  57. uint32_t buffer_size_ = 0;
  58. bool multi_part_processed_ = false;
  59. base::OneShotTimer read_starter_;
  60. base::WeakPtrFactory<URLLoaderWrapperImpl> weak_factory_{this};
  61. };
  62. } // namespace chrome_pdf
  63. #endif // PDF_URL_LOADER_WRAPPER_IMPL_H_