summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 14:23:52 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 14:23:52 +0000
commit938590b7f188fbfba52a1daceab90d51a29f109e (patch)
tree2c7be86ada0b05e2dda92b0164cf5da9369fb136 /webkit
parent30a718b5ead20a1b7390b7a9c0e292c0c486b979 (diff)
downloadchromium_src-938590b7f188fbfba52a1daceab90d51a29f109e.zip
chromium_src-938590b7f188fbfba52a1daceab90d51a29f109e.tar.gz
chromium_src-938590b7f188fbfba52a1daceab90d51a29f109e.tar.bz2
Deprecate LocalFileSystemOperation::ScopedUpdateNotifier
This changeset is a part of refactoring for cleaning up FilesystemObject's life time and introducing scoped_ptr. - Using scoped notifier makes it difficult to cleanup the FSO lifetime, so we should stop using it. - Also change FileSystemOperation creation code to create the base operation from source URL rather than dest URL (to make the code and later changes more natural). BUG=176444 TEST=existing tests Review URL: https://codereview.chromium.org/12336002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/async_file_test_helper.cc4
-rw-r--r--webkit/fileapi/cross_operation_delegate.cc33
-rw-r--r--webkit/fileapi/cross_operation_delegate.h24
-rw-r--r--webkit/fileapi/local_file_system_operation.cc167
-rw-r--r--webkit/fileapi/local_file_system_operation.h22
5 files changed, 118 insertions, 132 deletions
diff --git a/webkit/fileapi/async_file_test_helper.cc b/webkit/fileapi/async_file_test_helper.cc
index 178efdc..99899e6 100644
--- a/webkit/fileapi/async_file_test_helper.cc
+++ b/webkit/fileapi/async_file_test_helper.cc
@@ -82,7 +82,7 @@ base::PlatformFileError AsyncFileTestHelper::Copy(
const FileSystemURL& dest) {
DCHECK(context);
FileSystemOperation* operation =
- context->CreateFileSystemOperation(dest, NULL);
+ context->CreateFileSystemOperation(src, NULL);
EXPECT_TRUE(operation != NULL);
base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED;
base::RunLoop run_loop;
@@ -96,7 +96,7 @@ base::PlatformFileError AsyncFileTestHelper::Move(
const FileSystemURL& src,
const FileSystemURL& dest) {
FileSystemOperation* operation =
- context->CreateFileSystemOperation(dest, NULL);
+ context->CreateFileSystemOperation(src, NULL);
EXPECT_TRUE(operation != NULL);
base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED;
base::RunLoop run_loop;
diff --git a/webkit/fileapi/cross_operation_delegate.cc b/webkit/fileapi/cross_operation_delegate.cc
index d4d217b..e2989f2 100644
--- a/webkit/fileapi/cross_operation_delegate.cc
+++ b/webkit/fileapi/cross_operation_delegate.cc
@@ -14,23 +14,22 @@
namespace fileapi {
CrossOperationDelegate::CrossOperationDelegate(
- LocalFileSystemOperation* original_operation,
+ LocalFileSystemOperation* src_root_operation,
+ LocalFileSystemOperation* dest_root_operation,
const FileSystemURL& src_root,
const FileSystemURL& dest_root,
OperationType operation_type,
const StatusCallback& callback)
- : RecursiveOperationDelegate(original_operation),
+ : RecursiveOperationDelegate(src_root_operation),
src_root_(src_root),
dest_root_(dest_root),
operation_type_(operation_type),
callback_(callback),
- src_root_operation_(NULL) {
+ dest_root_operation_(dest_root_operation) {
same_file_system_ = AreSameFileSystem(src_root_, dest_root_);
}
CrossOperationDelegate::~CrossOperationDelegate() {
- if (src_root_operation_)
- delete src_root_operation_;
}
void CrossOperationDelegate::Run() {
@@ -53,21 +52,6 @@ void CrossOperationDelegate::RunRecursively() {
return;
}
- // Initialize the src_root_operation_ for the src root URL.
- DCHECK(!src_root_operation_);
- if (!same_file_system_) {
- base::PlatformFileError error = base::PLATFORM_FILE_OK;
- FileSystemOperation* operation = file_system_context()->
- CreateFileSystemOperation(src_root_, &error);
- if (error != base::PLATFORM_FILE_OK) {
- DCHECK(!operation);
- callback_.Run(error);
- return;
- }
- src_root_operation_ = operation->AsLocalFileSystemOperation();
- DCHECK(src_root_operation_);
- }
-
// First try to copy/move it as a file.
CopyOrMoveFile(src_root_, dest_root_,
base::Bind(&CrossOperationDelegate::DidTryCopyOrMoveFile,
@@ -230,7 +214,7 @@ FileSystemURL CrossOperationDelegate::CreateDestURL(
relative);
}
-LocalFileSystemOperation* CrossOperationDelegate::NewDestOperation(
+LocalFileSystemOperation* CrossOperationDelegate::NewSourceOperation(
const FileSystemURL& url) {
base::PlatformFileError error = base::PLATFORM_FILE_OK;
LocalFileSystemOperation* operation =
@@ -243,10 +227,10 @@ LocalFileSystemOperation* CrossOperationDelegate::NewDestOperation(
return operation;
}
-LocalFileSystemOperation* CrossOperationDelegate::NewSourceOperation(
+LocalFileSystemOperation* CrossOperationDelegate::NewDestOperation(
const FileSystemURL& url) {
if (same_file_system_)
- return NewDestOperation(url);
+ return NewSourceOperation(url);
base::PlatformFileError error = base::PLATFORM_FILE_OK;
FileSystemOperation* operation = file_system_context()->
@@ -259,11 +243,10 @@ LocalFileSystemOperation* CrossOperationDelegate::NewSourceOperation(
LocalFileSystemOperation* local_operation =
operation->AsLocalFileSystemOperation();
DCHECK(local_operation);
- DCHECK(src_root_operation_);
// Let the new operation inherit from the root operation.
local_operation->set_overriding_operation_context(
- src_root_operation_->operation_context());
+ dest_root_operation_->operation_context());
return local_operation;
}
diff --git a/webkit/fileapi/cross_operation_delegate.h b/webkit/fileapi/cross_operation_delegate.h
index 3be003a..5209045 100644
--- a/webkit/fileapi/cross_operation_delegate.h
+++ b/webkit/fileapi/cross_operation_delegate.h
@@ -8,6 +8,7 @@
#include <stack>
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "webkit/fileapi/recursive_operation_delegate.h"
namespace webkit_blob {
@@ -26,11 +27,13 @@ class CrossOperationDelegate
OPERATION_MOVE
};
- CrossOperationDelegate(LocalFileSystemOperation* original_operation,
- const FileSystemURL& src_root,
- const FileSystemURL& dest_root,
- OperationType operation_type,
- const StatusCallback& callback);
+ CrossOperationDelegate(
+ LocalFileSystemOperation* src_root_operation,
+ LocalFileSystemOperation* dest_root_operation,
+ const FileSystemURL& src_root,
+ const FileSystemURL& dest_root,
+ OperationType operation_type,
+ const StatusCallback& callback);
virtual ~CrossOperationDelegate();
// RecursiveOperationDelegate overrides:
@@ -71,17 +74,14 @@ class CrossOperationDelegate
// When the creation fails it fires callback_ with the
// error code and returns NULL.
//
- // - NewDestOperation is basically a thin wrapper of
+ // - NewSourceOperation is basically a thin wrapper of
// RecursiveOperationDelegate::NewOperation().
- // (Since the original_operation must have been created for the destination
- // URL. TODO(kinuko): we should have some assertion for this assumption)
- //
- // - NewSourceOperation also redirects the request to
+ // - NewDestOperation also redirects the request to
// RecursiveOperationDelegate::NewOperation() **iff** same_file_system_
// is true.
// Otherwise it's for cross-filesystem operation and it needs a
// separate FileSystemOperationContext, so it creates a new operation
- // which inherits context from src_root_operation_.
+ // which inherits context from dest_root_operation_.
//
LocalFileSystemOperation* NewSourceOperation(const FileSystemURL& url);
LocalFileSystemOperation* NewDestOperation(const FileSystemURL& url);
@@ -92,7 +92,7 @@ class CrossOperationDelegate
OperationType operation_type_;
StatusCallback callback_;
- LocalFileSystemOperation* src_root_operation_;
+ scoped_ptr<LocalFileSystemOperation> dest_root_operation_;
scoped_refptr<webkit_blob::ShareableFileReference> current_file_ref_;
diff --git a/webkit/fileapi/local_file_system_operation.cc b/webkit/fileapi/local_file_system_operation.cc
index c5f4e1a..535e010 100644
--- a/webkit/fileapi/local_file_system_operation.cc
+++ b/webkit/fileapi/local_file_system_operation.cc
@@ -30,43 +30,11 @@ using webkit_blob::ShareableFileReference;
namespace fileapi {
-namespace {
-
-bool IsMediaFileSystemType(FileSystemType type) {
- return type == kFileSystemTypeNativeMedia ||
- type == kFileSystemTypeDeviceMedia;
-}
-
-} // namespace
-
-// LocalFileSystemOperation::ScopedUpdateNotifier -----------------------------
-
-class LocalFileSystemOperation::ScopedUpdateNotifier {
- public:
- ScopedUpdateNotifier(FileSystemOperationContext* operation_context,
- const FileSystemURL& url);
- ~ScopedUpdateNotifier();
-
- private:
- UpdateObserverList update_observers_;
- FileSystemURL url_;
- DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier);
-};
-
-LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier(
- FileSystemOperationContext* operation_context,
- const FileSystemURL& url)
- : update_observers_(*operation_context->update_observers()), url_(url) {
- update_observers_.Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url_));
-}
-
-LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() {
- update_observers_.Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(url_));
-}
-
-// LocalFileSystemOperation ---------------------------------------------------
-
LocalFileSystemOperation::~LocalFileSystemOperation() {
+ if (write_target_url_.is_valid()) {
+ operation_context()->update_observers()->Notify(
+ &FileUpdateObserver::OnEndUpdate, MakeTuple(write_target_url_));
+ }
if (!termination_callback_.is_null())
termination_callback_.Run();
}
@@ -76,7 +44,7 @@ void LocalFileSystemOperation::CreateFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateFile));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -96,7 +64,7 @@ void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateDirectory));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -114,17 +82,39 @@ void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy));
- base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_WRITE);
+ // Setting up this (source) operation.
+ base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
+ // Setting up a new operation for dest.
+ base::PlatformFileError error = base::PLATFORM_FILE_OK;
+ FileSystemOperation* operation =
+ file_system_context()->CreateFileSystemOperation(dest_url, &error);
+ if (error != base::PLATFORM_FILE_OK) {
+ DCHECK(!operation);
+ callback.Run(error);
+ delete this;
+ return;
+ }
+ LocalFileSystemOperation* dest_operation =
+ operation->AsLocalFileSystemOperation();
+ DCHECK(dest_operation);
+ result = dest_operation->SetUp(dest_url, OPERATION_MODE_WRITE);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
+ delete dest_operation;
+ delete this;
+ return;
+ }
+
DCHECK(!recursive_operation_delegate_);
recursive_operation_delegate_.reset(
new CrossOperationDelegate(
- this, src_url, dest_url,
+ this, dest_operation, src_url, dest_url,
CrossOperationDelegate::OPERATION_COPY,
base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation,
base::Unretained(this), callback)));
@@ -136,17 +126,40 @@ void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationMove));
- base::PlatformFileError result = SetUp(src_url, SETUP_FOR_WRITE);
+ // Setting up this (source) operation.
+ base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
+ // Setting up a new operation for dest.
+ base::PlatformFileError error = base::PLATFORM_FILE_OK;
+ FileSystemOperation* operation =
+ file_system_context()->CreateFileSystemOperation(dest_url, &error);
+ if (error != base::PLATFORM_FILE_OK) {
+ DCHECK(!operation);
+ callback.Run(error);
+ delete this;
+ return;
+ }
+ LocalFileSystemOperation* dest_operation =
+ operation->AsLocalFileSystemOperation();
+ DCHECK(dest_operation);
+
+ result = dest_operation->SetUp(dest_url, OPERATION_MODE_WRITE);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
+ delete dest_operation;
+ delete this;
+ return;
+ }
+
DCHECK(!recursive_operation_delegate_);
recursive_operation_delegate_.reset(
new CrossOperationDelegate(
- this, src_url, dest_url,
+ this, dest_operation, src_url, dest_url,
CrossOperationDelegate::OPERATION_MOVE,
base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation,
base::Unretained(this), callback)));
@@ -157,7 +170,7 @@ void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationDirectoryExists));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -174,7 +187,7 @@ void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationFileExists));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -191,7 +204,7 @@ void LocalFileSystemOperation::GetMetadata(
const FileSystemURL& url, const GetMetadataCallback& callback) {
DCHECK(SetPendingOperationType(kOperationGetMetadata));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), base::FilePath());
delete this;
@@ -208,7 +221,7 @@ void LocalFileSystemOperation::ReadDirectory(
const FileSystemURL& url, const ReadDirectoryCallback& callback) {
DCHECK(SetPendingOperationType(kOperationReadDirectory));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
delete this;
@@ -226,7 +239,7 @@ void LocalFileSystemOperation::Remove(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -258,7 +271,7 @@ void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTruncate));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -277,7 +290,7 @@ void LocalFileSystemOperation::TouchFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTouchFile));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -313,13 +326,13 @@ void LocalFileSystemOperation::OpenFile(const FileSystemURL& url,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
}
} else {
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
@@ -383,7 +396,7 @@ void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url,
base::FilePath* platform_path) {
DCHECK(SetPendingOperationType(kOperationGetLocalPath));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
delete this;
return;
@@ -402,7 +415,7 @@ void LocalFileSystemOperation::CreateSnapshotFile(
const SnapshotFileCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), base::FilePath(), NULL);
delete this;
@@ -421,7 +434,7 @@ void LocalFileSystemOperation::CopyInForeignFile(
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
- base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -440,7 +453,7 @@ void LocalFileSystemOperation::RemoveFile(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -457,7 +470,7 @@ void LocalFileSystemOperation::RemoveDirectory(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -477,22 +490,15 @@ void LocalFileSystemOperation::CopyFileLocal(
DCHECK(SetPendingOperationType(kOperationCopy));
DCHECK(AreSameFileSystem(src_url, dest_url));
- base::PlatformFileError result = SetUp(src_url, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_READ);
if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, SETUP_FOR_CREATE);
+ result = SetUp(dest_url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- // Record read access for src_url.
- operation_context()->access_observers()->Notify(
- &FileAccessObserver::OnAccess, MakeTuple(src_url));
- // Record update access for dest_url.
- scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
- operation_context(), dest_url));
-
GetUsageAndQuotaThenRunTask(
dest_url,
base::Bind(&LocalFileSystemOperation::DoCopyFileLocal,
@@ -507,19 +513,15 @@ void LocalFileSystemOperation::MoveFileLocal(
DCHECK(SetPendingOperationType(kOperationMove));
DCHECK(AreSameFileSystem(src_url, dest_url));
- base::PlatformFileError result = SetUp(src_url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_WRITE);
if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, SETUP_FOR_CREATE);
+ result = SetUp(dest_url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- // Record update access for dest_url.
- scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
- operation_context(), dest_url));
-
GetUsageAndQuotaThenRunTask(
dest_url,
base::Bind(&LocalFileSystemOperation::DoMoveFileLocal,
@@ -587,7 +589,7 @@ base::Closure LocalFileSystemOperation::GetWriteClosure(
const WriteCallback& callback) {
DCHECK(SetPendingOperationType(kOperationWrite));
- base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE);
if (result != base::PLATFORM_FILE_OK) {
return base::Bind(&LocalFileSystemOperation::DidFailWrite,
base::Owned(this), callback, result);
@@ -832,7 +834,7 @@ void LocalFileSystemOperation::DidCreateSnapshotFile(
base::PlatformFileError LocalFileSystemOperation::SetUp(
const FileSystemURL& url,
- SetUpMode mode) {
+ OperationMode mode) {
DCHECK(url.is_valid());
async_file_util_ = file_system_context()->GetAsyncFileUtil(url.type());
@@ -845,14 +847,17 @@ base::PlatformFileError LocalFileSystemOperation::SetUp(
if (overriding_operation_context_)
return base::PLATFORM_FILE_OK;
- // Notify / set up observers.
- if (mode == SETUP_FOR_READ) {
- operation_context()->access_observers()->Notify(
- &FileAccessObserver::OnAccess, MakeTuple(url));
- } else {
- DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE);
- scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
- operation_context(), url));
+ switch (mode) {
+ case OPERATION_MODE_READ:
+ operation_context()->access_observers()->Notify(
+ &FileAccessObserver::OnAccess, MakeTuple(url));
+ break;
+ case OPERATION_MODE_WRITE:
+ operation_context()->update_observers()->Notify(
+ &FileUpdateObserver::OnStartUpdate, MakeTuple(url));
+ DCHECK(!write_target_url_.is_valid());
+ write_target_url_ = url;
+ break;
}
return base::PLATFORM_FILE_OK;
diff --git a/webkit/fileapi/local_file_system_operation.h b/webkit/fileapi/local_file_system_operation.h
index fd66acd..8df01c9 100644
--- a/webkit/fileapi/local_file_system_operation.h
+++ b/webkit/fileapi/local_file_system_operation.h
@@ -153,15 +153,13 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
const StatusCallback& callback);
// Synchronously gets the platform path for the given |url|.
- void SyncGetPlatformPath(const FileSystemURL& url, base::FilePath* platform_path);
+ void SyncGetPlatformPath(const FileSystemURL& url,
+ base::FilePath* platform_path);
private:
- class ScopedUpdateNotifier;
-
- enum SetUpMode {
- SETUP_FOR_READ,
- SETUP_FOR_WRITE,
- SETUP_FOR_CREATE,
+ enum OperationMode {
+ OPERATION_MODE_READ,
+ OPERATION_MODE_WRITE,
};
// Only MountPointProviders or testing class can create a
@@ -301,7 +299,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
// Checks the validity of a given |url| and populates |file_util| for |mode|.
base::PlatformFileError SetUp(
const FileSystemURL& url,
- SetUpMode mode);
+ OperationMode mode);
// Used only for internal assertions.
// Returns false if there's another inflight pending operation.
@@ -333,10 +331,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
// A callback that is called when this instance goes away.
base::Closure termination_callback_;
- // This is set before any write operations to dispatch
- // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate.
- ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_;
-
// These are all used only by Write().
friend class FileWriterDelegate;
scoped_ptr<FileWriterDelegate> file_writer_delegate_;
@@ -357,6 +351,10 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
// A flag to make sure we call operation only once per instance.
OperationType pending_operation_;
+ // We keep track of the file to be modified by this operation so that
+ // we can notify observers when we're done.
+ FileSystemURL write_target_url_;
+
// LocalFileSystemOperation instance is usually deleted upon completion but
// could be deleted while it has inflight callbacks when Cancel is called.
base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_;