Commit 586d8063 authored by tzik's avatar tzik Committed by Commit Bot

Stop using IDMap in FileSystemOperationRunner

This converts storage::FileSystemOperationRunner::operations_ from
base::IDMap to std::map.

All other users of base::IDMap don't store null value to base::IDMap,
and the null value makes the interface of base::IDMap complex.
So, this removes base::IDMap from FSOR as a preparation to refactor
IDMap.

Change-Id: I65b81ead88133b9ac5ea724af53df67b812e0fde
Reviewed-on: https://chromium-review.googlesource.com/995652Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548336}
parent d9909349
......@@ -45,7 +45,7 @@ FileSystemOperationRunner::OperationHandle::~OperationHandle() = default;
FileSystemOperationRunner::~FileSystemOperationRunner() = default;
void FileSystemOperationRunner::Shutdown() {
operations_.Clear();
operations_.clear();
}
OperationID FileSystemOperationRunner::CreateFile(
......@@ -331,13 +331,14 @@ void FileSystemOperationRunner::Cancel(
stray_cancel_callbacks_[id] = callback;
return;
}
FileSystemOperation* operation = operations_.Lookup(id);
if (!operation) {
Operations::iterator found = operations_.find(id);
if (found == operations_.end() || !found->second) {
// There is no operation with |id|.
callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
return;
}
operation->Cancel(callback);
found->second->Cancel(callback);
}
OperationID FileSystemOperationRunner::TouchFile(
......@@ -696,7 +697,8 @@ FileSystemOperationRunner::BeginOperation(
std::unique_ptr<FileSystemOperation> operation,
base::WeakPtr<BeginOperationScoper> scope) {
OperationHandle handle;
handle.id = operations_.Add(std::move(operation));
handle.id = next_operation_id_++;
operations_.emplace(handle.id, std::move(operation));
handle.scope = scope;
return handle;
}
......@@ -715,10 +717,7 @@ void FileSystemOperationRunner::FinishOperation(OperationID id) {
write_target_urls_.erase(found);
}
// IDMap::Lookup fails if the operation is NULL, so we don't check
// operations_.Lookup(id) here.
operations_.Remove(id);
operations_.erase(id);
finished_operations_.erase(id);
// Dispatch stray cancel callback if exists.
......
......@@ -307,8 +307,10 @@ class STORAGE_EXPORT FileSystemOperationRunner
// Not owned; file_system_context owns this.
FileSystemContext* file_system_context_;
// IDMap<std::unique_ptr<FileSystemOperation>> operations_;
base::IDMap<std::unique_ptr<FileSystemOperation>> operations_;
using Operations =
std::map<OperationID, std::unique_ptr<FileSystemOperation>>;
OperationID next_operation_id_ = 1;
Operations operations_;
// We keep track of the file to be modified by each operation so that
// we can notify observers when we're done.
......
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