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

Unified Diff: chrome/browser/file_system/file_system_backend.cc

Issue 3212002: Changes for browser-side implementation for file api.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months 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: chrome/browser/file_system/file_system_backend.cc
===================================================================
--- chrome/browser/file_system/file_system_backend.cc (revision 0)
+++ chrome/browser/file_system/file_system_backend.cc (revision 0)
@@ -0,0 +1,188 @@
+// Copyright (c) 2010 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 "base/file_util_proxy.h"
+#include "base/platform_file.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/file_system/file_system_backend.h"
+#include "chrome/browser/file_system/file_system_backend_client.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
+
+namespace {
+// Utility method for error conversions.
+WebKit::WebFileError PlatformToWebkitError(base::PlatformFileError rv) {
+ switch (rv) {
+ case base::PLATFORM_FILE_ERROR_NOT_FOUND:
+ return WebKit::WebFileErrorNotFound;
+ case base::PLATFORM_FILE_ERROR_INVALID_OPERATION:
+ case base::PLATFORM_FILE_ERROR_EXISTS:
+ case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
+ return WebKit::WebFileErrorInvalidModification;
+ case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
+ return WebKit::WebFileErrorInvalidModification;
+ default:
+ return WebKit::WebFileErrorNoModificationAllowed;
+ }
+}
+} // namespace
+
+FileSystemBackend::FileSystemBackend()
+ : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
+
+void FileSystemBackend::set_client(FileSystemBackendClient* client) {
+ client_ = client;
+}
+
+void FileSystemBackend::CreateFile(const FilePath& path,
+ bool exclusive,
+ int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::CreateOrOpen(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, base::PLATFORM_FILE_CREATE,
+ callback_factory_.NewCallback(
+ exclusive ? &FileSystemBackend::DidCreateFileExclusive
+ : &FileSystemBackend::DidCreateFileNonExclusive));
+}
+
+void FileSystemBackend::CreateDirectory(const FilePath& path,
+ bool exclusive,
+ int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::CreateDirectory(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, exclusive, callback_factory_.NewCallback(
+ &FileSystemBackend::DidFinishFileOperation));
+}
+
+void FileSystemBackend::Copy(const FilePath& src_path,
+ const FilePath& dest_path,
+ int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::Copy(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ src_path, dest_path, callback_factory_.NewCallback(
+ &FileSystemBackend::DidFinishFileOperation));
+}
+
+void FileSystemBackend::Move(const FilePath& src_path,
+ const FilePath& dest_path,
+ int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::Move(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ src_path, dest_path, callback_factory_.NewCallback(
+ &FileSystemBackend::DidFinishFileOperation));
+}
+
+void FileSystemBackend::DirectoryExists(const FilePath& path, int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::GetFileInfo(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, callback_factory_.NewCallback(
+ &FileSystemBackend::DidDirectoryExists));
+}
+
+void FileSystemBackend::FileExists(const FilePath& path, int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::GetFileInfo(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, callback_factory_.NewCallback(&FileSystemBackend::DidFileExists));
+}
+
+void FileSystemBackend::GetMetadata(const FilePath& path, int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::GetFileInfo(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, callback_factory_.NewCallback(&FileSystemBackend::DidGetMetadata));
+}
+
+void FileSystemBackend::ReadDirectory(
+ const FilePath& path, int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::ReadDirectory(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, callback_factory_.NewCallback(
+ &FileSystemBackend::DidReadDirectory));
+}
+
+void FileSystemBackend::Remove(const FilePath& path, int request_id) {
+ request_id_ = request_id;
+ base::FileUtilProxy::Delete(
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ path, callback_factory_.NewCallback(
+ &FileSystemBackend::DidFinishFileOperation));
+}
+
+void FileSystemBackend::DidCreateFileExclusive(base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created) {
+ DidFinishFileOperation(rv);
+}
+
+void FileSystemBackend::DidCreateFileNonExclusive(base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created) {
+ // Supress the already exists error and report success.
+ if (rv == base::PLATFORM_FILE_OK ||
+ rv == base::PLATFORM_FILE_ERROR_EXISTS)
+ client_->DidSucceed(rv);
+ else
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+}
+
+void FileSystemBackend::DidFinishFileOperation(base::PlatformFileError rv) {
+ DCHECK(client_);
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidSucceed(request_id_);
+ else
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+}
+
+void FileSystemBackend::DidDirectoryExists(
+ base::PlatformFileError rv, const file_util::FileInfo& file_info) {
+ DCHECK(client_);
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ client_->DidSucceed(request_id_);
+ else
+ client_->DidFail(WebKit::WebFileErrorInvalidState, request_id_);
+ } else {
+ // Something else went wrong.
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+ }
+}
+
+void FileSystemBackend::DidFileExists(base::PlatformFileError rv,
+ const file_util::FileInfo& file_info) {
+ DCHECK(client_);
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ client_->DidFail(WebKit::WebFileErrorInvalidState, request_id_);
+ else
+ client_->DidSucceed(request_id_);
+ } else {
+ // Something else went wrong.
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+ }
+}
+
+void FileSystemBackend::DidGetMetadata(base::PlatformFileError rv,
+ const file_util::FileInfo& file_info) {
+ DCHECK(client_);
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidReadMetadata(file_info, request_id_);
+ else
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+}
+
+void FileSystemBackend::DidReadDirectory(
+ base::PlatformFileError rv,
+ const std::vector<base::file_util_proxy::Entry>& entries) {
+ DCHECK(client_);
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidReadDirectory(entries, false /* has_more */ , request_id_);
+ else
+ client_->DidFail(PlatformToWebkitError(rv), request_id_);
+}

Powered by Google App Engine
This is Rietveld 408576698