Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Unified Diff: webkit/chromeos/fileapi/file_util_async.cc

Issue 8907014: Implement async verision of FileSystemFileUtil and in-memory file system for testing purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Read() and Write() from FileUtilAsync Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/chromeos/fileapi/file_util_async.cc
diff --git a/webkit/chromeos/fileapi/file_util_async.cc b/webkit/chromeos/fileapi/file_util_async.cc
new file mode 100644
index 0000000000000000000000000000000000000000..408528f27a7d4ad307140fde0fc40fa989aef19c
--- /dev/null
+++ b/webkit/chromeos/fileapi/file_util_async.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/chromeos/fileapi/file_util_async.h"
+
+#include "base/bind.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop.h"
+
+namespace fileapi {
+
+FileUtilAsync::FileUtilAsync() {
+}
+
+// Depending on the flags value the flow of file opening will be one of
+// the following:
+//
+// PLATFORM_FILE_OPEN:
+// GetFileInfo
+// DidGetFileInfoForOpen
+// OpenVerifiedFile
+//
+// PLATFORM_FILE_CREATE:
+// Create
+// DidCreateOrTruncateForOpen
+// OpenVerifiedFile
+//
+// PLATFORM_FILE_OPEN_ALWAYS:
+// GetFileInfo
+// DidGetFileInfoForOpen
+// OpenVerifiedFile OR Create
+// DidCreateOrTruncateForOpen
+// OpenVerifiedFile
+//
+// PLATFORM_FILE_CREATE_ALWAYS:
+// Truncate
+// OpenTruncatedFileOrCreate
+// OpenVerifiedFile OR Create
+// DidCreateOrTruncateForOpen
+// OpenVerifiedFile
+//
+// PLATFORM_FILE_OPEN_TRUNCATED:
+// Truncate
+// DidCreateOrTruncateForOpen
+// OpenVerifiedFile
+//
+void FileUtilAsync::Open(
satorux1 2011/12/14 08:42:29 She was doubtful of having the default implementat
satorux1 2011/12/14 08:55:32 Moved to MemoryFileUtil.
Oleg Eterevsky 2011/12/14 15:20:59 To be honest, I'm not sure about this. Having the
+ const FilePath& file_path,
+ int flags,
+ const OpenCallback& callback) {
+ int create_flag = flags & (base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_CREATE |
+ base::PLATFORM_FILE_OPEN_ALWAYS |
+ base::PLATFORM_FILE_CREATE_ALWAYS |
+ base::PLATFORM_FILE_OPEN_TRUNCATED);
+ switch (create_flag) {
+ case base::PLATFORM_FILE_OPEN:
+ case base::PLATFORM_FILE_OPEN_ALWAYS:
+ GetFileInfo(
+ file_path,
+ base::Bind(&FileUtilAsync::DidGetFileInfoForOpen,
+ base::Unretained(this), file_path, flags, callback));
+
+ break;
+
+ case base::PLATFORM_FILE_CREATE:
+ Create(
+ file_path,
+ base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
+ base::Unretained(this), file_path, flags, 0, callback));
+ break;
+
+ case base::PLATFORM_FILE_CREATE_ALWAYS:
+ Truncate(
+ file_path,
+ 0,
+ base::Bind(&FileUtilAsync::OpenTruncatedFileOrCreate,
+ base::Unretained(this), file_path, flags, callback));
+
+ case base::PLATFORM_FILE_OPEN_TRUNCATED:
+ Truncate(
+ file_path,
+ 0,
+ base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
+ base::Unretained(this), file_path, flags, 0, callback));
+ break;
+
+ default:
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ base::PLATFORM_FILE_ERROR_INVALID_OPERATION,
+ static_cast<AsyncFileStream*>(NULL)));
+ }
+}
+
+void FileUtilAsync::DidGetFileInfoForOpen(
+ const FilePath& file_path,
+ int flags,
+ const OpenCallback& callback,
+ PlatformFileError get_info_result,
+ const base::PlatformFileInfo& file_info) {
+ if (get_info_result == base::PLATFORM_FILE_OK && file_info.is_directory) {
+ callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE, NULL);
+ return;
+ }
+
+ if (get_info_result == base::PLATFORM_FILE_OK) {
+ OpenVerifiedFile(file_path, flags, callback);
+ return;
+ }
+
+ if (get_info_result == base::PLATFORM_FILE_ERROR_NOT_FOUND &&
+ flags & base::PLATFORM_FILE_CREATE_ALWAYS) {
+ Create(file_path,
+ base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
+ base::Unretained(this), file_path, flags, 0, callback));
+ return;
+ }
+
+ callback.Run(get_info_result, NULL);
+}
+
+void FileUtilAsync::OpenTruncatedFileOrCreate(
+ const FilePath& file_path,
+ int flags,
+ const OpenCallback& callback,
+ PlatformFileError result) {
+ if (result == base::PLATFORM_FILE_OK) {
+ OpenVerifiedFile(file_path, flags, callback);
+ return;
+ }
+
+ if (result == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
+ Create(
+ file_path,
+ base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
+ base::Unretained(this), file_path, flags, 0, callback));
+ return;
+ }
+
+ callback.Run(result, NULL);
+}
+
+void FileUtilAsync::DidCreateOrTruncateForOpen(
+ const FilePath& file_path,
+ int flags,
+ int64 size,
+ const OpenCallback& callback,
+ PlatformFileError result) {
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, NULL);
+ return;
+ }
+
+ OpenVerifiedFile(file_path, flags, callback);
+}
+
+} // namespace fileapi

Powered by Google App Engine
This is Rietveld 408576698