atom_blob_reader.h 2.0 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. } // namespace storage
  19. namespace v8 {
  20. template <class T>
  21. class Local;
  22. class Value;
  23. } // namespace v8
  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(const std::string& uuid,
  34. const AtomBlobReader::CompletionCallback& callback);
  35. private:
  36. // A self-destroyed helper class to read the blob data.
  37. // Must be accessed on IO thread.
  38. class BlobReadHelper {
  39. public:
  40. using CompletionCallback = base::Callback<void(char*, int)>;
  41. BlobReadHelper(std::unique_ptr<storage::BlobReader> blob_reader,
  42. const BlobReadHelper::CompletionCallback& callback);
  43. ~BlobReadHelper();
  44. void Read();
  45. private:
  46. void DidCalculateSize(int result);
  47. void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
  48. int bytes_read);
  49. std::unique_ptr<storage::BlobReader> blob_reader_;
  50. BlobReadHelper::CompletionCallback completion_callback_;
  51. DISALLOW_COPY_AND_ASSIGN(BlobReadHelper);
  52. };
  53. scoped_refptr<content::ChromeBlobStorageContext> blob_context_;
  54. scoped_refptr<storage::FileSystemContext> file_system_context_;
  55. DISALLOW_COPY_AND_ASSIGN(AtomBlobReader);
  56. };
  57. } // namespace atom
  58. #endif // ATOM_BROWSER_ATOM_BLOB_READER_H_