Commit 358a5fe9 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

storage: shareable file ref should not be a data handle

This is just cleanup in preparation for larger data handle changes.
There's no need for ShareableFileReference to subclass
BlobDataItem::DataHandle as it doesn't implement any of its interfaces.
Its goal is to preserve the lifetime of the ScopedFile, and it's clearer
to do this by holding onto the ShareableFileReference in BlobDataItem
directly.

Bug: 1012869
Change-Id: Ieaad64adede4358d734aff8e3cc21bd9038566cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1850198
Commit-Queue: enne <enne@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: enne <enne@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704357}
parent aba5567b
...@@ -495,8 +495,7 @@ void BlobBuilderFromStream::AllocateMoreFileSpace( ...@@ -495,8 +495,7 @@ void BlobBuilderFromStream::AllocateMoreFileSpace(
items_.back()->item()->length() < kMaxFileSize) { items_.back()->item()->length() < kMaxFileSize) {
auto item = items_.back()->item(); auto item = items_.back()->item();
uint64_t old_file_size = item->length(); uint64_t old_file_size = item->length();
scoped_refptr<ShareableFileReference> file_reference = scoped_refptr<ShareableFileReference> file_reference = item->file_ref_;
static_cast<ShareableFileReference*>(item->data_handle());
DCHECK(file_reference); DCHECK(file_reference);
auto file_size_delta = std::min(kMaxFileSize - old_file_size, length_hint); auto file_size_delta = std::min(kMaxFileSize - old_file_size, length_hint);
context_->mutable_memory_controller()->GrowFileAllocation( context_->mutable_memory_controller()->GrowFileAllocation(
...@@ -618,7 +617,7 @@ void BlobBuilderFromStream::DidWriteToExtendedFile( ...@@ -618,7 +617,7 @@ void BlobBuilderFromStream::DidWriteToExtendedFile(
DCHECK(!items_.empty()); DCHECK(!items_.empty());
auto item = items_.back()->item(); auto item = items_.back()->item();
DCHECK_EQ(item->type(), BlobDataItem::Type::kFile); DCHECK_EQ(item->type(), BlobDataItem::Type::kFile);
DCHECK_EQ(item->data_handle(), file_reference.get()); DCHECK_EQ(item->file_ref_, file_reference.get());
item->SetFileModificationTime(modification_time); item->SetFileModificationTime(modification_time);
current_total_size_ += bytes_written; current_total_size_ += bytes_written;
......
...@@ -281,8 +281,7 @@ void BlobDataBuilder::SliceBlob(const BlobEntry* source, ...@@ -281,8 +281,7 @@ void BlobDataBuilder::SliceBlob(const BlobEntry* source,
case BlobDataItem::Type::kFile: { case BlobDataItem::Type::kFile: {
data_item = BlobDataItem::CreateFile( data_item = BlobDataItem::CreateFile(
source_item->path(), source_item->offset() + item_offset, read_size, source_item->path(), source_item->offset() + item_offset, read_size,
source_item->expected_modification_time(), source_item->expected_modification_time(), source_item->file_ref_);
source_item->data_handle_);
if (source_item->IsFutureFileItem()) { if (source_item->IsFutureFileItem()) {
// The source file isn't a real file yet (path is fake), so store the // The source file isn't a real file yet (path is fake), so store the
......
...@@ -78,12 +78,12 @@ scoped_refptr<BlobDataItem> BlobDataItem::CreateFile( ...@@ -78,12 +78,12 @@ scoped_refptr<BlobDataItem> BlobDataItem::CreateFile(
uint64_t offset, uint64_t offset,
uint64_t length, uint64_t length,
base::Time expected_modification_time, base::Time expected_modification_time,
scoped_refptr<DataHandle> data_handle) { scoped_refptr<ShareableFileReference> file_ref) {
auto item = auto item =
base::WrapRefCounted(new BlobDataItem(Type::kFile, offset, length)); base::WrapRefCounted(new BlobDataItem(Type::kFile, offset, length));
item->path_ = std::move(path); item->path_ = std::move(path);
item->expected_modification_time_ = std::move(expected_modification_time); item->expected_modification_time_ = std::move(expected_modification_time);
item->data_handle_ = std::move(data_handle); item->file_ref_ = std::move(file_ref);
// TODO(mek): DCHECK(!item->IsFutureFileItem()) when BlobDataBuilder has some // TODO(mek): DCHECK(!item->IsFutureFileItem()) when BlobDataBuilder has some
// other way of slicing a future file. // other way of slicing a future file.
return item; return item;
...@@ -171,14 +171,15 @@ void BlobDataItem::ShrinkBytes(size_t new_length) { ...@@ -171,14 +171,15 @@ void BlobDataItem::ShrinkBytes(size_t new_length) {
bytes_.resize(length_); bytes_.resize(length_);
} }
void BlobDataItem::PopulateFile(base::FilePath path, void BlobDataItem::PopulateFile(
base::Time expected_modification_time, base::FilePath path,
scoped_refptr<DataHandle> data_handle) { base::Time expected_modification_time,
scoped_refptr<ShareableFileReference> file_ref) {
DCHECK_EQ(type_, Type::kFile); DCHECK_EQ(type_, Type::kFile);
DCHECK(IsFutureFileItem()); DCHECK(IsFutureFileItem());
path_ = std::move(path); path_ = std::move(path);
expected_modification_time_ = std::move(expected_modification_time); expected_modification_time_ = std::move(expected_modification_time);
data_handle_ = std::move(data_handle); file_ref_ = std::move(file_ref);
} }
void BlobDataItem::ShrinkFile(uint64_t new_length) { void BlobDataItem::ShrinkFile(uint64_t new_length) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace storage { namespace storage {
...@@ -102,7 +103,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem ...@@ -102,7 +103,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem
uint64_t offset, uint64_t offset,
uint64_t length, uint64_t length,
base::Time expected_modification_time = base::Time(), base::Time expected_modification_time = base::Time(),
scoped_refptr<DataHandle> data_handle = nullptr); scoped_refptr<ShareableFileReference> file_ref = nullptr);
static scoped_refptr<BlobDataItem> CreateFutureFile(uint64_t offset, static scoped_refptr<BlobDataItem> CreateFutureFile(uint64_t offset,
uint64_t length, uint64_t length,
uint64_t file_id); uint64_t file_id);
...@@ -148,8 +149,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem ...@@ -148,8 +149,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem
} }
DataHandle* data_handle() const { DataHandle* data_handle() const {
DCHECK(type_ == Type::kFile || type_ == Type::kReadableDataHandle) DCHECK_EQ(type_, Type::kReadableDataHandle) << static_cast<int>(type_);
<< static_cast<int>(type_);
return data_handle_.get(); return data_handle_.get();
} }
...@@ -180,7 +180,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem ...@@ -180,7 +180,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem
void PopulateFile(base::FilePath path, void PopulateFile(base::FilePath path,
base::Time expected_modification_time, base::Time expected_modification_time,
scoped_refptr<DataHandle> data_handle); scoped_refptr<ShareableFileReference> file_ref);
void ShrinkFile(uint64_t new_length); void ShrinkFile(uint64_t new_length);
void GrowFile(uint64_t new_length); void GrowFile(uint64_t new_length);
void SetFileModificationTime(base::Time time) { void SetFileModificationTime(base::Time time) {
...@@ -198,8 +198,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem ...@@ -198,8 +198,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem
base::Time base::Time
expected_modification_time_; // For Type::kFile and kFileFilesystem. expected_modification_time_; // For Type::kFile and kFileFilesystem.
scoped_refptr<DataHandle> scoped_refptr<DataHandle> data_handle_; // For kReadableDataHandle.
data_handle_; // For Type::kFile and kReadableDataHandle. scoped_refptr<ShareableFileReference> file_ref_; // For Type::kFile
scoped_refptr<FileSystemContext> scoped_refptr<FileSystemContext>
file_system_context_; // For Type::kFileFilesystem. file_system_context_; // For Type::kFileFilesystem.
......
...@@ -520,7 +520,7 @@ void BlobStorageContext::FinishBuilding(BlobEntry* entry) { ...@@ -520,7 +520,7 @@ void BlobStorageContext::FinishBuilding(BlobEntry* entry) {
source_item->path(), source_item->path(),
source_item->offset() + copy.source_item_offset, dest_size, source_item->offset() + copy.source_item_offset, dest_size,
source_item->expected_modification_time(), source_item->expected_modification_time(),
source_item->data_handle_); source_item->file_ref_);
copy.dest_item->set_item(std::move(new_item)); copy.dest_item->set_item(std::move(new_item));
break; break;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "storage/browser/blob/blob_data_item.h"
#include "storage/browser/blob/scoped_file.h" #include "storage/browser/blob/scoped_file.h"
namespace storage { namespace storage {
...@@ -17,7 +16,7 @@ namespace storage { ...@@ -17,7 +16,7 @@ namespace storage {
// This class is non-thread-safe and all methods must be called on a single // This class is non-thread-safe and all methods must be called on a single
// thread. // thread.
class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference
: public BlobDataItem::DataHandle { : public base::RefCounted<ShareableFileReference> {
public: public:
using FinalReleaseCallback = ScopedFile::ScopeOutCallback; using FinalReleaseCallback = ScopedFile::ScopeOutCallback;
...@@ -64,8 +63,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference ...@@ -64,8 +63,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference
void AddFinalReleaseCallback(FinalReleaseCallback callback); void AddFinalReleaseCallback(FinalReleaseCallback callback);
private: private:
friend class base::RefCounted<ShareableFileReference>;
ShareableFileReference(ScopedFile scoped_file); ShareableFileReference(ScopedFile scoped_file);
~ShareableFileReference() override; ~ShareableFileReference();
ScopedFile scoped_file_; ScopedFile scoped_file_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment