diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 02:28:37 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 02:28:37 +0000 |
commit | 2f0193c279b1b40a82a6ad027ec9468272eb25b2 (patch) | |
tree | 9d2e2f5bcf09837a1189723567906fb8de45c7e2 /chrome/browser/file_system | |
parent | 4c56ef5fbed46794f2b16b9f8ed88ac179d65309 (diff) | |
download | chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.zip chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.tar.gz chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.tar.bz2 |
Moving file_util::FileInfo to base::PlatformFileInfo, and adding the
last_accessed and creation_time fields.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3347005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/file_system')
-rw-r--r-- | chrome/browser/file_system/file_system_backend.cc | 378 | ||||
-rw-r--r-- | chrome/browser/file_system/file_system_backend.h | 6 | ||||
-rw-r--r-- | chrome/browser/file_system/file_system_backend_client.h | 2 |
3 files changed, 194 insertions, 192 deletions
diff --git a/chrome/browser/file_system/file_system_backend.cc b/chrome/browser/file_system/file_system_backend.cc index 36b1005..12847ed 100644 --- a/chrome/browser/file_system/file_system_backend.cc +++ b/chrome/browser/file_system/file_system_backend.cc @@ -1,188 +1,190 @@ -// 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_);
-}
+// 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 base::PlatformFileInfo& 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 base::PlatformFileInfo& 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 base::PlatformFileInfo& 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_); +} diff --git a/chrome/browser/file_system/file_system_backend.h b/chrome/browser/file_system/file_system_backend.h index 9b33afb..5ee511a 100644 --- a/chrome/browser/file_system/file_system_backend.h +++ b/chrome/browser/file_system/file_system_backend.h @@ -59,13 +59,13 @@ class FileSystemBackend { void DidFinishFileOperation(base::PlatformFileError rv); void DidDirectoryExists(base::PlatformFileError rv, - const file_util::FileInfo& file_info); + const base::PlatformFileInfo& file_info); void DidFileExists(base::PlatformFileError rv, - const file_util::FileInfo& file_info); + const base::PlatformFileInfo& file_info); void DidGetMetadata(base::PlatformFileError rv, - const file_util::FileInfo& file_info); + const base::PlatformFileInfo& file_info); void DidReadDirectory( base::PlatformFileError rv, diff --git a/chrome/browser/file_system/file_system_backend_client.h b/chrome/browser/file_system/file_system_backend_client.h index 6da0bc2..ad969ab1 100644 --- a/chrome/browser/file_system/file_system_backend_client.h +++ b/chrome/browser/file_system/file_system_backend_client.h @@ -20,7 +20,7 @@ class FileSystemBackendClient { virtual void DidSucceed(int request_id) = 0; // Info about the file entry such as modification date and size. - virtual void DidReadMetadata(const file_util::FileInfo& info, + virtual void DidReadMetadata(const base::PlatformFileInfo& info, int request_id) = 0; virtual void DidReadDirectory( |