atom_blob_reader.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_ATOM_BLOB_READER_H_
  5. #define ATOM_BROWSER_ATOM_BLOB_READER_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. namespace content {
  9. class ChromeBlobStorageContext;
  10. }
  11. namespace net {
  12. class IOBuffer;
  13. }
  14. namespace storage {
  15. class BlobDataHandle;
  16. class BlobReader;
  17. class FileSystemContext;
  18. }
  19. namespace v8 {
  20. template <class T>
  21. class Local;
  22. class Value;
  23. }
  24. namespace atom {
  25. // A class to keep track of the blob context. All methods,
  26. // except Ctor are expected to be called on IO thread.
  27. class AtomBlobReader {
  28. public:
  29. using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
  30. AtomBlobReader(content::ChromeBlobStorageContext* blob_context,
  31. storage::FileSystemContext* file_system_context);
  32. ~AtomBlobReader();
  33. void StartReading(
  34. const std::string& uuid,
  35. const AtomBlobReader::CompletionCallback& callback);
  36. private:
  37. // A self-destroyed helper class to read the blob data.
  38. // Must be accessed on IO thread.
  39. class BlobReadHelper {
  40. public:
  41. using CompletionCallback = base::Callback<void(char*, int)>;
  42. BlobReadHelper(std::unique_ptr<storage::BlobReader> blob_reader,
  43. const BlobReadHelper::CompletionCallback& callback);
  44. ~BlobReadHelper();
  45. void Read();
  46. private:
  47. void DidCalculateSize(int result);
  48. void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
  49. int bytes_read);
  50. std::unique_ptr<storage::BlobReader> blob_reader_;
  51. BlobReadHelper::CompletionCallback completion_callback_;
  52. DISALLOW_COPY_AND_ASSIGN(BlobReadHelper);
  53. };
  54. scoped_refptr<content::ChromeBlobStorageContext> blob_context_;
  55. scoped_refptr<storage::FileSystemContext> file_system_context_;
  56. DISALLOW_COPY_AND_ASSIGN(AtomBlobReader);
  57. };
  58. } // namespace atom
  59. #endif // ATOM_BROWSER_ATOM_BLOB_READER_H_