#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_EXTERNAL_OBJECT_H_
#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_EXTERNAL_OBJECT_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
#include "third_party/blink/public/mojom/file_system_access/file_system_access_transfer_token.mojom.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-forward.h"
namespace content::indexed_db {
class CONTENT_EXPORT IndexedDBExternalObject {
public:
const static int64_t kUnknownSize = -1;
static void ConvertToMojo(
const std::vector<IndexedDBExternalObject>& objects,
std::vector<blink::mojom::IDBExternalObjectPtr>* mojo_objects);
IndexedDBExternalObject();
IndexedDBExternalObject(mojo::PendingRemote<blink::mojom::Blob> blob_remote,
const std::u16string& type,
int64_t size);
IndexedDBExternalObject(const std::u16string& type,
int64_t size,
int64_t blob_number);
IndexedDBExternalObject(mojo::PendingRemote<blink::mojom::Blob> blob_remote,
const std::u16string& file_name,
const std::u16string& type,
const base::Time& last_modified,
const int64_t size);
IndexedDBExternalObject(int64_t blob_number,
const std::u16string& type,
const std::u16string& file_name,
const base::Time& last_modified,
const int64_t size);
explicit IndexedDBExternalObject(
mojo::PendingRemote<blink::mojom::FileSystemAccessTransferToken>
token_remote);
explicit IndexedDBExternalObject(
std::vector<uint8_t> serialized_file_system_access_handle);
IndexedDBExternalObject(const IndexedDBExternalObject& other);
~IndexedDBExternalObject();
IndexedDBExternalObject& operator=(const IndexedDBExternalObject& other);
enum class ObjectType : uint8_t {
kBlob = 0,
kFile = 1,
kFileSystemAccessHandle = 2,
kMaxValue = kFileSystemAccessHandle
};
ObjectType object_type() const { return object_type_; }
bool is_remote_valid() const { return blob_remote_.is_bound(); }
void Clone(mojo::PendingReceiver<blink::mojom::Blob> receiver) const;
mojo::SharedRemote<blink::mojom::Blob> remote() const { return blob_remote_; }
const std::u16string& type() const { return type_; }
int64_t size() const { return size_; }
const std::u16string& file_name() const { return file_name_; }
const base::FilePath indexed_db_file_path() const {
return indexed_db_file_path_;
}
int64_t blob_number() const { return blob_number_; }
const base::Time& last_modified() const { return last_modified_; }
const std::vector<uint8_t>& serialized_file_system_access_handle() const {
return serialized_file_system_access_handle_;
}
bool is_file_system_access_remote_valid() const {
return token_remote_.is_bound();
}
blink::mojom::FileSystemAccessTransferToken* file_system_access_token_remote()
const {
return token_remote_.get();
}
const base::RepeatingClosure& mark_used_callback() const {
return mark_used_callback_;
}
const base::RepeatingClosure& release_callback() const {
return release_callback_;
}
void set_size(int64_t size);
void set_indexed_db_file_path(const base::FilePath& file_path);
void set_last_modified(const base::Time& time);
void set_serialized_file_system_access_handle(std::vector<uint8_t> token);
void set_blob_number(int64_t blob_number);
void set_mark_used_callback(base::RepeatingClosure mark_used_callback);
void set_release_callback(base::RepeatingClosure release_callback);
private:
ObjectType object_type_;
mojo::SharedRemote<blink::mojom::Blob> blob_remote_;
std::u16string type_;
base::FilePath indexed_db_file_path_;
int64_t size_ = kUnknownSize;
std::u16string file_name_;
base::Time last_modified_;
mojo::SharedRemote<blink::mojom::FileSystemAccessTransferToken> token_remote_;
std::vector<uint8_t> serialized_file_system_access_handle_;
int64_t blob_number_ = DatabaseMetaDataKey::kInvalidBlobNumber;
base::RepeatingClosure mark_used_callback_;
base::RepeatingClosure release_callback_;
};
}
#endif