Commit 24391300 authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

[fsp] Remove the create flag from the file opening operation.

This CL removes the create flag, and makes the Open operation fail if a file
doesn't exist. This is because a separate event for creating files is coming
soon.

TEST=unit_tests, browser_tests: *FileSystemProvider*Open*, *FileSystemProvider*ReadFile*
BUG=391362

Review URL: https://codereview.chromium.org/379743003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282033 0039d316-1c4b-4281-b951-d872f2087c98
parent d33d0b27
...@@ -142,9 +142,8 @@ void FakeProvidedFileSystem::ReadDirectory( ...@@ -142,9 +142,8 @@ void FakeProvidedFileSystem::ReadDirectory(
void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path, void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path,
OpenFileMode mode, OpenFileMode mode,
bool create,
const OpenFileCallback& callback) { const OpenFileCallback& callback) {
if (mode == OPEN_FILE_MODE_WRITE || create) { if (mode == OPEN_FILE_MODE_WRITE) {
base::MessageLoopProxy::current()->PostTask( base::MessageLoopProxy::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(callback, base::Bind(callback,
......
...@@ -48,7 +48,6 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -48,7 +48,6 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
virtual void OpenFile(const base::FilePath& file_path, virtual void OpenFile(const base::FilePath& file_path,
OpenFileMode mode, OpenFileMode mode,
bool create,
const OpenFileCallback& callback) OVERRIDE; const OpenFileCallback& callback) OVERRIDE;
virtual void CloseFile( virtual void CloseFile(
int file_handle, int file_handle,
......
...@@ -49,7 +49,6 @@ void OpenFileOnUIThread( ...@@ -49,7 +49,6 @@ void OpenFileOnUIThread(
parser.file_system()->OpenFile( parser.file_system()->OpenFile(
parser.file_path(), parser.file_path(),
ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
false /* create */,
base::Bind( base::Bind(
callback, parser.file_system()->GetWeakPtr(), parser.file_path())); callback, parser.file_system()->GetWeakPtr(), parser.file_path()));
} }
......
...@@ -18,12 +18,10 @@ OpenFile::OpenFile( ...@@ -18,12 +18,10 @@ OpenFile::OpenFile(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& file_path, const base::FilePath& file_path,
ProvidedFileSystemInterface::OpenFileMode mode, ProvidedFileSystemInterface::OpenFileMode mode,
bool create,
const ProvidedFileSystemInterface::OpenFileCallback& callback) const ProvidedFileSystemInterface::OpenFileCallback& callback)
: Operation(event_router, file_system_info), : Operation(event_router, file_system_info),
file_path_(file_path), file_path_(file_path),
mode_(mode), mode_(mode),
create_(create),
callback_(callback) { callback_(callback) {
} }
...@@ -49,8 +47,6 @@ bool OpenFile::Execute(int request_id) { ...@@ -49,8 +47,6 @@ bool OpenFile::Execute(int request_id) {
break; break;
} }
values->SetBoolean("create", create_);
return SendEvent( return SendEvent(
request_id, request_id,
extensions::api::file_system_provider::OnOpenFileRequested::kEventName, extensions::api::file_system_provider::OnOpenFileRequested::kEventName,
......
...@@ -25,16 +25,14 @@ namespace chromeos { ...@@ -25,16 +25,14 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace operations { namespace operations {
// Opens a file for either read or write, with optionally creating the file // Opens a file for either read or write. The file must exist, otherwise the
// first. Note, that this is part of fileapi::CreateOrOpen file, but it does // operation will fail. Created per request.
// not download the file locally. Created per request.
class OpenFile : public Operation { class OpenFile : public Operation {
public: public:
OpenFile(extensions::EventRouter* event_router, OpenFile(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& file_path, const base::FilePath& file_path,
ProvidedFileSystemInterface::OpenFileMode mode, ProvidedFileSystemInterface::OpenFileMode mode,
bool create,
const ProvidedFileSystemInterface::OpenFileCallback& callback); const ProvidedFileSystemInterface::OpenFileCallback& callback);
virtual ~OpenFile(); virtual ~OpenFile();
...@@ -50,7 +48,6 @@ class OpenFile : public Operation { ...@@ -50,7 +48,6 @@ class OpenFile : public Operation {
private: private:
base::FilePath file_path_; base::FilePath file_path_;
ProvidedFileSystemInterface::OpenFileMode mode_; ProvidedFileSystemInterface::OpenFileMode mode_;
bool create_;
const ProvidedFileSystemInterface::OpenFileCallback callback_; const ProvidedFileSystemInterface::OpenFileCallback callback_;
DISALLOW_COPY_AND_ASSIGN(OpenFile); DISALLOW_COPY_AND_ASSIGN(OpenFile);
......
...@@ -90,7 +90,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) { ...@@ -90,7 +90,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) {
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kFilePath), base::FilePath::FromUTF8Unsafe(kFilePath),
ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
false /* create */,
base::Bind(&CallbackLogger::OnOpenFile, base::Bind(&CallbackLogger::OnOpenFile,
base::Unretained(&callback_logger))); base::Unretained(&callback_logger)));
open_file.SetDispatchEventImplForTesting( open_file.SetDispatchEventImplForTesting(
...@@ -128,10 +127,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) { ...@@ -128,10 +127,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) {
extensions::api::file_system_provider::ToString( extensions::api::file_system_provider::ToString(
extensions::api::file_system_provider::OPEN_FILE_MODE_READ); extensions::api::file_system_provider::OPEN_FILE_MODE_READ);
EXPECT_EQ(expected_file_open_mode, event_file_open_mode); EXPECT_EQ(expected_file_open_mode, event_file_open_mode);
bool event_create;
EXPECT_TRUE(options->GetBoolean("create", &event_create));
EXPECT_FALSE(event_create);
} }
TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) { TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) {
...@@ -142,7 +137,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) { ...@@ -142,7 +137,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) {
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kFilePath), base::FilePath::FromUTF8Unsafe(kFilePath),
ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
false /* create */,
base::Bind(&CallbackLogger::OnOpenFile, base::Bind(&CallbackLogger::OnOpenFile,
base::Unretained(&callback_logger))); base::Unretained(&callback_logger)));
open_file.SetDispatchEventImplForTesting( open_file.SetDispatchEventImplForTesting(
...@@ -160,7 +154,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { ...@@ -160,7 +154,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) {
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kFilePath), base::FilePath::FromUTF8Unsafe(kFilePath),
ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
false /* create */,
base::Bind(&CallbackLogger::OnOpenFile, base::Bind(&CallbackLogger::OnOpenFile,
base::Unretained(&callback_logger))); base::Unretained(&callback_logger)));
open_file.SetDispatchEventImplForTesting( open_file.SetDispatchEventImplForTesting(
...@@ -186,7 +179,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) { ...@@ -186,7 +179,6 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) {
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kFilePath), base::FilePath::FromUTF8Unsafe(kFilePath),
ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
false /* create */,
base::Bind(&CallbackLogger::OnOpenFile, base::Bind(&CallbackLogger::OnOpenFile,
base::Unretained(&callback_logger))); base::Unretained(&callback_logger)));
open_file.SetDispatchEventImplForTesting( open_file.SetDispatchEventImplForTesting(
......
...@@ -99,11 +99,9 @@ void ProvidedFileSystem::ReadFile(int file_handle, ...@@ -99,11 +99,9 @@ void ProvidedFileSystem::ReadFile(int file_handle,
void ProvidedFileSystem::OpenFile(const base::FilePath& file_path, void ProvidedFileSystem::OpenFile(const base::FilePath& file_path,
OpenFileMode mode, OpenFileMode mode,
bool create,
const OpenFileCallback& callback) { const OpenFileCallback& callback) {
// Writing is not supported. Note, that this includes a situation, when a file // Writing is not supported.
// exists, but |create| is set to true. if (mode == OPEN_FILE_MODE_WRITE) {
if (mode == OPEN_FILE_MODE_WRITE || create) {
callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY);
return; return;
} }
...@@ -115,7 +113,6 @@ void ProvidedFileSystem::OpenFile(const base::FilePath& file_path, ...@@ -115,7 +113,6 @@ void ProvidedFileSystem::OpenFile(const base::FilePath& file_path,
file_system_info_, file_system_info_,
file_path, file_path,
mode, mode,
create,
callback)))) { callback)))) {
callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY);
} }
......
...@@ -48,7 +48,6 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -48,7 +48,6 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
virtual void OpenFile(const base::FilePath& file_path, virtual void OpenFile(const base::FilePath& file_path,
OpenFileMode mode, OpenFileMode mode,
bool create,
const OpenFileCallback& callback) OVERRIDE; const OpenFileCallback& callback) OVERRIDE;
virtual void CloseFile( virtual void CloseFile(
int file_handle, int file_handle,
......
...@@ -78,11 +78,10 @@ class ProvidedFileSystemInterface { ...@@ -78,11 +78,10 @@ class ProvidedFileSystemInterface {
const base::FilePath& directory_path, const base::FilePath& directory_path,
const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) = 0; const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) = 0;
// Requests opening a file at |file_path|. If |create| is set to true, it will // Requests opening a file at |file_path|. If the file doesn't exist, then the
// create a file and return success in case it didn't exist. // operation will fail.
virtual void OpenFile(const base::FilePath& file_path, virtual void OpenFile(const base::FilePath& file_path,
OpenFileMode mode, OpenFileMode mode,
bool create,
const OpenFileCallback& callback) = 0; const OpenFileCallback& callback) = 0;
// Requests closing a file, previously opened with OpenFile() as a file with // Requests closing a file, previously opened with OpenFile() as a file with
......
...@@ -90,7 +90,6 @@ namespace fileSystemProvider { ...@@ -90,7 +90,6 @@ namespace fileSystemProvider {
long requestId; long requestId;
DOMString filePath; DOMString filePath;
OpenFileMode mode; OpenFileMode mode;
boolean create;
}; };
// Options for the <code>onCloseFileRequested()</code> event. // Options for the <code>onCloseFileRequested()</code> event.
...@@ -195,9 +194,8 @@ namespace fileSystemProvider { ...@@ -195,9 +194,8 @@ namespace fileSystemProvider {
EntriesCallback successCallback, EntriesCallback successCallback,
ProviderErrorCallback errorCallback); ProviderErrorCallback errorCallback);
// Raised when opening a file at <code>filePath</code> is requested. // Raised when opening a file at <code>filePath</code> is requested. If the
// If <code>create</code> is set to <code>true</code> and the file does not // file does not exist, then the operation must fail.
// exist, then it should be created.
[maxListeners=1] static void onOpenFileRequested( [maxListeners=1] static void onOpenFileRequested(
OpenFileRequestedOptions options, OpenFileRequestedOptions options,
ProviderSuccessCallback successCallback, ProviderSuccessCallback successCallback,
......
...@@ -54,7 +54,7 @@ function onOpenFileRequested(options, onSuccess, onError) { ...@@ -54,7 +54,7 @@ function onOpenFileRequested(options, onSuccess, onError) {
return; return;
} }
if (options.mode != 'READ' || options.create) { if (options.mode != 'READ') {
onError('ACCESS_DENIED'); // enum ProviderError. onError('ACCESS_DENIED'); // enum ProviderError.
return; return;
} }
......
...@@ -78,7 +78,7 @@ function onOpenFileRequested(options, onSuccess, onError) { ...@@ -78,7 +78,7 @@ function onOpenFileRequested(options, onSuccess, onError) {
return; return;
} }
if (options.mode != 'READ' || options.create) { if (options.mode != 'READ') {
onError('ACCESS_DENIED'); // enum ProviderError. onError('ACCESS_DENIED'); // enum ProviderError.
return; return;
} }
......
...@@ -57,7 +57,7 @@ var TESTING_BROKEN_TIRAMISU_FILE = Object.freeze({ ...@@ -57,7 +57,7 @@ var TESTING_BROKEN_TIRAMISU_FILE = Object.freeze({
*/ */
function onOpenFileRequested(options, onSuccess, onError) { function onOpenFileRequested(options, onSuccess, onError) {
if (options.fileSystemId != test_util.FILE_SYSTEM_ID || if (options.fileSystemId != test_util.FILE_SYSTEM_ID ||
options.mode != 'READ' || options.create) { options.mode != 'READ') {
onError('SECURITY'); // enum ProviderError. onError('SECURITY'); // enum ProviderError.
return; return;
} }
......
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