Commit 28afa1fa authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Change some blob callback types to be OnceCallback.

These callbacks are only called once, so should really be OnceCallback
rather than Callback.

Bug: none
Change-Id: Ia8b15a328db8f7949402bd7b6a737a578fba01dd
Reviewed-on: https://chromium-review.googlesource.com/874953
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530407}
parent 3f25cfcc
...@@ -101,22 +101,22 @@ BlobStatus BlobDataHandle::GetBlobStatus() const { ...@@ -101,22 +101,22 @@ BlobStatus BlobDataHandle::GetBlobStatus() const {
return shared_->context_->GetBlobStatus(shared_->uuid_); return shared_->context_->GetBlobStatus(shared_->uuid_);
} }
void BlobDataHandle::RunOnConstructionComplete(const BlobStatusCallback& done) { void BlobDataHandle::RunOnConstructionComplete(BlobStatusCallback done) {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (!shared_->context_.get()) { if (!shared_->context_.get()) {
done.Run(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); std::move(done).Run(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS);
return; return;
} }
shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); shared_->context_->RunOnConstructionComplete(shared_->uuid_, std::move(done));
} }
void BlobDataHandle::RunOnConstructionBegin(const BlobStatusCallback& done) { void BlobDataHandle::RunOnConstructionBegin(BlobStatusCallback done) {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (!shared_->context_.get()) { if (!shared_->context_.get()) {
done.Run(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); std::move(done).Run(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS);
return; return;
} }
shared_->context_->RunOnConstructionBegin(shared_->uuid_, done); shared_->context_->RunOnConstructionBegin(shared_->uuid_, std::move(done));
} }
std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
......
...@@ -67,7 +67,7 @@ class STORAGE_EXPORT BlobDataHandle ...@@ -67,7 +67,7 @@ class STORAGE_EXPORT BlobDataHandle
// Must be called on IO thread. // Must be called on IO thread.
// Calling this multiple times results in registering multiple // Calling this multiple times results in registering multiple
// completion callbacks. // completion callbacks.
void RunOnConstructionComplete(const BlobStatusCallback& done); void RunOnConstructionComplete(BlobStatusCallback done);
// The callback will be run on the IO thread when construction of the blob // The callback will be run on the IO thread when construction of the blob
// has began. If construction has already began (or has finished already), // has began. If construction has already began (or has finished already),
...@@ -76,7 +76,7 @@ class STORAGE_EXPORT BlobDataHandle ...@@ -76,7 +76,7 @@ class STORAGE_EXPORT BlobDataHandle
// Must be called on IO thread. // Must be called on IO thread.
// Calling this multiple times results in registering multiple // Calling this multiple times results in registering multiple
// callbacks. // callbacks.
void RunOnConstructionBegin(const BlobStatusCallback& done); void RunOnConstructionBegin(BlobStatusCallback done);
// A BlobReader is used to read the data from the blob. This object is // A BlobReader is used to read the data from the blob. This object is
// intended to be transient and should not be stored for any extended period // intended to be transient and should not be stored for any extended period
......
...@@ -33,7 +33,7 @@ BlobEntry::BuildingState::BuildingState( ...@@ -33,7 +33,7 @@ BlobEntry::BuildingState::BuildingState(
TransportAllowedCallback transport_allowed_callback, TransportAllowedCallback transport_allowed_callback,
size_t num_building_dependent_blobs) size_t num_building_dependent_blobs)
: transport_items_present(transport_items_present), : transport_items_present(transport_items_present),
transport_allowed_callback(transport_allowed_callback), transport_allowed_callback(std::move(transport_allowed_callback)),
num_building_dependent_blobs(num_building_dependent_blobs) {} num_building_dependent_blobs(num_building_dependent_blobs) {}
BlobEntry::BuildingState::~BuildingState() { BlobEntry::BuildingState::~BuildingState() {
......
...@@ -26,9 +26,8 @@ class ShareableBlobDataItem; ...@@ -26,9 +26,8 @@ class ShareableBlobDataItem;
// Represents a blob in BlobStorageRegistry. Exported only for unit tests. // Represents a blob in BlobStorageRegistry. Exported only for unit tests.
class STORAGE_EXPORT BlobEntry { class STORAGE_EXPORT BlobEntry {
public: public:
using TransportAllowedCallback = using TransportAllowedCallback = base::OnceCallback<
base::Callback<void(BlobStatus, void(BlobStatus, std::vector<BlobMemoryController::FileCreationInfo>)>;
std::vector<BlobMemoryController::FileCreationInfo>)>;
// Records a copy from a referenced blob. Copies happen after referenced blobs // Records a copy from a referenced blob. Copies happen after referenced blobs
// are complete & quota for the copies is granted. // are complete & quota for the copies is granted.
......
...@@ -374,9 +374,9 @@ void BlobRegistryImpl::BlobUnderConstruction::ResolvedAllBlobDependencies() { ...@@ -374,9 +374,9 @@ void BlobRegistryImpl::BlobUnderConstruction::ResolvedAllBlobDependencies() {
} }
} }
BlobStorageContext::TransportAllowedCallback callback = auto callback =
base::Bind(&BlobUnderConstruction::OnReadyForTransport, base::BindRepeating(&BlobUnderConstruction::OnReadyForTransport,
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
// OnReadyForTransport can be called synchronously, which can call // OnReadyForTransport can be called synchronously, which can call
// MarkAsFinishedAndDeleteSelf synchronously, so don't access any members // MarkAsFinishedAndDeleteSelf synchronously, so don't access any members
......
...@@ -475,30 +475,32 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFutureBlob( ...@@ -475,30 +475,32 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFutureBlob(
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildPreregisteredBlob( std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildPreregisteredBlob(
const BlobDataBuilder& content, const BlobDataBuilder& content,
const TransportAllowedCallback& transport_allowed_callback) { TransportAllowedCallback transport_allowed_callback) {
BlobEntry* entry = registry_.GetEntry(content.uuid()); BlobEntry* entry = registry_.GetEntry(content.uuid());
DCHECK(entry); DCHECK(entry);
DCHECK_EQ(BlobStatus::PENDING_CONSTRUCTION, entry->status()); DCHECK_EQ(BlobStatus::PENDING_CONSTRUCTION, entry->status());
entry->set_size(0); entry->set_size(0);
return BuildBlobInternal(entry, content, transport_allowed_callback); return BuildBlobInternal(entry, content,
std::move(transport_allowed_callback));
} }
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlob( std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlob(
const BlobDataBuilder& content, const BlobDataBuilder& content,
const TransportAllowedCallback& transport_allowed_callback) { TransportAllowedCallback transport_allowed_callback) {
DCHECK(!registry_.HasEntry(content.uuid_)); DCHECK(!registry_.HasEntry(content.uuid_));
BlobEntry* entry = registry_.CreateEntry( BlobEntry* entry = registry_.CreateEntry(
content.uuid(), content.content_type_, content.content_disposition_); content.uuid(), content.content_type_, content.content_disposition_);
return BuildBlobInternal(entry, content, transport_allowed_callback); return BuildBlobInternal(entry, content,
std::move(transport_allowed_callback));
} }
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal( std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal(
BlobEntry* entry, BlobEntry* entry,
const BlobDataBuilder& content, const BlobDataBuilder& content,
const TransportAllowedCallback& transport_allowed_callback) { TransportAllowedCallback transport_allowed_callback) {
// This flattens all blob references in the transportion content out and // This flattens all blob references in the transportion content out and
// stores the complete item representation in the internal data. // stores the complete item representation in the internal data.
BlobFlattener flattener(content, entry, &registry_); BlobFlattener flattener(content, entry, &registry_);
...@@ -547,8 +549,8 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal( ...@@ -547,8 +549,8 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal(
auto previous_building_state = std::move(entry->building_state_); auto previous_building_state = std::move(entry->building_state_);
entry->set_building_state(std::make_unique<BlobEntry::BuildingState>( entry->set_building_state(std::make_unique<BlobEntry::BuildingState>(
!flattener.pending_transport_items.empty(), transport_allowed_callback, !flattener.pending_transport_items.empty(),
num_building_dependent_blobs)); std::move(transport_allowed_callback), num_building_dependent_blobs));
BlobEntry::BuildingState* building_state = entry->building_state_.get(); BlobEntry::BuildingState* building_state = entry->building_state_.get();
std::swap(building_state->copies, flattener.copies); std::swap(building_state->copies, flattener.copies);
std::swap(building_state->dependent_blobs, dependent_blobs); std::swap(building_state->dependent_blobs, dependent_blobs);
...@@ -562,9 +564,9 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal( ...@@ -562,9 +564,9 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal(
std::swap(building_state->build_completion_callbacks, std::swap(building_state->build_completion_callbacks,
previous_building_state->build_completion_callbacks); previous_building_state->build_completion_callbacks);
auto runner = base::ThreadTaskRunnerHandle::Get(); auto runner = base::ThreadTaskRunnerHandle::Get();
for (const auto& callback : for (auto& callback : previous_building_state->build_started_callbacks)
previous_building_state->build_started_callbacks) runner->PostTask(FROM_HERE,
runner->PostTask(FROM_HERE, base::BindOnce(callback, entry->status())); base::BindOnce(std::move(callback), entry->status()));
} }
// Break ourselves if we have an error. BuildingState must be set first so the // Break ourselves if we have an error. BuildingState must be set first so the
...@@ -683,28 +685,27 @@ BlobStatus BlobStorageContext::GetBlobStatus(const std::string& uuid) const { ...@@ -683,28 +685,27 @@ BlobStatus BlobStorageContext::GetBlobStatus(const std::string& uuid) const {
return entry->status(); return entry->status();
} }
void BlobStorageContext::RunOnConstructionComplete( void BlobStorageContext::RunOnConstructionComplete(const std::string& uuid,
const std::string& uuid, BlobStatusCallback done) {
const BlobStatusCallback& done) {
BlobEntry* entry = registry_.GetEntry(uuid); BlobEntry* entry = registry_.GetEntry(uuid);
DCHECK(entry); DCHECK(entry);
if (BlobStatusIsPending(entry->status())) { if (BlobStatusIsPending(entry->status())) {
entry->building_state_->build_completion_callbacks.push_back(done); entry->building_state_->build_completion_callbacks.push_back(
std::move(done));
return; return;
} }
done.Run(entry->status()); std::move(done).Run(entry->status());
} }
void BlobStorageContext::RunOnConstructionBegin( void BlobStorageContext::RunOnConstructionBegin(const std::string& uuid,
const std::string& uuid, BlobStatusCallback done) {
const BlobStatusCallback& done) {
BlobEntry* entry = registry_.GetEntry(uuid); BlobEntry* entry = registry_.GetEntry(uuid);
DCHECK(entry); DCHECK(entry);
if (entry->status() == BlobStatus::PENDING_CONSTRUCTION) { if (entry->status() == BlobStatus::PENDING_CONSTRUCTION) {
entry->building_state_->build_started_callbacks.push_back(done); entry->building_state_->build_started_callbacks.push_back(std::move(done));
return; return;
} }
done.Run(entry->status()); std::move(done).Run(entry->status());
} }
std::unique_ptr<BlobDataHandle> BlobStorageContext::CreateHandle( std::unique_ptr<BlobDataHandle> BlobStorageContext::CreateHandle(
...@@ -735,20 +736,19 @@ void BlobStorageContext::CancelBuildingBlobInternal(BlobEntry* entry, ...@@ -735,20 +736,19 @@ void BlobStorageContext::CancelBuildingBlobInternal(BlobEntry* entry,
if (entry->building_state_ && if (entry->building_state_ &&
entry->building_state_->transport_allowed_callback) { entry->building_state_->transport_allowed_callback) {
transport_allowed_callback = transport_allowed_callback =
entry->building_state_->transport_allowed_callback; std::move(entry->building_state_->transport_allowed_callback);
entry->building_state_->transport_allowed_callback.Reset();
} }
if (entry->building_state_ && if (entry->building_state_ &&
entry->status() == BlobStatus::PENDING_CONSTRUCTION) { entry->status() == BlobStatus::PENDING_CONSTRUCTION) {
auto runner = base::ThreadTaskRunnerHandle::Get(); auto runner = base::ThreadTaskRunnerHandle::Get();
for (const auto& callback : entry->building_state_->build_started_callbacks) for (auto& callback : entry->building_state_->build_started_callbacks)
runner->PostTask(FROM_HERE, base::BindOnce(callback, reason)); runner->PostTask(FROM_HERE, base::BindOnce(std::move(callback), reason));
} }
ClearAndFreeMemory(entry); ClearAndFreeMemory(entry);
entry->set_status(reason); entry->set_status(reason);
if (transport_allowed_callback) { if (transport_allowed_callback) {
transport_allowed_callback.Run( std::move(transport_allowed_callback)
reason, std::vector<BlobMemoryController::FileCreationInfo>()); .Run(reason, std::vector<BlobMemoryController::FileCreationInfo>());
} }
FinishBuilding(entry); FinishBuilding(entry);
} }
...@@ -825,8 +825,9 @@ void BlobStorageContext::FinishBuilding(BlobEntry* entry) { ...@@ -825,8 +825,9 @@ void BlobStorageContext::FinishBuilding(BlobEntry* entry) {
memory_controller_.NotifyMemoryItemsUsed(entry->items()); memory_controller_.NotifyMemoryItemsUsed(entry->items());
auto runner = base::ThreadTaskRunnerHandle::Get(); auto runner = base::ThreadTaskRunnerHandle::Get();
for (const auto& callback : callbacks) for (auto& callback : callbacks)
runner->PostTask(FROM_HERE, base::Bind(callback, entry->status())); runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), entry->status()));
for (const auto& shareable_item : entry->items()) { for (const auto& shareable_item : entry->items()) {
DCHECK_NE(network::DataElement::TYPE_BYTES_DESCRIPTION, DCHECK_NE(network::DataElement::TYPE_BYTES_DESCRIPTION,
......
...@@ -99,7 +99,7 @@ class STORAGE_EXPORT BlobStorageContext { ...@@ -99,7 +99,7 @@ class STORAGE_EXPORT BlobStorageContext {
// referencing ourself. // referencing ourself.
std::unique_ptr<BlobDataHandle> BuildBlob( std::unique_ptr<BlobDataHandle> BuildBlob(
const BlobDataBuilder& input_builder, const BlobDataBuilder& input_builder,
const TransportAllowedCallback& transport_allowed_callback); TransportAllowedCallback transport_allowed_callback);
// Similar to BuildBlob, but this merely registers a blob that will be built // Similar to BuildBlob, but this merely registers a blob that will be built
// in the future. The caller must later call either BuildPreregisteredBlob // in the future. The caller must later call either BuildPreregisteredBlob
...@@ -118,7 +118,7 @@ class STORAGE_EXPORT BlobStorageContext { ...@@ -118,7 +118,7 @@ class STORAGE_EXPORT BlobStorageContext {
// AddFutureBlob. // AddFutureBlob.
std::unique_ptr<BlobDataHandle> BuildPreregisteredBlob( std::unique_ptr<BlobDataHandle> BuildPreregisteredBlob(
const BlobDataBuilder& input_builder, const BlobDataBuilder& input_builder,
const TransportAllowedCallback& transport_allowed_callback); TransportAllowedCallback transport_allowed_callback);
// This breaks a blob that is currently being built by using the BuildBlob // This breaks a blob that is currently being built by using the BuildBlob
// method above. Any callbacks waiting on this blob, including the // method above. Any callbacks waiting on this blob, including the
...@@ -243,12 +243,12 @@ class STORAGE_EXPORT BlobStorageContext { ...@@ -243,12 +243,12 @@ class STORAGE_EXPORT BlobStorageContext {
// Runs |done| when construction completes with the final status of the blob. // Runs |done| when construction completes with the final status of the blob.
void RunOnConstructionComplete(const std::string& uuid, void RunOnConstructionComplete(const std::string& uuid,
const BlobStatusCallback& done_callback); BlobStatusCallback done_callback);
// Runs |done| when construction begins (when the blob is no longer // Runs |done| when construction begins (when the blob is no longer
// PENDING_CONSTRUCTION) with the new status of the blob. // PENDING_CONSTRUCTION) with the new status of the blob.
void RunOnConstructionBegin(const std::string& uuid, void RunOnConstructionBegin(const std::string& uuid,
const BlobStatusCallback& done_callback); BlobStatusCallback done_callback);
BlobStorageRegistry* mutable_registry() { return &registry_; } BlobStorageRegistry* mutable_registry() { return &registry_; }
...@@ -260,7 +260,7 @@ class STORAGE_EXPORT BlobStorageContext { ...@@ -260,7 +260,7 @@ class STORAGE_EXPORT BlobStorageContext {
std::unique_ptr<BlobDataHandle> BuildBlobInternal( std::unique_ptr<BlobDataHandle> BuildBlobInternal(
BlobEntry* entry, BlobEntry* entry,
const BlobDataBuilder& input_builder, const BlobDataBuilder& input_builder,
const TransportAllowedCallback& transport_allowed_callback); TransportAllowedCallback transport_allowed_callback);
std::unique_ptr<BlobDataHandle> CreateHandle(const std::string& uuid, std::unique_ptr<BlobDataHandle> CreateHandle(const std::string& uuid,
BlobEntry* entry); BlobEntry* entry);
......
...@@ -131,7 +131,7 @@ enum class BlobStatus { ...@@ -131,7 +131,7 @@ enum class BlobStatus {
LAST = LAST_PENDING LAST = LAST_PENDING
}; };
using BlobStatusCallback = base::Callback<void(BlobStatus)>; using BlobStatusCallback = base::OnceCallback<void(BlobStatus)>;
// Returns if the status is an error code. // Returns if the status is an error code.
STORAGE_COMMON_EXPORT bool BlobStatusIsError(BlobStatus status); STORAGE_COMMON_EXPORT bool BlobStatusIsError(BlobStatus status);
......
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