2016-08-31 00:08:32 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_ATOM_BLOB_READER_H_
|
|
|
|
#define SHELL_BROWSER_ATOM_BLOB_READER_H_
|
2016-08-31 00:08:32 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2016-08-31 00:08:32 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/promise_util.h"
|
2016-08-31 00:08:32 +00:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class ChromeBlobStorageContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace net {
|
|
|
|
class IOBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace storage {
|
|
|
|
class BlobDataHandle;
|
|
|
|
class BlobReader;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace storage
|
2016-08-31 00:08:32 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
template <class T>
|
|
|
|
class Local;
|
|
|
|
class Value;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace v8
|
2016-08-31 00:08:32 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-08-31 00:08:32 +00:00
|
|
|
|
|
|
|
// A class to keep track of the blob context. All methods,
|
|
|
|
// except Ctor are expected to be called on IO thread.
|
|
|
|
class AtomBlobReader {
|
|
|
|
public:
|
2018-04-12 08:06:23 +00:00
|
|
|
explicit AtomBlobReader(content::ChromeBlobStorageContext* blob_context);
|
2016-08-31 00:08:32 +00:00
|
|
|
~AtomBlobReader();
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
void StartReading(const std::string& uuid, electron::util::Promise promise);
|
2016-08-31 00:08:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// A self-destroyed helper class to read the blob data.
|
|
|
|
// Must be accessed on IO thread.
|
|
|
|
class BlobReadHelper {
|
|
|
|
public:
|
2019-03-14 15:11:01 +00:00
|
|
|
using CompletionCallback = base::OnceCallback<void(char*, int)>;
|
2016-08-31 00:08:32 +00:00
|
|
|
|
|
|
|
BlobReadHelper(std::unique_ptr<storage::BlobReader> blob_reader,
|
2019-03-14 15:11:01 +00:00
|
|
|
BlobReadHelper::CompletionCallback callback);
|
2016-08-31 00:08:32 +00:00
|
|
|
~BlobReadHelper();
|
|
|
|
|
|
|
|
void Read();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DidCalculateSize(int result);
|
|
|
|
void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
|
|
|
|
int bytes_read);
|
|
|
|
|
|
|
|
std::unique_ptr<storage::BlobReader> blob_reader_;
|
|
|
|
BlobReadHelper::CompletionCallback completion_callback_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BlobReadHelper);
|
|
|
|
};
|
|
|
|
|
|
|
|
scoped_refptr<content::ChromeBlobStorageContext> blob_context_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomBlobReader);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-08-31 00:08:32 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_ATOM_BLOB_READER_H_
|