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