[FileSystem] FileSystem Onion Soup
Moves functionality from content/renderer/fileapi to blink/renderer/modules/filesystem: - Moves most functionality in content::FileSystemDispatcher and content::WebFileSystemImpl into blink::FileSystemDispatcher - Moves all functionality in content::WebFileWriterBase to blink::FileWriterBase - Moves all functionality in content::WebFileWriterImpl to blink::FileWriter and blink::FileWriterSync - Move web_file_writer_base_test.cc to blink - Removes WebFileWriter, WebFileWriterClient, WebFileSystemCallbacks, WebFileError, WebFileInfo, WebFileSystemEntry - Makes AsyncFileSystemCallbacks and FileSystemCallbacks use base::File::Error directly instead of using blink::FileError. Bug: 787281 Change-Id: Iff0ca3e9fe20d0586709c5efbce4cd1cc79c1419 Reviewed-on: https://chromium-review.googlesource.com/1195098 Reviewed-by: Jeremy Roman <jbroman@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> Cr-Commit-Position: refs/heads/master@{#592811}
This commit is contained in:

committed by
Commit Bot

parent
4e332cde84
commit
7d88a0cd06
content
browser
fileapi
renderer
BUILD.gnfile_info_util.ccfile_info_util.h
fileapi
file_system_dispatcher.ccfile_system_dispatcher.hwebfilesystem_impl.ccwebfilesystem_impl.hwebfilewriter_base.ccwebfilewriter_base.hwebfilewriter_base_unittest.ccwebfilewriter_impl.ccwebfilewriter_impl.h
pepper
renderer_blink_platform_impl.cctest
storage/common/fileapi
third_party/blink
public
BUILD.gn
platform
web_file_error.hweb_file_info.hweb_file_system.hweb_file_system_callbacks.hweb_file_system_entry.hweb_file_writer.hweb_file_writer_client.h
web
renderer
core
fileapi
modules
BUILD.gn
exported
filesystem
BUILD.gnDEPSdirectory_reader.ccdirectory_reader.hdirectory_reader_sync.ccdirectory_reader_sync.hdom_file_system.ccdom_file_system.hdom_file_system_base.ccdom_file_system_base.hdom_file_system_sync.ccdom_file_system_sync.hdom_window_file_system.ccfile_system_callbacks.ccfile_system_callbacks.hfile_system_directory_handle.ccfile_system_directory_iterator.ccfile_system_directory_iterator.hfile_system_dispatcher.ccfile_system_dispatcher.hfile_system_file_handle.ccfile_writer.ccfile_writer.hfile_writer_base.ccfile_writer_base.hfile_writer_sync.ccfile_writer_sync.hfile_writer_test.cclocal_file_system.cclocal_file_system.hsync_callback_helper.hworker_global_scope_file_system.cc
platform
@ -744,8 +744,11 @@ void FileSystemManagerImpl::DidResolveURL(
|
||||
type == storage::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND)
|
||||
result = base::File::FILE_ERROR_NOT_FOUND;
|
||||
|
||||
base::FilePath normalized_path(
|
||||
storage::VirtualPath::GetNormalizedFilePath(file_path));
|
||||
std::move(callback).Run(
|
||||
mojo::ConvertTo<blink::mojom::FileSystemInfoPtr>(info), file_path,
|
||||
mojo::ConvertTo<blink::mojom::FileSystemInfoPtr>(info),
|
||||
std::move(normalized_path),
|
||||
type == storage::FileSystemContext::RESOLVED_ENTRY_DIRECTORY, result);
|
||||
// For ResolveURL we do not create a new operation, so no unregister here.
|
||||
}
|
||||
|
@ -109,16 +109,10 @@ target(link_target_type, "renderer") {
|
||||
"fetchers/multi_resolution_image_resource_fetcher.h",
|
||||
"fetchers/resource_fetcher_impl.cc",
|
||||
"fetchers/resource_fetcher_impl.h",
|
||||
"file_info_util.cc",
|
||||
"file_info_util.h",
|
||||
"fileapi/file_system_dispatcher.cc",
|
||||
"fileapi/file_system_dispatcher.h",
|
||||
"fileapi/webfilesystem_impl.cc",
|
||||
"fileapi/webfilesystem_impl.h",
|
||||
"fileapi/webfilewriter_base.cc",
|
||||
"fileapi/webfilewriter_base.h",
|
||||
"fileapi/webfilewriter_impl.cc",
|
||||
"fileapi/webfilewriter_impl.h",
|
||||
"frame_blame_context.cc",
|
||||
"frame_blame_context.h",
|
||||
"frame_owner_properties.cc",
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright 2014 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 "content/renderer/file_info_util.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "third_party/blink/public/platform/web_file_info.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
void FileInfoToWebFileInfo(const base::File::Info& file_info,
|
||||
blink::WebFileInfo* web_file_info) {
|
||||
DCHECK(web_file_info);
|
||||
// Blink now expects NaN as uninitialized/null Date.
|
||||
if (file_info.last_modified.is_null())
|
||||
web_file_info->modification_time = std::numeric_limits<double>::quiet_NaN();
|
||||
else
|
||||
web_file_info->modification_time = file_info.last_modified.ToJsTime();
|
||||
web_file_info->length = file_info.size;
|
||||
if (file_info.is_directory)
|
||||
web_file_info->type = blink::WebFileInfo::kTypeDirectory;
|
||||
else
|
||||
web_file_info->type = blink::WebFileInfo::kTypeFile;
|
||||
}
|
||||
|
||||
static_assert(std::numeric_limits<double>::has_quiet_NaN,
|
||||
"should have quiet NaN");
|
||||
|
||||
} // namespace content
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#ifndef CONTENT_RENDERER_FILE_INFO_UTIL_H_
|
||||
#define CONTENT_RENDERER_FILE_INFO_UTIL_H_
|
||||
|
||||
#include "base/files/file.h"
|
||||
|
||||
namespace blink {
|
||||
struct WebFileInfo;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
|
||||
// File info conversion
|
||||
void FileInfoToWebFileInfo(const base::File::Info& file_info,
|
||||
blink::WebFileInfo* web_file_info);
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_RENDERER_FILE_INFO_UTIL_H_
|
@ -23,156 +23,11 @@
|
||||
|
||||
namespace content {
|
||||
|
||||
class FileSystemDispatcher::CallbackDispatcher {
|
||||
public:
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const StatusCallback& callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->status_callback_ = callback;
|
||||
dispatcher->error_callback_ = callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const MetadataCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->metadata_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const CreateSnapshotFileCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->snapshot_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const ReadDirectoryCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->directory_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const OpenFileSystemCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->filesystem_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const ResolveURLCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->resolve_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
static std::unique_ptr<CallbackDispatcher> Create(
|
||||
const WriteCallback& callback,
|
||||
const StatusCallback& error_callback) {
|
||||
auto dispatcher = base::WrapUnique(new CallbackDispatcher);
|
||||
dispatcher->write_callback_ = callback;
|
||||
dispatcher->error_callback_ = error_callback;
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
~CallbackDispatcher() {}
|
||||
|
||||
void DidSucceed() { status_callback_.Run(base::File::FILE_OK); }
|
||||
|
||||
void DidFail(base::File::Error error_code) {
|
||||
error_callback_.Run(error_code);
|
||||
}
|
||||
|
||||
void DidReadMetadata(const base::File::Info& file_info) {
|
||||
metadata_callback_.Run(file_info);
|
||||
}
|
||||
|
||||
void DidCreateSnapshotFile(
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::Optional<blink::mojom::ReceivedSnapshotListenerPtr> opt_listener,
|
||||
int request_id) {
|
||||
snapshot_callback_.Run(file_info, platform_path, std::move(opt_listener),
|
||||
request_id);
|
||||
}
|
||||
|
||||
void DidReadDirectory(
|
||||
const std::vector<filesystem::mojom::DirectoryEntry>& entries,
|
||||
bool has_more) {
|
||||
directory_callback_.Run(entries, has_more);
|
||||
}
|
||||
|
||||
void DidOpenFileSystem(const std::string& name, const GURL& root) {
|
||||
filesystem_callback_.Run(name, root);
|
||||
}
|
||||
|
||||
void DidResolveURL(const storage::FileSystemInfo& info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory) {
|
||||
resolve_callback_.Run(info, file_path, is_directory);
|
||||
}
|
||||
|
||||
void DidWrite(int64_t bytes, bool complete) {
|
||||
write_callback_.Run(bytes, complete);
|
||||
}
|
||||
|
||||
private:
|
||||
CallbackDispatcher() {}
|
||||
|
||||
StatusCallback status_callback_;
|
||||
MetadataCallback metadata_callback_;
|
||||
CreateSnapshotFileCallback snapshot_callback_;
|
||||
ReadDirectoryCallback directory_callback_;
|
||||
OpenFileSystemCallback filesystem_callback_;
|
||||
ResolveURLCallback resolve_callback_;
|
||||
WriteCallback write_callback_;
|
||||
|
||||
StatusCallback error_callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
|
||||
};
|
||||
|
||||
class FileSystemDispatcher::FileSystemOperationListenerImpl
|
||||
: public blink::mojom::FileSystemOperationListener {
|
||||
public:
|
||||
FileSystemOperationListenerImpl(int request_id,
|
||||
FileSystemDispatcher* dispatcher)
|
||||
: request_id_(request_id), dispatcher_(dispatcher) {}
|
||||
|
||||
private:
|
||||
// blink::mojom::FileSystemOperationListener
|
||||
void ResultsRetrieved(
|
||||
std::vector<filesystem::mojom::DirectoryEntryPtr> entries,
|
||||
bool has_more) override;
|
||||
void ErrorOccurred(base::File::Error error_code) override;
|
||||
void DidWrite(int64_t byte_count, bool complete) override;
|
||||
|
||||
const int request_id_;
|
||||
FileSystemDispatcher* const dispatcher_;
|
||||
};
|
||||
|
||||
FileSystemDispatcher::FileSystemDispatcher(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
|
||||
: main_thread_task_runner_(std::move(main_thread_task_runner)) {}
|
||||
|
||||
FileSystemDispatcher::~FileSystemDispatcher() {
|
||||
// Make sure we fire all the remaining callbacks.
|
||||
for (base::IDMap<std::unique_ptr<CallbackDispatcher>>::iterator iter(
|
||||
&dispatchers_);
|
||||
!iter.IsAtEnd(); iter.Advance()) {
|
||||
int request_id = iter.GetCurrentKey();
|
||||
CallbackDispatcher* dispatcher = iter.GetCurrentValue();
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidFail(base::File::FILE_ERROR_ABORT);
|
||||
dispatchers_.Remove(request_id);
|
||||
}
|
||||
}
|
||||
FileSystemDispatcher::~FileSystemDispatcher() = default;
|
||||
|
||||
blink::mojom::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
|
||||
auto BindInterfaceOnMainThread =
|
||||
@ -195,376 +50,6 @@ blink::mojom::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
|
||||
return *file_system_manager_ptr_;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::OpenFileSystem(
|
||||
const GURL& origin_url,
|
||||
storage::FileSystemType type,
|
||||
const OpenFileSystemCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
GetFileSystemManager().Open(
|
||||
origin_url, mojo::ConvertTo<blink::mojom::FileSystemType>(type),
|
||||
base::BindOnce(&FileSystemDispatcher::DidOpenFileSystem,
|
||||
base::Unretained(this), request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::OpenFileSystemSync(
|
||||
const GURL& origin_url,
|
||||
storage::FileSystemType type,
|
||||
const OpenFileSystemCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
std::string name;
|
||||
GURL root_url;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Open(
|
||||
origin_url, mojo::ConvertTo<blink::mojom::FileSystemType>(type), &name,
|
||||
&root_url, &error_code);
|
||||
DidOpenFileSystem(request_id, std::move(name), root_url, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ResolveURL(
|
||||
const GURL& filesystem_url,
|
||||
const ResolveURLCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
GetFileSystemManager().ResolveURL(
|
||||
filesystem_url, base::BindOnce(&FileSystemDispatcher::DidResolveURL,
|
||||
base::Unretained(this), request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ResolveURLSync(
|
||||
const GURL& filesystem_url,
|
||||
const ResolveURLCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
blink::mojom::FileSystemInfoPtr info;
|
||||
base::FilePath file_path;
|
||||
bool is_directory;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ResolveURL(filesystem_url, &info, &file_path,
|
||||
&is_directory, &error_code);
|
||||
DidResolveURL(request_id, std::move(info), std::move(file_path), is_directory,
|
||||
error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Move(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Move(
|
||||
src_path, dest_path,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::MoveSync(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Move(src_path, dest_path, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Copy(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Copy(
|
||||
src_path, dest_path,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CopySync(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Copy(src_path, dest_path, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Remove(const GURL& path,
|
||||
bool recursive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Remove(
|
||||
path, recursive,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::RemoveSync(const GURL& path,
|
||||
bool recursive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Remove(path, recursive, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadMetadata(
|
||||
const GURL& path,
|
||||
const MetadataCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
GetFileSystemManager().ReadMetadata(
|
||||
path, base::BindOnce(&FileSystemDispatcher::DidReadMetadata,
|
||||
base::Unretained(this), request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadMetadataSync(
|
||||
const GURL& path,
|
||||
const MetadataCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
base::File::Info file_info;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ReadMetadata(path, &file_info, &error_code);
|
||||
DidReadMetadata(request_id, std::move(file_info), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFile(const GURL& path,
|
||||
bool exclusive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Create(
|
||||
path, exclusive, /*is_directory=*/false, /*is_recursive=*/false,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFileSync(const GURL& path,
|
||||
bool exclusive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Create(path, exclusive, /*is_directory=*/false,
|
||||
/*is_recursive=*/false, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateDirectory(const GURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Create(
|
||||
path, exclusive, true, recursive,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateDirectorySync(const GURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Create(path, exclusive, true, recursive, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Exists(const GURL& path,
|
||||
bool is_directory,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().Exists(
|
||||
path, is_directory,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ExistsSync(const GURL& path,
|
||||
bool is_directory,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Exists(path, is_directory, &error_code);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadDirectory(
|
||||
const GURL& path,
|
||||
const ReadDirectoryCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
blink::mojom::FileSystemOperationListenerPtr ptr;
|
||||
blink::mojom::FileSystemOperationListenerRequest request =
|
||||
mojo::MakeRequest(&ptr);
|
||||
op_listeners_.AddBinding(
|
||||
std::make_unique<FileSystemOperationListenerImpl>(request_id, this),
|
||||
std::move(request));
|
||||
GetFileSystemManager().ReadDirectory(path, std::move(ptr));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadDirectorySync(
|
||||
const GURL& path,
|
||||
const ReadDirectoryCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
std::vector<filesystem::mojom::DirectoryEntryPtr> entries;
|
||||
base::File::Error result = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ReadDirectorySync(path, &entries, &result);
|
||||
if (result == base::File::FILE_OK)
|
||||
DidReadDirectory(request_id, std::move(entries), /*has_more=*/false);
|
||||
else
|
||||
DidFail(request_id, result);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Truncate(const GURL& path,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
blink::mojom::FileSystemCancellableOperationPtr op_ptr;
|
||||
blink::mojom::FileSystemCancellableOperationRequest op_request =
|
||||
mojo::MakeRequest(&op_ptr);
|
||||
op_ptr.set_connection_error_handler(
|
||||
base::BindOnce(&FileSystemDispatcher::RemoveOperationPtr,
|
||||
base::Unretained(this), request_id));
|
||||
cancellable_operations_[request_id] = std::move(op_ptr);
|
||||
GetFileSystemManager().Truncate(
|
||||
path, offset, std::move(op_request),
|
||||
base::BindOnce(&FileSystemDispatcher::DidTruncate, base::Unretained(this),
|
||||
request_id));
|
||||
|
||||
if (request_id_out)
|
||||
*request_id_out = request_id;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::TruncateSync(const GURL& path,
|
||||
int64_t offset,
|
||||
const StatusCallback& callback) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().TruncateSync(path, offset, &error_code);
|
||||
std::move(callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Write(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const WriteCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
|
||||
blink::mojom::FileSystemCancellableOperationPtr op_ptr;
|
||||
blink::mojom::FileSystemCancellableOperationRequest op_request =
|
||||
mojo::MakeRequest(&op_ptr);
|
||||
op_ptr.set_connection_error_handler(
|
||||
base::BindOnce(&FileSystemDispatcher::RemoveOperationPtr,
|
||||
base::Unretained(this), request_id));
|
||||
cancellable_operations_[request_id] = std::move(op_ptr);
|
||||
|
||||
blink::mojom::FileSystemOperationListenerPtr listener_ptr;
|
||||
blink::mojom::FileSystemOperationListenerRequest request =
|
||||
mojo::MakeRequest(&listener_ptr);
|
||||
op_listeners_.AddBinding(
|
||||
std::make_unique<FileSystemOperationListenerImpl>(request_id, this),
|
||||
std::move(request));
|
||||
|
||||
GetFileSystemManager().Write(path, blob_id, offset, std::move(op_request),
|
||||
std::move(listener_ptr));
|
||||
|
||||
if (request_id_out)
|
||||
*request_id_out = request_id;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::WriteSync(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset,
|
||||
const WriteCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int64_t byte_count;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().WriteSync(path, blob_id, offset, &byte_count,
|
||||
&error_code);
|
||||
if (error_code == base::File::FILE_OK)
|
||||
std::move(success_callback).Run(byte_count, /*complete=*/true);
|
||||
else
|
||||
std::move(error_callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Cancel(int request_id_to_cancel,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
if (cancellable_operations_.find(request_id_to_cancel) ==
|
||||
cancellable_operations_.end()) {
|
||||
DidFail(request_id, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
cancellable_operations_[request_id_to_cancel]->Cancel(
|
||||
base::BindOnce(&FileSystemDispatcher::DidCancel, base::Unretained(this),
|
||||
request_id, request_id_to_cancel));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::TouchFile(const GURL& path,
|
||||
const base::Time& last_access_time,
|
||||
const base::Time& last_modified_time,
|
||||
const StatusCallback& callback) {
|
||||
int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
|
||||
GetFileSystemManager().TouchFile(
|
||||
path, last_access_time, last_modified_time,
|
||||
base::BindOnce(&FileSystemDispatcher::DidFinish, base::Unretained(this),
|
||||
request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateSnapshotFile(
|
||||
const GURL& file_path,
|
||||
const CreateSnapshotFileCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
GetFileSystemManager().CreateSnapshotFile(
|
||||
file_path, base::BindOnce(&FileSystemDispatcher::DidCreateSnapshotFile,
|
||||
base::Unretained(this), request_id));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateSnapshotFileSync(
|
||||
const GURL& file_path,
|
||||
const CreateSnapshotFileCallback& success_callback,
|
||||
const StatusCallback& error_callback) {
|
||||
int request_id = dispatchers_.Add(
|
||||
CallbackDispatcher::Create(success_callback, error_callback));
|
||||
base::File::Info file_info;
|
||||
base::FilePath platform_path;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
blink::mojom::ReceivedSnapshotListenerPtr listener;
|
||||
GetFileSystemManager().CreateSnapshotFile(
|
||||
file_path, &file_info, &platform_path, &error_code, &listener);
|
||||
DidCreateSnapshotFile(request_id, std::move(file_info),
|
||||
std::move(platform_path), error_code,
|
||||
std::move(listener));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFileWriter(
|
||||
const GURL& file_path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks> callbacks) {
|
||||
GetFileSystemManager().CreateWriter(
|
||||
file_path,
|
||||
base::BindOnce(
|
||||
[](std::unique_ptr<CreateFileWriterCallbacks> callbacks,
|
||||
base::File::Error result, blink::mojom::FileWriterPtr writer) {
|
||||
if (result != base::File::FILE_OK) {
|
||||
callbacks->OnError(result);
|
||||
} else {
|
||||
callbacks->OnSuccess(writer.PassInterface().PassHandle());
|
||||
}
|
||||
},
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ChooseEntry(
|
||||
int render_frame_id,
|
||||
std::unique_ptr<ChooseEntryCallbacks> callbacks) {
|
||||
@ -591,149 +76,4 @@ void FileSystemDispatcher::ChooseEntry(
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidOpenFileSystem(int request_id,
|
||||
const std::string& name,
|
||||
const GURL& root,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidOpenFileSystem(name, root);
|
||||
dispatchers_.Remove(request_id);
|
||||
} else {
|
||||
DidFail(request_id, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidResolveURL(int request_id,
|
||||
blink::mojom::FileSystemInfoPtr info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
DCHECK(info->root_url.is_valid());
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidResolveURL(mojo::ConvertTo<storage::FileSystemInfo>(info),
|
||||
file_path, is_directory);
|
||||
dispatchers_.Remove(request_id);
|
||||
} else {
|
||||
DidFail(request_id, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidFinish(int request_id,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidSucceed();
|
||||
dispatchers_.Remove(request_id);
|
||||
} else {
|
||||
DidFail(request_id, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidReadMetadata(int request_id,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::FILE_OK) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidReadMetadata(file_info);
|
||||
dispatchers_.Remove(request_id);
|
||||
} else {
|
||||
DidFail(request_id, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidCreateSnapshotFile(
|
||||
int request_id,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::File::Error error_code,
|
||||
blink::mojom::ReceivedSnapshotListenerPtr listener) {
|
||||
base::Optional<blink::mojom::ReceivedSnapshotListenerPtr> opt_listener;
|
||||
if (listener)
|
||||
opt_listener = std::move(listener);
|
||||
if (error_code == base::File::FILE_OK) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidCreateSnapshotFile(file_info, platform_path,
|
||||
std::move(opt_listener), request_id);
|
||||
dispatchers_.Remove(request_id);
|
||||
} else {
|
||||
DidFail(request_id, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidReadDirectory(
|
||||
int request_id,
|
||||
std::vector<filesystem::mojom::DirectoryEntryPtr> entries,
|
||||
bool has_more) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
std::vector<filesystem::mojom::DirectoryEntry> entries_copy;
|
||||
for (const auto& entry : entries) {
|
||||
entries_copy.push_back(*entry);
|
||||
}
|
||||
dispatcher->DidReadDirectory(std::move(entries_copy), has_more);
|
||||
if (!has_more)
|
||||
dispatchers_.Remove(request_id);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidFail(int request_id,
|
||||
base::File::Error error_code) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidFail(error_code);
|
||||
dispatchers_.Remove(request_id);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidWrite(int request_id,
|
||||
int64_t bytes,
|
||||
bool complete) {
|
||||
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
|
||||
DCHECK(dispatcher);
|
||||
dispatcher->DidWrite(bytes, complete);
|
||||
if (complete) {
|
||||
dispatchers_.Remove(request_id);
|
||||
RemoveOperationPtr(request_id);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidTruncate(int request_id,
|
||||
base::File::Error error_code) {
|
||||
// If |error_code| is ABORT, it means the operation was cancelled,
|
||||
// so we let DidCancel clean up the interface pointer.
|
||||
if (error_code != base::File::FILE_ERROR_ABORT)
|
||||
RemoveOperationPtr(request_id);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidCancel(int request_id,
|
||||
int cancelled_request_id,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::FILE_OK)
|
||||
RemoveOperationPtr(cancelled_request_id);
|
||||
DidFinish(request_id, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::FileSystemOperationListenerImpl::ResultsRetrieved(
|
||||
std::vector<filesystem::mojom::DirectoryEntryPtr> entries,
|
||||
bool has_more) {
|
||||
dispatcher_->DidReadDirectory(request_id_, std::move(entries), has_more);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::FileSystemOperationListenerImpl::ErrorOccurred(
|
||||
base::File::Error error_code) {
|
||||
dispatcher_->DidFail(request_id_, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::FileSystemOperationListenerImpl::DidWrite(
|
||||
int64_t byte_count,
|
||||
bool complete) {
|
||||
dispatcher_->DidWrite(request_id_, byte_count, complete);
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -5,244 +5,35 @@
|
||||
#ifndef CONTENT_RENDERER_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
|
||||
#define CONTENT_RENDERER_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/containers/id_map.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/process/process.h"
|
||||
#include "components/services/filesystem/public/interfaces/types.mojom.h"
|
||||
#include "ipc/ipc_listener.h"
|
||||
#include "ipc/ipc_platform_file.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding_set.h"
|
||||
#include "storage/common/fileapi/file_system_types.h"
|
||||
#include "storage/common/quota/quota_limit_type.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "third_party/blink/public/mojom/filesystem/file_system.mojom.h"
|
||||
#include "third_party/blink/public/platform/web_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
||||
namespace storage {
|
||||
struct FileSystemInfo;
|
||||
}
|
||||
|
||||
class GURL;
|
||||
class SingleThreadTaskRunner;
|
||||
} // namespace base
|
||||
|
||||
namespace content {
|
||||
class FileSystemOperationListenerImpl;
|
||||
|
||||
// Dispatches and sends file system related messages sent to/from a child
|
||||
// process from/to the main browser process. There is an instance held by
|
||||
// each WebFileSystemImpl and WebFileWriterImpl object.
|
||||
// each WebFileSystemImpl object.
|
||||
// TODO(adithyas): Move functionality to blink::FileSystemDispatcher and
|
||||
// remove this class.
|
||||
class FileSystemDispatcher {
|
||||
public:
|
||||
typedef base::Callback<void(base::File::Error error)> StatusCallback;
|
||||
typedef base::Callback<void(const base::File::Info& file_info)>
|
||||
MetadataCallback;
|
||||
typedef base::Callback<void(
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::Optional<blink::mojom::ReceivedSnapshotListenerPtr> opt_listener,
|
||||
int request_id)>
|
||||
CreateSnapshotFileCallback;
|
||||
|
||||
typedef base::Callback<void(
|
||||
const std::vector<filesystem::mojom::DirectoryEntry>& entries,
|
||||
bool has_more)>
|
||||
ReadDirectoryCallback;
|
||||
typedef base::Callback<void(const std::string& name, const GURL& root)>
|
||||
OpenFileSystemCallback;
|
||||
typedef base::Callback<void(const storage::FileSystemInfo& info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory)>
|
||||
ResolveURLCallback;
|
||||
|
||||
typedef base::Callback<void(int64_t bytes, bool complete)> WriteCallback;
|
||||
typedef base::Callback<void(base::PlatformFile file,
|
||||
int file_open_id,
|
||||
storage::QuotaLimitType quota_policy)>
|
||||
OpenFileCallback;
|
||||
|
||||
explicit FileSystemDispatcher(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
|
||||
~FileSystemDispatcher();
|
||||
|
||||
void OpenFileSystem(const GURL& origin_url,
|
||||
storage::FileSystemType type,
|
||||
const OpenFileSystemCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void OpenFileSystemSync(const GURL& origin_url,
|
||||
storage::FileSystemType type,
|
||||
const OpenFileSystemCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
void ResolveURL(const GURL& filesystem_url,
|
||||
const ResolveURLCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void ResolveURLSync(const GURL& filesystem_url,
|
||||
const ResolveURLCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
void Move(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback);
|
||||
void MoveSync(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void Copy(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback);
|
||||
void CopySync(const GURL& src_path,
|
||||
const GURL& dest_path,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void Remove(const GURL& path, bool recursive, const StatusCallback& callback);
|
||||
void RemoveSync(const GURL& path,
|
||||
bool recursive,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void ReadMetadata(const GURL& path,
|
||||
const MetadataCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void ReadMetadataSync(const GURL& path,
|
||||
const MetadataCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
void CreateFile(const GURL& path,
|
||||
bool exclusive,
|
||||
const StatusCallback& callback);
|
||||
void CreateFileSync(const GURL& path,
|
||||
bool exclusive,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void CreateDirectory(const GURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
const StatusCallback& callback);
|
||||
void CreateDirectorySync(const GURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void Exists(const GURL& path,
|
||||
bool for_directory,
|
||||
const StatusCallback& callback);
|
||||
void ExistsSync(const GURL& path,
|
||||
bool for_directory,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void ReadDirectory(const GURL& path,
|
||||
const ReadDirectoryCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void ReadDirectorySync(const GURL& path,
|
||||
const ReadDirectoryCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
void Truncate(const GURL& path,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const StatusCallback& callback);
|
||||
void TruncateSync(const GURL& path,
|
||||
int64_t offset,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void Write(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const WriteCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void WriteSync(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset,
|
||||
const WriteCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
void Cancel(int request_id_to_cancel, const StatusCallback& callback);
|
||||
void TouchFile(const GURL& file_path,
|
||||
const base::Time& last_access_time,
|
||||
const base::Time& last_modified_time,
|
||||
const StatusCallback& callback);
|
||||
|
||||
void CreateSnapshotFile(const GURL& file_path,
|
||||
const CreateSnapshotFileCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
void CreateSnapshotFileSync(
|
||||
const GURL& file_path,
|
||||
const CreateSnapshotFileCallback& success_callback,
|
||||
const StatusCallback& error_callback);
|
||||
|
||||
using CreateFileWriterCallbacks =
|
||||
blink::WebFileSystem::CreateFileWriterCallbacks;
|
||||
void CreateFileWriter(const GURL& file_path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks> callbacks);
|
||||
|
||||
using ChooseEntryCallbacks = blink::WebFileSystem::ChooseEntryCallbacks;
|
||||
void ChooseEntry(int render_frame_id,
|
||||
std::unique_ptr<ChooseEntryCallbacks> callbacks);
|
||||
|
||||
private:
|
||||
class CallbackDispatcher;
|
||||
class FileSystemOperationListenerImpl;
|
||||
|
||||
void DidOpenFileSystem(int request_id,
|
||||
const std::string& name,
|
||||
const GURL& root,
|
||||
base::File::Error error_code);
|
||||
void DidResolveURL(int request_id,
|
||||
blink::mojom::FileSystemInfoPtr info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory,
|
||||
base::File::Error error_code);
|
||||
void DidFinish(int request_id, base::File::Error error_code);
|
||||
void DidReadMetadata(int request_id,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error);
|
||||
void DidCreateSnapshotFile(
|
||||
int request_id,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::File::Error error_code,
|
||||
blink::mojom::ReceivedSnapshotListenerPtr listener);
|
||||
void DidReadDirectory(
|
||||
int request_id,
|
||||
std::vector<filesystem::mojom::DirectoryEntryPtr> entries,
|
||||
bool has_more);
|
||||
void DidFail(int request_id, base::File::Error error_code);
|
||||
void DidWrite(int request_id, int64_t bytes, bool complete);
|
||||
void DidTruncate(int request_id, base::File::Error error_code);
|
||||
void DidCancel(int request_id,
|
||||
int cancelled_request_id,
|
||||
base::File::Error error_code);
|
||||
|
||||
void RemoveOperationPtr(int request_id) {
|
||||
DCHECK(cancellable_operations_.find(request_id) !=
|
||||
cancellable_operations_.end());
|
||||
cancellable_operations_.erase(request_id);
|
||||
}
|
||||
|
||||
blink::mojom::FileSystemManager& GetFileSystemManager();
|
||||
|
||||
blink::mojom::FileSystemManagerPtr file_system_manager_ptr_;
|
||||
|
||||
base::IDMap<std::unique_ptr<CallbackDispatcher>> dispatchers_;
|
||||
|
||||
mojo::StrongBindingSet<blink::mojom::FileSystemOperationListener>
|
||||
op_listeners_;
|
||||
|
||||
using OperationsMap =
|
||||
std::unordered_map<int, blink::mojom::FileSystemCancellableOperationPtr>;
|
||||
OperationsMap cancellable_operations_;
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher);
|
||||
|
@ -4,40 +4,13 @@
|
||||
|
||||
#include "content/renderer/fileapi/webfilesystem_impl.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread_local.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "components/services/filesystem/public/interfaces/types.mojom.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/renderer/file_info_util.h"
|
||||
#include "content/renderer/fileapi/file_system_dispatcher.h"
|
||||
#include "content/renderer/fileapi/webfilewriter_impl.h"
|
||||
#include "content/renderer/render_thread_impl.h"
|
||||
#include "storage/common/fileapi/file_system_util.h"
|
||||
#include "third_party/blink/public/platform/file_path_conversion.h"
|
||||
#include "third_party/blink/public/platform/web_file_info.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using blink::WebFileInfo;
|
||||
using blink::WebFileSystemCallbacks;
|
||||
using blink::WebFileSystemEntry;
|
||||
using blink::WebString;
|
||||
using blink::WebURL;
|
||||
using blink::WebVector;
|
||||
#include "third_party/blink/public/web/web_frame.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -51,198 +24,6 @@ enum CallbacksUnregisterMode {
|
||||
DO_NOT_UNREGISTER_CALLBACKS,
|
||||
};
|
||||
|
||||
template <typename Method, typename Params>
|
||||
void CallDispatcher(const WebFileSystemCallbacks& callbacks,
|
||||
Method async_method,
|
||||
Method sync_method,
|
||||
FileSystemDispatcher* dispatcher,
|
||||
Params&& params) {
|
||||
if (callbacks.ShouldBlockUntilCompletion())
|
||||
DispatchToMethod(dispatcher, sync_method, params);
|
||||
else
|
||||
DispatchToMethod(dispatcher, async_method, params);
|
||||
}
|
||||
|
||||
// Bridging functions that convert the arguments into Blink objects
|
||||
// (e.g. WebFileInfo, WebString, WebVector<WebFileSystemEntry>)
|
||||
// and call WebFileSystemCallbacks's methods.
|
||||
void DidSucceed(WebFileSystemCallbacks* callbacks) {
|
||||
callbacks->DidSucceed();
|
||||
}
|
||||
|
||||
void DidReadMetadata(const base::File::Info& file_info,
|
||||
WebFileSystemCallbacks* callbacks) {
|
||||
WebFileInfo web_file_info;
|
||||
FileInfoToWebFileInfo(file_info, &web_file_info);
|
||||
callbacks->DidReadMetadata(web_file_info);
|
||||
}
|
||||
|
||||
void DidReadDirectory(
|
||||
const std::vector<filesystem::mojom::DirectoryEntry>& entries,
|
||||
bool has_more,
|
||||
WebFileSystemCallbacks* callbacks) {
|
||||
WebVector<WebFileSystemEntry> file_system_entries(entries.size());
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
file_system_entries[i].name =
|
||||
blink::FilePathToWebString(base::FilePath(entries[i].name));
|
||||
file_system_entries[i].is_directory =
|
||||
entries[i].type == filesystem::mojom::FsFileType::DIRECTORY;
|
||||
}
|
||||
callbacks->DidReadDirectory(file_system_entries, has_more);
|
||||
}
|
||||
|
||||
void DidOpenFileSystem(const std::string& name,
|
||||
const GURL& root,
|
||||
WebFileSystemCallbacks* callbacks) {
|
||||
callbacks->DidOpenFileSystem(blink::WebString::FromUTF8(name), root);
|
||||
}
|
||||
|
||||
void DidResolveURL(const std::string& name,
|
||||
const GURL& root_url,
|
||||
storage::FileSystemType mount_type,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory,
|
||||
WebFileSystemCallbacks* callbacks) {
|
||||
callbacks->DidResolveURL(blink::WebString::FromUTF8(name), root_url,
|
||||
static_cast<blink::WebFileSystemType>(mount_type),
|
||||
blink::FilePathToWebString(file_path), is_directory);
|
||||
}
|
||||
|
||||
void DidFail(base::File::Error error, WebFileSystemCallbacks* callbacks) {
|
||||
callbacks->DidFail(storage::FileErrorToWebFileError(error));
|
||||
}
|
||||
|
||||
void RunCallbacks(int callbacks_id,
|
||||
base::OnceCallback<void(WebFileSystemCallbacks*)> callback,
|
||||
CallbacksUnregisterMode callbacks_unregister_mode) {
|
||||
WebFileSystemImpl* filesystem =
|
||||
WebFileSystemImpl::ThreadSpecificInstance(nullptr);
|
||||
if (!filesystem)
|
||||
return;
|
||||
WebFileSystemCallbacks callbacks = filesystem->GetCallbacks(callbacks_id);
|
||||
if (callbacks_unregister_mode == UNREGISTER_CALLBACKS)
|
||||
filesystem->UnregisterCallbacks(callbacks_id);
|
||||
std::move(callback).Run(&callbacks);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Callback adapters.
|
||||
|
||||
void OpenFileSystemCallbackAdapter(int callbacks_id,
|
||||
const std::string& name,
|
||||
const GURL& root) {
|
||||
RunCallbacks(callbacks_id, base::BindOnce(&DidOpenFileSystem, name, root),
|
||||
UNREGISTER_CALLBACKS);
|
||||
}
|
||||
|
||||
void ResolveURLCallbackAdapter(int callbacks_id,
|
||||
const storage::FileSystemInfo& info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory) {
|
||||
base::FilePath normalized_path(
|
||||
storage::VirtualPath::GetNormalizedFilePath(file_path));
|
||||
RunCallbacks(callbacks_id,
|
||||
base::BindOnce(&DidResolveURL, info.name, info.root_url,
|
||||
info.mount_type, normalized_path, is_directory),
|
||||
UNREGISTER_CALLBACKS);
|
||||
}
|
||||
|
||||
void StatusCallbackAdapter(int callbacks_id, base::File::Error error) {
|
||||
if (error == base::File::FILE_OK) {
|
||||
RunCallbacks(callbacks_id, base::BindOnce(&DidSucceed),
|
||||
UNREGISTER_CALLBACKS);
|
||||
} else {
|
||||
RunCallbacks(callbacks_id, base::BindOnce(&DidFail, error),
|
||||
UNREGISTER_CALLBACKS);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadMetadataCallbackAdapter(int callbacks_id,
|
||||
const base::File::Info& file_info) {
|
||||
RunCallbacks(callbacks_id, base::BindOnce(&DidReadMetadata, file_info),
|
||||
UNREGISTER_CALLBACKS);
|
||||
}
|
||||
|
||||
void ReadDirectoryCallbackAdapter(
|
||||
int callbacks_id,
|
||||
const std::vector<filesystem::mojom::DirectoryEntry>& entries,
|
||||
bool has_more) {
|
||||
RunCallbacks(callbacks_id,
|
||||
base::BindOnce(&DidReadDirectory, entries, has_more),
|
||||
has_more ? DO_NOT_UNREGISTER_CALLBACKS : UNREGISTER_CALLBACKS);
|
||||
}
|
||||
|
||||
void DidCreateFileWriter(int callbacks_id,
|
||||
const GURL& path,
|
||||
blink::WebFileWriterClient* client,
|
||||
base::SingleThreadTaskRunner* main_thread_task_runner,
|
||||
const base::File::Info& file_info) {
|
||||
WebFileSystemImpl* filesystem =
|
||||
WebFileSystemImpl::ThreadSpecificInstance(nullptr);
|
||||
if (!filesystem)
|
||||
return;
|
||||
|
||||
WebFileSystemCallbacks callbacks = filesystem->GetCallbacks(callbacks_id);
|
||||
filesystem->UnregisterCallbacks(callbacks_id);
|
||||
|
||||
if (file_info.is_directory || file_info.size < 0) {
|
||||
callbacks.DidFail(blink::kWebFileErrorInvalidState);
|
||||
return;
|
||||
}
|
||||
WebFileWriterImpl::Type type = callbacks.ShouldBlockUntilCompletion()
|
||||
? WebFileWriterImpl::TYPE_SYNC
|
||||
: WebFileWriterImpl::TYPE_ASYNC;
|
||||
callbacks.DidCreateFileWriter(
|
||||
new WebFileWriterImpl(path, client, type, main_thread_task_runner),
|
||||
file_info.size);
|
||||
}
|
||||
|
||||
void CreateFileWriterCallbackAdapter(
|
||||
int callbacks_id,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
|
||||
const GURL& path,
|
||||
blink::WebFileWriterClient* client,
|
||||
const base::File::Info& file_info) {
|
||||
DidCreateFileWriter(callbacks_id, path, client, main_thread_task_runner.get(),
|
||||
file_info);
|
||||
}
|
||||
|
||||
void DidCreateSnapshotFile(
|
||||
int callbacks_id,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::Optional<blink::mojom::ReceivedSnapshotListenerPtr> opt_listener,
|
||||
int request_id) {
|
||||
WebFileSystemImpl* filesystem =
|
||||
WebFileSystemImpl::ThreadSpecificInstance(nullptr);
|
||||
if (!filesystem)
|
||||
return;
|
||||
|
||||
WebFileSystemCallbacks callbacks = filesystem->GetCallbacks(callbacks_id);
|
||||
filesystem->UnregisterCallbacks(callbacks_id);
|
||||
|
||||
WebFileInfo web_file_info;
|
||||
FileInfoToWebFileInfo(file_info, &web_file_info);
|
||||
web_file_info.platform_path = blink::FilePathToWebString(platform_path);
|
||||
callbacks.DidCreateSnapshotFile(web_file_info);
|
||||
|
||||
// TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes
|
||||
// non-bridge model.
|
||||
if (opt_listener) {
|
||||
opt_listener.value()->DidReceiveSnapshotFile();
|
||||
}
|
||||
}
|
||||
|
||||
void CreateSnapshotFileCallbackAdapter(
|
||||
int callbacks_id,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::Optional<blink::mojom::ReceivedSnapshotListenerPtr> opt_listener,
|
||||
int request_id) {
|
||||
DidCreateSnapshotFile(callbacks_id, file_info, platform_path,
|
||||
std::move(opt_listener), request_id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -268,7 +49,6 @@ void WebFileSystemImpl::DeleteThreadSpecificInstance() {
|
||||
WebFileSystemImpl::WebFileSystemImpl(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
|
||||
: main_thread_task_runner_(main_thread_task_runner),
|
||||
next_callbacks_id_(1),
|
||||
file_system_dispatcher_(std::move(main_thread_task_runner)) {
|
||||
g_webfilesystem_tls.Pointer()->Set(this);
|
||||
}
|
||||
@ -282,175 +62,6 @@ void WebFileSystemImpl::WillStopCurrentWorkerThread() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::OpenFileSystem(const blink::WebURL& storage_partition,
|
||||
blink::WebFileSystemType type,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::OpenFileSystem,
|
||||
&FileSystemDispatcher::OpenFileSystemSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(storage_partition), static_cast<storage::FileSystemType>(type),
|
||||
base::BindRepeating(&OpenFileSystemCallbackAdapter, callbacks_id),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::ResolveURL(const blink::WebURL& filesystem_url,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::ResolveURL,
|
||||
&FileSystemDispatcher::ResolveURLSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(filesystem_url),
|
||||
base::BindRepeating(&ResolveURLCallbackAdapter, callbacks_id),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::Move(const blink::WebURL& src_path,
|
||||
const blink::WebURL& dest_path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Move,
|
||||
&FileSystemDispatcher::MoveSync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(src_path), GURL(dest_path),
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::Copy(const blink::WebURL& src_path,
|
||||
const blink::WebURL& dest_path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Copy,
|
||||
&FileSystemDispatcher::CopySync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(src_path), GURL(dest_path),
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::Remove(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Remove,
|
||||
&FileSystemDispatcher::RemoveSync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(path), /*recursive=*/false,
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::RemoveRecursively(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Remove,
|
||||
&FileSystemDispatcher::RemoveSync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(path), /*recursive=*/true,
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::ReadMetadata(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::ReadMetadata,
|
||||
&FileSystemDispatcher::ReadMetadataSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path),
|
||||
base::BindRepeating(&ReadMetadataCallbackAdapter, callbacks_id),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::CreateFile(const blink::WebURL& path,
|
||||
bool exclusive,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::CreateFile,
|
||||
&FileSystemDispatcher::CreateFileSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path), exclusive,
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::CreateDirectory(const blink::WebURL& path,
|
||||
bool exclusive,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::CreateDirectory,
|
||||
&FileSystemDispatcher::CreateDirectorySync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path), exclusive, /*recursive=*/false,
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::FileExists(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Exists,
|
||||
&FileSystemDispatcher::ExistsSync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(path), /*directory=*/false,
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::DirectoryExists(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(callbacks, &FileSystemDispatcher::Exists,
|
||||
&FileSystemDispatcher::ExistsSync, &file_system_dispatcher_,
|
||||
std::make_tuple(GURL(path), /*directory=*/true,
|
||||
base::BindRepeating(&StatusCallbackAdapter,
|
||||
callbacks_id)));
|
||||
}
|
||||
|
||||
int WebFileSystemImpl::ReadDirectory(const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::ReadDirectory,
|
||||
&FileSystemDispatcher::ReadDirectorySync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path),
|
||||
base::BindRepeating(&ReadDirectoryCallbackAdapter, callbacks_id),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
return callbacks_id;
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::CreateFileWriter(const WebURL& path,
|
||||
blink::WebFileWriterClient* client,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::ReadMetadata,
|
||||
&FileSystemDispatcher::ReadMetadataSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path),
|
||||
base::BindRepeating(&CreateFileWriterCallbackAdapter, callbacks_id,
|
||||
main_thread_task_runner_, GURL(path), client),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::CreateFileWriter(
|
||||
const blink::WebURL& path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks> callbacks) {
|
||||
file_system_dispatcher_.CreateFileWriter(path, std::move(callbacks));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::CreateSnapshotFileAndReadMetadata(
|
||||
const blink::WebURL& path,
|
||||
WebFileSystemCallbacks callbacks) {
|
||||
int callbacks_id = RegisterCallbacks(callbacks);
|
||||
CallDispatcher(
|
||||
callbacks, &FileSystemDispatcher::CreateSnapshotFile,
|
||||
&FileSystemDispatcher::CreateSnapshotFileSync, &file_system_dispatcher_,
|
||||
std::make_tuple(
|
||||
GURL(path),
|
||||
base::BindRepeating(&CreateSnapshotFileCallbackAdapter, callbacks_id),
|
||||
base::BindRepeating(&StatusCallbackAdapter, callbacks_id)));
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::ChooseEntry(
|
||||
blink::WebFrame* frame,
|
||||
std::unique_ptr<ChooseEntryCallbacks> callbacks) {
|
||||
@ -458,26 +69,4 @@ void WebFileSystemImpl::ChooseEntry(
|
||||
RenderFrame::GetRoutingIdForWebFrame(frame), std::move(callbacks));
|
||||
}
|
||||
|
||||
int WebFileSystemImpl::RegisterCallbacks(
|
||||
const WebFileSystemCallbacks& callbacks) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
int id = next_callbacks_id_++;
|
||||
callbacks_[id] = callbacks;
|
||||
return id;
|
||||
}
|
||||
|
||||
WebFileSystemCallbacks WebFileSystemImpl::GetCallbacks(int callbacks_id) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
CallbacksMap::iterator found = callbacks_.find(callbacks_id);
|
||||
DCHECK(found != callbacks_.end());
|
||||
return found->second;
|
||||
}
|
||||
|
||||
void WebFileSystemImpl::UnregisterCallbacks(int callbacks_id) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
CallbacksMap::iterator found = callbacks_.find(callbacks_id);
|
||||
DCHECK(found != callbacks_.end());
|
||||
callbacks_.erase(found);
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -5,10 +5,6 @@
|
||||
#ifndef CONTENT_RENDERER_FILEAPI_WEBFILESYSTEM_IMPL_H_
|
||||
#define CONTENT_RENDERER_FILEAPI_WEBFILESYSTEM_IMPL_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/threading/thread_checker.h"
|
||||
#include "content/public/renderer/worker_thread.h"
|
||||
@ -19,13 +15,10 @@ namespace base {
|
||||
class SingleThreadTaskRunner;
|
||||
}
|
||||
|
||||
namespace blink {
|
||||
class WebURL;
|
||||
class WebFileWriterClient;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
|
||||
// TODO(adithyas): Move functionality to blink::FileSystemDispatcher and remove
|
||||
// this class.
|
||||
class WebFileSystemImpl : public blink::WebFileSystem,
|
||||
public WorkerThread::Observer {
|
||||
public:
|
||||
@ -47,60 +40,11 @@ class WebFileSystemImpl : public blink::WebFileSystem,
|
||||
// WorkerThread::Observer implementation.
|
||||
void WillStopCurrentWorkerThread() override;
|
||||
|
||||
// WebFileSystem implementation.
|
||||
void OpenFileSystem(const blink::WebURL& storage_partition,
|
||||
const blink::WebFileSystemType type,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void ResolveURL(const blink::WebURL& filesystem_url,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void Move(const blink::WebURL& src_path,
|
||||
const blink::WebURL& dest_path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void Copy(const blink::WebURL& src_path,
|
||||
const blink::WebURL& dest_path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void Remove(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void RemoveRecursively(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void ReadMetadata(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void CreateFile(const blink::WebURL& path,
|
||||
bool exclusive,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void CreateDirectory(const blink::WebURL& path,
|
||||
bool exclusive,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void FileExists(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void DirectoryExists(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
int ReadDirectory(const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void CreateFileWriter(const blink::WebURL& path,
|
||||
blink::WebFileWriterClient*,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
void CreateFileWriter(
|
||||
const blink::WebURL& path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks> callbacks) override;
|
||||
void CreateSnapshotFileAndReadMetadata(
|
||||
const blink::WebURL& path,
|
||||
blink::WebFileSystemCallbacks) override;
|
||||
|
||||
void ChooseEntry(blink::WebFrame* frame,
|
||||
std::unique_ptr<ChooseEntryCallbacks>) override;
|
||||
|
||||
int RegisterCallbacks(const blink::WebFileSystemCallbacks& callbacks);
|
||||
blink::WebFileSystemCallbacks GetCallbacks(int callbacks_id);
|
||||
void UnregisterCallbacks(int callbacks_id);
|
||||
|
||||
private:
|
||||
typedef std::map<int, blink::WebFileSystemCallbacks> CallbacksMap;
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
|
||||
|
||||
CallbacksMap callbacks_;
|
||||
int next_callbacks_id_;
|
||||
FileSystemDispatcher file_system_dispatcher_;
|
||||
|
||||
// Thread-affine per use of TLS in impl.
|
||||
|
@ -1,151 +0,0 @@
|
||||
// Copyright 2013 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 "content/renderer/fileapi/webfilewriter_base.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "storage/common/fileapi/file_system_util.h"
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer_client.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
|
||||
using storage::FileErrorToWebFileError;
|
||||
|
||||
namespace content {
|
||||
|
||||
WebFileWriterBase::WebFileWriterBase(const GURL& path,
|
||||
blink::WebFileWriterClient* client)
|
||||
: path_(path),
|
||||
client_(client),
|
||||
operation_(kOperationNone),
|
||||
cancel_state_(kCancelNotInProgress) {}
|
||||
|
||||
WebFileWriterBase::~WebFileWriterBase() {}
|
||||
|
||||
void WebFileWriterBase::Truncate(long long length) {
|
||||
DCHECK(kOperationNone == operation_);
|
||||
DCHECK(kCancelNotInProgress == cancel_state_);
|
||||
operation_ = kOperationTruncate;
|
||||
DoTruncate(path_, length);
|
||||
}
|
||||
|
||||
void WebFileWriterBase::Write(long long position, const blink::WebString& id) {
|
||||
DCHECK_EQ(kOperationNone, operation_);
|
||||
DCHECK_EQ(kCancelNotInProgress, cancel_state_);
|
||||
operation_ = kOperationWrite;
|
||||
DoWrite(path_, id.Utf8(), position);
|
||||
}
|
||||
|
||||
// When we cancel a write/truncate, we always get back the result of the write
|
||||
// before the result of the cancel, no matter what happens.
|
||||
// So we'll get back either
|
||||
// success [of the write/truncate, in a DidWrite(XXX, true)/DidSucceed() call]
|
||||
// followed by failure [of the cancel]; or
|
||||
// failure [of the write, either from cancel or other reasons] followed by
|
||||
// the result of the cancel.
|
||||
// In the write case, there could also be queued up non-terminal DidWrite calls
|
||||
// before any of that comes back, but there will always be a terminal write
|
||||
// response [success or failure] after them, followed by the cancel result, so
|
||||
// we can ignore non-terminal write responses, take the terminal write success
|
||||
// or the first failure as the last write response, then know that the next
|
||||
// thing to come back is the cancel response. We only notify the
|
||||
// AsyncFileWriterClient when it's all over.
|
||||
void WebFileWriterBase::Cancel() {
|
||||
// Check for the cancel passing the previous operation's return in-flight.
|
||||
if (kOperationWrite != operation_ && kOperationTruncate != operation_)
|
||||
return;
|
||||
if (kCancelNotInProgress != cancel_state_)
|
||||
return;
|
||||
cancel_state_ = kCancelSent;
|
||||
DoCancel();
|
||||
}
|
||||
|
||||
void WebFileWriterBase::DidFinish(base::File::Error error_code) {
|
||||
if (error_code == base::File::FILE_OK)
|
||||
DidSucceed();
|
||||
else
|
||||
DidFail(error_code);
|
||||
}
|
||||
|
||||
void WebFileWriterBase::DidWrite(int64_t bytes, bool complete) {
|
||||
DCHECK(kOperationWrite == operation_);
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
if (complete)
|
||||
operation_ = kOperationNone;
|
||||
client_->DidWrite(bytes, complete);
|
||||
break;
|
||||
case kCancelSent:
|
||||
// This is the success call of the write, which we'll eat, even though
|
||||
// it succeeded before the cancel got there. We accepted the cancel call,
|
||||
// so the write will eventually return an error.
|
||||
if (complete)
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void WebFileWriterBase::DidSucceed() {
|
||||
// Write never gets a DidSucceed call, so this is either a cancel or truncate
|
||||
// response.
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
// A truncate succeeded, with no complications.
|
||||
DCHECK(kOperationTruncate == operation_);
|
||||
operation_ = kOperationNone;
|
||||
client_->DidTruncate();
|
||||
break;
|
||||
case kCancelSent:
|
||||
DCHECK(kOperationTruncate == operation_);
|
||||
// This is the success call of the truncate, which we'll eat, even though
|
||||
// it succeeded before the cancel got there. We accepted the cancel call,
|
||||
// so the truncate will eventually return an error.
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
// This is the success of the cancel operation.
|
||||
FinishCancel();
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void WebFileWriterBase::DidFail(base::File::Error error_code) {
|
||||
DCHECK(kOperationNone != operation_);
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
// A write or truncate failed.
|
||||
operation_ = kOperationNone;
|
||||
client_->DidFail(FileErrorToWebFileError(error_code));
|
||||
break;
|
||||
case kCancelSent:
|
||||
// This is the failure of a write or truncate; the next message should be
|
||||
// the result of the cancel. We don't assume that it'll be a success, as
|
||||
// the write/truncate could have failed for other reasons.
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
// The cancel reported failure, meaning that the write or truncate
|
||||
// finished before the cancel got there. But we suppressed the
|
||||
// write/truncate's response, and will now report that it was cancelled.
|
||||
FinishCancel();
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void WebFileWriterBase::FinishCancel() {
|
||||
DCHECK(kCancelReceivedWriteResponse == cancel_state_);
|
||||
DCHECK(kOperationNone != operation_);
|
||||
cancel_state_ = kCancelNotInProgress;
|
||||
operation_ = kOperationNone;
|
||||
client_->DidFail(blink::kWebFileErrorAbort);
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -1,71 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#ifndef CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_BASE_H_
|
||||
#define CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_BASE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/files/file.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace blink {
|
||||
class WebFileWriterClient;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
|
||||
class CONTENT_EXPORT WebFileWriterBase : public blink::WebFileWriter {
|
||||
public:
|
||||
WebFileWriterBase(const GURL& path, blink::WebFileWriterClient* client);
|
||||
~WebFileWriterBase() override;
|
||||
|
||||
// WebFileWriter implementation
|
||||
void Truncate(long long length) override;
|
||||
void Write(long long position, const blink::WebString& id) override;
|
||||
void Cancel() override;
|
||||
|
||||
protected:
|
||||
// This calls DidSucceed() or DidFail() based on the value of |error_code|.
|
||||
void DidFinish(base::File::Error error_code);
|
||||
|
||||
void DidWrite(int64_t bytes, bool complete);
|
||||
void DidSucceed();
|
||||
void DidFail(base::File::Error error_code);
|
||||
|
||||
// Derived classes must provide these methods to asynchronously perform
|
||||
// the requested operation, and they must call the appropiate DidSomething
|
||||
// method upon completion and as progress is made in the Write case.
|
||||
virtual void DoTruncate(const GURL& path, int64_t offset) = 0;
|
||||
virtual void DoWrite(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset) = 0;
|
||||
virtual void DoCancel() = 0;
|
||||
|
||||
private:
|
||||
enum OperationType {
|
||||
kOperationNone,
|
||||
kOperationWrite,
|
||||
kOperationTruncate
|
||||
};
|
||||
|
||||
enum CancelState {
|
||||
kCancelNotInProgress,
|
||||
kCancelSent,
|
||||
kCancelReceivedWriteResponse,
|
||||
};
|
||||
|
||||
void FinishCancel();
|
||||
|
||||
GURL path_;
|
||||
blink::WebFileWriterClient* client_;
|
||||
OperationType operation_;
|
||||
CancelState cancel_state_;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_BASE_H_
|
@ -1,416 +0,0 @@
|
||||
// Copyright 2013 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 "content/renderer/fileapi/webfilewriter_base.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer_client.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
namespace {
|
||||
|
||||
// We use particular offsets to trigger particular behaviors
|
||||
// in the TestableFileWriter.
|
||||
const int kNoOffset = -1;
|
||||
const int kBasicFileTruncate_Offset = 1;
|
||||
const int kErrorFileTruncate_Offset = 2;
|
||||
const int kCancelFileTruncate_Offset = 3;
|
||||
const int kCancelFailedTruncate_Offset = 4;
|
||||
const int kBasicFileWrite_Offset = 1;
|
||||
const int kErrorFileWrite_Offset = 2;
|
||||
const int kMultiFileWrite_Offset = 3;
|
||||
const int kCancelFileWriteBeforeCompletion_Offset = 4;
|
||||
const int kCancelFileWriteAfterCompletion_Offset = 5;
|
||||
|
||||
GURL mock_path_as_gurl() {
|
||||
return GURL("MockPath");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class TestableFileWriter : public WebFileWriterBase {
|
||||
public:
|
||||
explicit TestableFileWriter(blink::WebFileWriterClient* client)
|
||||
: WebFileWriterBase(mock_path_as_gurl(), client) {
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
received_truncate_ = false;
|
||||
received_truncate_path_ = GURL();
|
||||
received_truncate_offset_ = kNoOffset;
|
||||
received_write_ = false;
|
||||
received_write_path_ = GURL();
|
||||
received_write_offset_ = kNoOffset;
|
||||
received_write_blob_uuid_ = std::string();
|
||||
received_cancel_ = false;
|
||||
}
|
||||
|
||||
bool received_truncate_;
|
||||
GURL received_truncate_path_;
|
||||
int64_t received_truncate_offset_;
|
||||
bool received_write_;
|
||||
GURL received_write_path_;
|
||||
std::string received_write_blob_uuid_;
|
||||
int64_t received_write_offset_;
|
||||
bool received_cancel_;
|
||||
|
||||
protected:
|
||||
void DoTruncate(const GURL& path, int64_t offset) override {
|
||||
received_truncate_ = true;
|
||||
received_truncate_path_ = path;
|
||||
received_truncate_offset_ = offset;
|
||||
|
||||
if (offset == kBasicFileTruncate_Offset) {
|
||||
DidSucceed();
|
||||
} else if (offset == kErrorFileTruncate_Offset) {
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND);
|
||||
} else if (offset == kCancelFileTruncate_Offset) {
|
||||
Cancel();
|
||||
DidSucceed(); // truncate completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else if (offset == kCancelFailedTruncate_Offset) {
|
||||
Cancel();
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND); // truncate completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void DoWrite(const GURL& path,
|
||||
const std::string& blob_uuid,
|
||||
int64_t offset) override {
|
||||
received_write_ = true;
|
||||
received_write_path_ = path;
|
||||
received_write_offset_ = offset;
|
||||
received_write_blob_uuid_ = blob_uuid;
|
||||
|
||||
if (offset == kBasicFileWrite_Offset) {
|
||||
DidWrite(1, true);
|
||||
} else if (offset == kErrorFileWrite_Offset) {
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND);
|
||||
} else if (offset == kMultiFileWrite_Offset) {
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, true);
|
||||
} else if (offset == kCancelFileWriteBeforeCompletion_Offset) {
|
||||
DidWrite(1, false);
|
||||
Cancel();
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidFail(base::File::FILE_ERROR_FAILED); // write completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else if (offset == kCancelFileWriteAfterCompletion_Offset) {
|
||||
DidWrite(1, false);
|
||||
Cancel();
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, true); // write completion
|
||||
DidFail(base::File::FILE_ERROR_FAILED); // cancel completion
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void DoCancel() override { received_cancel_ = true; }
|
||||
};
|
||||
|
||||
class FileWriterTest : public testing::Test,
|
||||
public blink::WebFileWriterClient {
|
||||
public:
|
||||
FileWriterTest() {
|
||||
reset();
|
||||
}
|
||||
|
||||
blink::WebFileWriter* writer() {
|
||||
return testable_writer_.get();
|
||||
}
|
||||
|
||||
// WebFileWriterClient overrides
|
||||
void DidWrite(long long bytes, bool complete) override {
|
||||
EXPECT_FALSE(received_did_write_complete_);
|
||||
++received_did_write_count_;
|
||||
received_did_write_bytes_total_ += bytes;
|
||||
if (complete)
|
||||
received_did_write_complete_ = true;
|
||||
|
||||
if (delete_in_client_callback_)
|
||||
testable_writer_.reset(nullptr);
|
||||
}
|
||||
|
||||
void DidTruncate() override {
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
received_did_truncate_ = true;
|
||||
if (delete_in_client_callback_)
|
||||
testable_writer_.reset(nullptr);
|
||||
}
|
||||
|
||||
void DidFail(blink::WebFileError error) override {
|
||||
EXPECT_FALSE(received_did_fail_);
|
||||
received_did_fail_ = true;
|
||||
fail_error_received_ = error;
|
||||
if (delete_in_client_callback_)
|
||||
testable_writer_.reset(nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset() {
|
||||
testable_writer_.reset(new TestableFileWriter(this));
|
||||
delete_in_client_callback_ = false;
|
||||
received_did_write_count_ = 0;
|
||||
received_did_write_bytes_total_ = 0;
|
||||
received_did_write_complete_ = false;
|
||||
received_did_truncate_ = false;
|
||||
received_did_fail_ = false;
|
||||
fail_error_received_ = static_cast<blink::WebFileError>(0);
|
||||
}
|
||||
|
||||
std::unique_ptr<TestableFileWriter> testable_writer_;
|
||||
bool delete_in_client_callback_;
|
||||
|
||||
// Observed WebFileWriterClient artifacts.
|
||||
int received_did_write_count_;
|
||||
long long received_did_write_bytes_total_;
|
||||
bool received_did_write_complete_;
|
||||
bool received_did_truncate_;
|
||||
bool received_did_fail_;
|
||||
blink::WebFileError fail_error_received_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FileWriterTest);
|
||||
};
|
||||
|
||||
TEST_F(FileWriterTest, BasicFileWrite) {
|
||||
// Call the webkit facing api.
|
||||
const std::string kBlobId("1234");
|
||||
writer()->Write(kBasicFileWrite_Offset, blink::WebString::FromUTF8(kBlobId));
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_,
|
||||
mock_path_as_gurl());
|
||||
EXPECT_EQ(kBasicFileWrite_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_EQ(1, received_did_write_count_);
|
||||
EXPECT_TRUE(received_did_write_complete_);
|
||||
EXPECT_EQ(1, received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
EXPECT_FALSE(received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, BasicFileTruncate) {
|
||||
// Call the webkit facing api.
|
||||
writer()->Truncate(kBasicFileTruncate_Offset);
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_gurl(),
|
||||
testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kBasicFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_truncate_);
|
||||
EXPECT_EQ(0, received_did_write_count_);
|
||||
EXPECT_FALSE(received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, ErrorFileWrite) {
|
||||
// Call the webkit facing api.
|
||||
const std::string kBlobId("1234");
|
||||
writer()->Write(kErrorFileWrite_Offset, blink::WebString::FromUTF8(kBlobId));
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_,
|
||||
mock_path_as_gurl());
|
||||
EXPECT_EQ(kErrorFileWrite_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorNotFound, fail_error_received_);
|
||||
EXPECT_EQ(0, received_did_write_count_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, ErrorFileTruncate) {
|
||||
// Call the webkit facing api.
|
||||
writer()->Truncate(kErrorFileTruncate_Offset);
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_gurl(),
|
||||
testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kErrorFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorNotFound, fail_error_received_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
EXPECT_EQ(0, received_did_write_count_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, MultiFileWrite) {
|
||||
// Call the webkit facing api.
|
||||
const std::string kBlobId("1234");
|
||||
writer()->Write(kMultiFileWrite_Offset, blink::WebString::FromUTF8(kBlobId));
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_,
|
||||
mock_path_as_gurl());
|
||||
EXPECT_EQ(kMultiFileWrite_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_EQ(3, received_did_write_count_);
|
||||
EXPECT_TRUE(received_did_write_complete_);
|
||||
EXPECT_EQ(3, received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
EXPECT_FALSE(received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileWriteBeforeCompletion) {
|
||||
// Call the webkit facing api.
|
||||
const std::string kBlobId("1234");
|
||||
writer()->Write(kCancelFileWriteBeforeCompletion_Offset,
|
||||
blink::WebString::FromUTF8(kBlobId));
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_,
|
||||
mock_path_as_gurl());
|
||||
EXPECT_EQ(kCancelFileWriteBeforeCompletion_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorAbort, fail_error_received_);
|
||||
EXPECT_EQ(1, received_did_write_count_);
|
||||
EXPECT_FALSE(received_did_write_complete_);
|
||||
EXPECT_EQ(1, received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileWriteAfterCompletion) {
|
||||
// Call the webkit facing api.
|
||||
const std::string kBlobId("1234");
|
||||
writer()->Write(kCancelFileWriteAfterCompletion_Offset,
|
||||
blink::WebString::FromUTF8(kBlobId));
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_,
|
||||
mock_path_as_gurl());
|
||||
EXPECT_EQ(kCancelFileWriteAfterCompletion_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorAbort, fail_error_received_);
|
||||
EXPECT_EQ(1, received_did_write_count_);
|
||||
EXPECT_FALSE(received_did_write_complete_);
|
||||
EXPECT_EQ(1, received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileTruncate) {
|
||||
// Call the webkit facing api.
|
||||
writer()->Truncate(kCancelFileTruncate_Offset);
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_gurl(),
|
||||
testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kCancelFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorAbort, fail_error_received_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
EXPECT_EQ(0, received_did_write_count_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFailedTruncate) {
|
||||
// Call the webkit facing api.
|
||||
writer()->Truncate(kCancelFailedTruncate_Offset);
|
||||
|
||||
// Check that the derived class gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_gurl(),
|
||||
testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kCancelFailedTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
|
||||
// Check that the client gets called correctly.
|
||||
EXPECT_TRUE(received_did_fail_);
|
||||
EXPECT_EQ(blink::kWebFileErrorAbort, fail_error_received_);
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
EXPECT_EQ(0, received_did_write_count_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, DeleteInCompletionCallbacks) {
|
||||
const std::string kBlobId("1234");
|
||||
delete_in_client_callback_ = true;
|
||||
writer()->Write(kBasicFileWrite_Offset, blink::WebString::FromUTF8(kBlobId));
|
||||
EXPECT_FALSE(testable_writer_.get());
|
||||
|
||||
reset();
|
||||
delete_in_client_callback_ = true;
|
||||
writer()->Truncate(kBasicFileTruncate_Offset);
|
||||
EXPECT_FALSE(testable_writer_.get());
|
||||
|
||||
reset();
|
||||
delete_in_client_callback_ = true;
|
||||
writer()->Write(kErrorFileWrite_Offset, blink::WebString::FromUTF8(kBlobId));
|
||||
EXPECT_FALSE(testable_writer_.get());
|
||||
|
||||
reset();
|
||||
delete_in_client_callback_ = true;
|
||||
writer()->Truncate(kErrorFileTruncate_Offset);
|
||||
EXPECT_FALSE(testable_writer_.get());
|
||||
|
||||
// Not crashing counts as passing.
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -1,67 +0,0 @@
|
||||
// Copyright 2013 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 "content/renderer/fileapi/webfilewriter_impl.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "content/public/renderer/worker_thread.h"
|
||||
#include "content/renderer/fileapi/file_system_dispatcher.h"
|
||||
#include "content/renderer/render_thread_impl.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
typedef FileSystemDispatcher::StatusCallback StatusCallback;
|
||||
typedef FileSystemDispatcher::WriteCallback WriteCallback;
|
||||
|
||||
WebFileWriterImpl::WebFileWriterImpl(
|
||||
const GURL& path,
|
||||
blink::WebFileWriterClient* client,
|
||||
Type type,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
|
||||
: WebFileWriterBase(path, client),
|
||||
request_id_(0),
|
||||
type_(type),
|
||||
file_system_dispatcher_(std::make_unique<FileSystemDispatcher>(
|
||||
std::move(main_thread_task_runner))) {}
|
||||
|
||||
WebFileWriterImpl::~WebFileWriterImpl() {}
|
||||
|
||||
void WebFileWriterImpl::DoTruncate(const GURL& path, int64_t offset) {
|
||||
if (type_ == TYPE_SYNC) {
|
||||
file_system_dispatcher_->TruncateSync(
|
||||
path, offset,
|
||||
base::Bind(&WebFileWriterImpl::DidFinish, base::Unretained(this)));
|
||||
} else {
|
||||
file_system_dispatcher_->Truncate(
|
||||
path, offset, &request_id_,
|
||||
base::Bind(&WebFileWriterImpl::DidFinish, base::Unretained(this)));
|
||||
}
|
||||
}
|
||||
|
||||
void WebFileWriterImpl::DoWrite(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset) {
|
||||
if (type_ == TYPE_SYNC) {
|
||||
file_system_dispatcher_->WriteSync(
|
||||
path, blob_id, offset,
|
||||
base::Bind(&WebFileWriterImpl::DidWrite, base::Unretained(this)),
|
||||
base::Bind(&WebFileWriterImpl::DidFinish, base::Unretained(this)));
|
||||
} else {
|
||||
file_system_dispatcher_->Write(
|
||||
path, blob_id, offset, &request_id_,
|
||||
base::Bind(&WebFileWriterImpl::DidWrite, base::Unretained(this)),
|
||||
base::Bind(&WebFileWriterImpl::DidFinish, base::Unretained(this)));
|
||||
}
|
||||
}
|
||||
|
||||
void WebFileWriterImpl::DoCancel() {
|
||||
DCHECK_EQ(type_, TYPE_ASYNC);
|
||||
file_system_dispatcher_->Cancel(
|
||||
request_id_,
|
||||
base::Bind(&WebFileWriterImpl::DidFinish, base::Unretained(this)));
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -1,54 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#ifndef CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_IMPL_H_
|
||||
#define CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_IMPL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "content/renderer/fileapi/webfilewriter_base.h"
|
||||
|
||||
namespace base {
|
||||
class SingleThreadTaskRunner;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
|
||||
class FileSystemDispatcher;
|
||||
|
||||
// An implementation of WebFileWriter for use in chrome renderers and workers.
|
||||
class WebFileWriterImpl : public WebFileWriterBase {
|
||||
public:
|
||||
enum Type {
|
||||
TYPE_SYNC,
|
||||
TYPE_ASYNC,
|
||||
};
|
||||
|
||||
WebFileWriterImpl(
|
||||
const GURL& path,
|
||||
blink::WebFileWriterClient* client,
|
||||
Type type,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
|
||||
~WebFileWriterImpl() override;
|
||||
|
||||
protected:
|
||||
// WebFileWriterBase overrides
|
||||
void DoTruncate(const GURL& path, int64_t offset) override;
|
||||
void DoWrite(const GURL& path,
|
||||
const std::string& blob_id,
|
||||
int64_t offset) override;
|
||||
void DoCancel() override;
|
||||
|
||||
private:
|
||||
int request_id_;
|
||||
Type type_;
|
||||
std::unique_ptr<FileSystemDispatcher> file_system_dispatcher_;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_RENDERER_FILEAPI_WEBFILEWRITER_IMPL_H_
|
@ -19,7 +19,7 @@
|
||||
#include "ppapi/shared_impl/resource_var.h"
|
||||
#include "ppapi/shared_impl/scoped_pp_var.h"
|
||||
#include "storage/common/fileapi/file_system_util.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_type.h"
|
||||
#include "third_party/blink/public/platform/web_media_stream_source.h"
|
||||
#include "third_party/blink/public/platform/web_media_stream_track.h"
|
||||
#include "third_party/blink/public/web/web_dom_file_system.h"
|
||||
@ -42,16 +42,15 @@ void FlushComplete(
|
||||
callback.Run(true);
|
||||
}
|
||||
|
||||
// Converts a blink::WebFileSystem::Type to a PP_FileSystemType.
|
||||
PP_FileSystemType WebFileSystemTypeToPPAPI(blink::WebFileSystem::Type type) {
|
||||
PP_FileSystemType WebFileSystemTypeToPPAPI(blink::WebFileSystemType type) {
|
||||
switch (type) {
|
||||
case blink::WebFileSystem::kTypeTemporary:
|
||||
case blink::WebFileSystemType::kWebFileSystemTypeTemporary:
|
||||
return PP_FILESYSTEMTYPE_LOCALTEMPORARY;
|
||||
case blink::WebFileSystem::kTypePersistent:
|
||||
case blink::WebFileSystemType::kWebFileSystemTypePersistent:
|
||||
return PP_FILESYSTEMTYPE_LOCALPERSISTENT;
|
||||
case blink::WebFileSystem::kTypeIsolated:
|
||||
case blink::WebFileSystemType::kWebFileSystemTypeIsolated:
|
||||
return PP_FILESYSTEMTYPE_ISOLATED;
|
||||
case blink::WebFileSystem::kTypeExternal:
|
||||
case blink::WebFileSystemType::kWebFileSystemTypeExternal:
|
||||
return PP_FILESYSTEMTYPE_EXTERNAL;
|
||||
default:
|
||||
NOTREACHED();
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "content/renderer/dom_storage/local_storage_namespace.h"
|
||||
#include "content/renderer/dom_storage/session_web_storage_namespace_impl.h"
|
||||
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
|
||||
#include "content/renderer/file_info_util.h"
|
||||
#include "content/renderer/fileapi/webfilesystem_impl.h"
|
||||
#include "content/renderer/image_capture/image_capture_frame_grabber.h"
|
||||
#include "content/renderer/indexed_db/webidbfactory_impl.h"
|
||||
@ -101,7 +100,6 @@
|
||||
#include "third_party/blink/public/platform/url_conversion.h"
|
||||
#include "third_party/blink/public/platform/web_audio_latency_hint.h"
|
||||
#include "third_party/blink/public/platform/web_blob_registry.h"
|
||||
#include "third_party/blink/public/platform/web_file_info.h"
|
||||
#include "third_party/blink/public/platform/web_media_recorder_handler.h"
|
||||
#include "third_party/blink/public/platform/web_media_stream_center.h"
|
||||
#include "third_party/blink/public/platform/web_rtc_certificate_generator.h"
|
||||
@ -146,7 +144,6 @@ using blink::WebAudioLatencyHint;
|
||||
using blink::WebBlobRegistry;
|
||||
using blink::WebCanvasCaptureHandler;
|
||||
using blink::WebDatabaseObserver;
|
||||
using blink::WebFileInfo;
|
||||
using blink::WebFileSystem;
|
||||
using blink::WebIDBFactory;
|
||||
using blink::WebImageCaptureFrameGrabber;
|
||||
|
@ -1677,7 +1677,6 @@ test("content_unittests") {
|
||||
"../renderer/dom_storage/local_storage_cached_areas_unittest.cc",
|
||||
"../renderer/dom_storage/mock_leveldb_wrapper.cc",
|
||||
"../renderer/dom_storage/mock_leveldb_wrapper.h",
|
||||
"../renderer/fileapi/webfilewriter_base_unittest.cc",
|
||||
"../renderer/gpu/actions_parser_unittest.cc",
|
||||
"../renderer/gpu/frame_swap_message_queue_unittest.cc",
|
||||
"../renderer/gpu/layer_tree_view_unittest.cc",
|
||||
|
@ -341,35 +341,6 @@ base::FilePath StringToFilePath(const std::string& file_path_string) {
|
||||
#endif
|
||||
}
|
||||
|
||||
blink::WebFileError FileErrorToWebFileError(
|
||||
base::File::Error error_code) {
|
||||
switch (error_code) {
|
||||
case base::File::FILE_ERROR_NOT_FOUND:
|
||||
return blink::kWebFileErrorNotFound;
|
||||
case base::File::FILE_ERROR_INVALID_OPERATION:
|
||||
case base::File::FILE_ERROR_EXISTS:
|
||||
case base::File::FILE_ERROR_NOT_EMPTY:
|
||||
return blink::kWebFileErrorInvalidModification;
|
||||
case base::File::FILE_ERROR_NOT_A_DIRECTORY:
|
||||
case base::File::FILE_ERROR_NOT_A_FILE:
|
||||
return blink::kWebFileErrorTypeMismatch;
|
||||
case base::File::FILE_ERROR_ACCESS_DENIED:
|
||||
return blink::kWebFileErrorNoModificationAllowed;
|
||||
case base::File::FILE_ERROR_FAILED:
|
||||
return blink::kWebFileErrorInvalidState;
|
||||
case base::File::FILE_ERROR_ABORT:
|
||||
return blink::kWebFileErrorAbort;
|
||||
case base::File::FILE_ERROR_SECURITY:
|
||||
return blink::kWebFileErrorSecurity;
|
||||
case base::File::FILE_ERROR_NO_SPACE:
|
||||
return blink::kWebFileErrorQuotaExceeded;
|
||||
case base::File::FILE_ERROR_INVALID_URL:
|
||||
return blink::kWebFileErrorEncoding;
|
||||
default:
|
||||
return blink::kWebFileErrorInvalidModification;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetFileSystemPublicType(
|
||||
const std::string type_string,
|
||||
blink::WebFileSystemType* type) {
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "storage/common/fileapi/file_system_types.h"
|
||||
#include "storage/common/storage_common_export.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_type.h"
|
||||
|
||||
class GURL;
|
||||
@ -133,10 +132,6 @@ STORAGE_COMMON_EXPORT std::string FilePathToString(
|
||||
STORAGE_COMMON_EXPORT base::FilePath StringToFilePath(
|
||||
const std::string& file_path_string);
|
||||
|
||||
// File error conversion
|
||||
STORAGE_COMMON_EXPORT blink::WebFileError
|
||||
FileErrorToWebFileError(base::File::Error error_code);
|
||||
|
||||
// Generate a file system name for the given arguments. Should only be used by
|
||||
// platform apps.
|
||||
STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemName(
|
||||
|
6
third_party/blink/public/BUILD.gn
vendored
6
third_party/blink/public/BUILD.gn
vendored
@ -245,15 +245,9 @@ source_set("blink_headers") {
|
||||
"platform/web_encrypted_media_key_information.h",
|
||||
"platform/web_encrypted_media_request.h",
|
||||
"platform/web_encrypted_media_types.h",
|
||||
"platform/web_file_error.h",
|
||||
"platform/web_file_info.h",
|
||||
"platform/web_file_system.h",
|
||||
"platform/web_file_system_callbacks.h",
|
||||
"platform/web_file_system_entry.h",
|
||||
"platform/web_file_system_type.h",
|
||||
"platform/web_file_utilities.h",
|
||||
"platform/web_file_writer.h",
|
||||
"platform/web_file_writer_client.h",
|
||||
"platform/web_float_point.h",
|
||||
"platform/web_float_point_3d.h",
|
||||
"platform/web_float_rect.h",
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_ERROR_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_ERROR_H_
|
||||
|
||||
namespace blink {
|
||||
|
||||
// File-related error code defined in HTML5 File API.
|
||||
enum WebFileError {
|
||||
kWebFileErrorNotFound = 1,
|
||||
kWebFileErrorSecurity = 2,
|
||||
kWebFileErrorAbort = 3,
|
||||
kWebFileErrorNotReadable = 4,
|
||||
kWebFileErrorEncoding = 5,
|
||||
kWebFileErrorNoModificationAllowed = 6,
|
||||
kWebFileErrorInvalidState = 7,
|
||||
kWebFileErrorSyntax = 8,
|
||||
kWebFileErrorInvalidModification = 9,
|
||||
kWebFileErrorQuotaExceeded = 10,
|
||||
kWebFileErrorTypeMismatch = 11,
|
||||
kWebFileErrorPathExists = 12,
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_INFO_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_INFO_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
struct WebFileInfo {
|
||||
// The last modification time of the file, in milliseconds since Epoch,
|
||||
// with a quiet NaN value representing "not known."
|
||||
double modification_time;
|
||||
|
||||
// The length of the file in bytes.
|
||||
// The value -1 means that the length is not set.
|
||||
long long length;
|
||||
|
||||
enum Type { kTypeUnknown = 0, kTypeFile, kTypeDirectory };
|
||||
|
||||
Type type;
|
||||
|
||||
WebString platform_path;
|
||||
|
||||
WebFileInfo() : modification_time(0.0), length(-1), type(kTypeUnknown) {}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_INFO_H_
|
156
third_party/blink/public/platform/web_file_system.h
vendored
156
third_party/blink/public/platform/web_file_system.h
vendored
@ -35,170 +35,16 @@
|
||||
#include "mojo/public/cpp/system/message_pipe.h"
|
||||
#include "third_party/blink/public/platform/web_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_common.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_type.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/public/platform/web_vector.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class WebFileWriter;
|
||||
class WebFileWriterClient;
|
||||
class WebFrame;
|
||||
|
||||
class WebFileSystem {
|
||||
public:
|
||||
enum Type {
|
||||
kTypeTemporary,
|
||||
kTypePersistent,
|
||||
|
||||
// Indicates an isolated filesystem which only exposes a set of files.
|
||||
kTypeIsolated,
|
||||
|
||||
// Indicates a non-sandboxed filesystem.
|
||||
kTypeExternal,
|
||||
};
|
||||
|
||||
// Opens a FileSystem.
|
||||
// WebFileSystemCallbacks::DidOpenFileSystem() must be called with
|
||||
// a name and root path for the requested FileSystem when the operation
|
||||
// is completed successfully. WebFileSystemCallbacks::DidFail() must be
|
||||
// called otherwise.
|
||||
virtual void OpenFileSystem(const WebURL& storage_partition,
|
||||
const WebFileSystemType,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Resolves a filesystem URL.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called with filesystem
|
||||
// information (name, root path and type) and file metadata (file path and
|
||||
// file type) when the operation is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void ResolveURL(const WebURL& file_system_url,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Deletes FileSystem.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation
|
||||
// is completed successfully. WebFileSystemCallbacks::DidFail() must be
|
||||
// called otherwise.
|
||||
// All in-flight operations and following operations may fail after the
|
||||
// FileSystem is deleted.
|
||||
virtual void DeleteFileSystem(const WebURL& storage_partition,
|
||||
const WebFileSystemType,
|
||||
WebFileSystemCallbacks) {}
|
||||
|
||||
// Moves a file or directory at |src_path| to |dest_path|.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void Move(const WebURL& src_path,
|
||||
const WebURL& dest_path,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Copies a file or directory at |src_path| to |dest_path|.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void Copy(const WebURL& src_path,
|
||||
const WebURL& dest_path,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Deletes a file or directory at a given |path|.
|
||||
// It is an error to try to remove a directory that is not empty.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void Remove(const WebURL& path, WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Deletes a file or directory recursively at a given |path|.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void RemoveRecursively(const WebURL& path,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Retrieves the metadata information of the file or directory at the given
|
||||
// |path|. This may not always return the local platform path in remote
|
||||
// filesystem cases. WebFileSystemCallbacks::DidReadMetadata() must be called
|
||||
// with a valid metadata when the retrieval is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void ReadMetadata(const WebURL& path, WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Creates a file at given |path|.
|
||||
// If the |path| doesn't exist, it creates a new file at |path|.
|
||||
// If |exclusive| is true, it fails if the |path| already exists.
|
||||
// If |exclusive| is false, it succeeds if the |path| already exists or
|
||||
// it has successfully created a new file at |path|.
|
||||
//
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void CreateFile(const WebURL& path,
|
||||
bool exclusive,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Creates a directory at a given |path|.
|
||||
// If the |path| doesn't exist, it creates a new directory at |path|.
|
||||
// If |exclusive| is true, it fails if the |path| already exists.
|
||||
// If |exclusive| is false, it succeeds if the |path| already exists or it has
|
||||
// successfully created a new directory at |path|.
|
||||
//
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when
|
||||
// the operation is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void CreateDirectory(const WebURL& path,
|
||||
bool exclusive,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Checks if a file exists at a given |path|.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void FileExists(const WebURL& path, WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Checks if a directory exists at a given |path|.
|
||||
// WebFileSystemCallbacks::DidSucceed() must be called when the operation is
|
||||
// completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void DirectoryExists(const WebURL& path, WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Reads directory entries of a given directory at |path| and returns a
|
||||
// callbacks ID which can be used to wait for additional results.
|
||||
// WebFileSystemCallbacks::DidReadDirectory() must be called when the
|
||||
// operation is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual int ReadDirectory(const WebURL& path, WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Creates a WebFileWriter that can be used to write to the given file.
|
||||
// WebFileSystemCallbacks::DidCreateFileWriter() must be called with the
|
||||
// created WebFileWriter when the operation is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void CreateFileWriter(const WebURL& path,
|
||||
WebFileWriterClient*,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
// Creates a blink::mojom::FileWriter that can be used to write to the given
|
||||
// file. The resulting FileWriter is passed as a ScopedMessagePipeHandle to
|
||||
// deal with converting between non-blink and blink mojom bindings variants.
|
||||
using CreateFileWriterCallbacks =
|
||||
WebCallbacks<mojo::ScopedMessagePipeHandle, base::File::Error>;
|
||||
virtual void CreateFileWriter(const WebURL& path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks>) = 0;
|
||||
|
||||
// Creates a snapshot file for a given file specified by |path|. It returns
|
||||
// the metadata of the created snapshot file. The returned metadata should
|
||||
// include a local platform path to the snapshot image. In local filesystem
|
||||
// cases the backend may simply return the metadata of the file itself (as
|
||||
// well as readMetadata does), while in remote filesystem case the backend may
|
||||
// download the file into a temporary snapshot file and return the metadata of
|
||||
// the temporary file.
|
||||
// The returned metadata is used to create a File object for the |path|.
|
||||
// The snapshot file is supposed to be deleted when the last reference to a
|
||||
// blink::File referring to it's path is dropped.
|
||||
// WebFileSystemCallbacks::DidCreateSnapshotFile() with the metadata of the
|
||||
// snapshot file must be called when the operation is completed successfully.
|
||||
// WebFileSystemCallbacks::DidFail() must be called otherwise.
|
||||
virtual void CreateSnapshotFileAndReadMetadata(const WebURL& path,
|
||||
WebFileSystemCallbacks) = 0;
|
||||
|
||||
struct FileSystemEntry {
|
||||
WebString file_system_id;
|
||||
WebString base_name;
|
||||
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_SYSTEM_CALLBACKS_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_SYSTEM_CALLBACKS_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_common.h"
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_entry.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_type.h"
|
||||
#include "third_party/blink/public/platform/web_private_ptr.h"
|
||||
#include "third_party/blink/public/platform/web_vector.h"
|
||||
|
||||
#if INSIDE_BLINK
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
namespace blink {
|
||||
|
||||
class AsyncFileSystemCallbacks;
|
||||
class WebFileWriter;
|
||||
class WebString;
|
||||
class WebURL;
|
||||
class WebFileSystemCallbacksPrivate;
|
||||
struct WebFileInfo;
|
||||
|
||||
class WebFileSystemCallbacks {
|
||||
public:
|
||||
~WebFileSystemCallbacks() { Reset(); }
|
||||
WebFileSystemCallbacks() = default;
|
||||
WebFileSystemCallbacks(const WebFileSystemCallbacks& c) { Assign(c); }
|
||||
WebFileSystemCallbacks& operator=(const WebFileSystemCallbacks& c) {
|
||||
Assign(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BLINK_PLATFORM_EXPORT void Reset();
|
||||
BLINK_PLATFORM_EXPORT void Assign(const WebFileSystemCallbacks&);
|
||||
|
||||
#if INSIDE_BLINK
|
||||
BLINK_PLATFORM_EXPORT WebFileSystemCallbacks(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>&&);
|
||||
#endif
|
||||
|
||||
// Callback for WebFileSystem's various operations that don't require
|
||||
// return values.
|
||||
BLINK_PLATFORM_EXPORT void DidSucceed();
|
||||
|
||||
// Callback for WebFileSystem::ReadMetadata. Called with the file metadata
|
||||
// for the requested path.
|
||||
BLINK_PLATFORM_EXPORT void DidReadMetadata(const WebFileInfo&);
|
||||
|
||||
// Callback for WebFileSystem::CreateSnapshot. The metadata also includes the
|
||||
// platform file path.
|
||||
BLINK_PLATFORM_EXPORT void DidCreateSnapshotFile(const WebFileInfo&);
|
||||
|
||||
// Callback for WebFileSystem::ReadDirectory. Called with a vector of
|
||||
// file entries in the requested directory. This callback might be called
|
||||
// multiple times if the directory has many entries. |has_more| must be
|
||||
// true when there are more entries.
|
||||
BLINK_PLATFORM_EXPORT void DidReadDirectory(
|
||||
const WebVector<WebFileSystemEntry>&,
|
||||
bool has_more);
|
||||
|
||||
// Callback for WebFileSystem::OpenFileSystem. Called with a name and
|
||||
// root URL for the FileSystem when the request is accepted.
|
||||
BLINK_PLATFORM_EXPORT void DidOpenFileSystem(const WebString& name,
|
||||
const WebURL& root_url);
|
||||
|
||||
// Callback for WebFileSystem::ResolveURL. Called with a name, root URL and
|
||||
// file path for the FileSystem when the request is accepted. |is_directory|
|
||||
// must be true when an entry to be resolved is a directory.
|
||||
BLINK_PLATFORM_EXPORT void DidResolveURL(const WebString& name,
|
||||
const WebURL& root_url,
|
||||
WebFileSystemType,
|
||||
const WebString& file_path,
|
||||
bool is_directory);
|
||||
|
||||
// Callback for WebFileSystem::CreateFileWriter. Called with an instance
|
||||
// of WebFileWriter and the target file length. The writer's ownership
|
||||
// is transferred to the callback.
|
||||
BLINK_PLATFORM_EXPORT void DidCreateFileWriter(WebFileWriter*,
|
||||
long long length);
|
||||
|
||||
// Called with an error code when a requested operation hasn't been
|
||||
// completed.
|
||||
BLINK_PLATFORM_EXPORT void DidFail(WebFileError);
|
||||
|
||||
// Returns true if the caller expects to be blocked until the request
|
||||
// is fullfilled.
|
||||
BLINK_PLATFORM_EXPORT bool ShouldBlockUntilCompletion() const;
|
||||
|
||||
private:
|
||||
WebPrivatePtr<WebFileSystemCallbacksPrivate> private_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_SYSTEM_ENTRY_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_SYSTEM_ENTRY_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
struct WebFileSystemEntry {
|
||||
WebFileSystemEntry() : is_directory(false) {}
|
||||
|
||||
// The name of the entry.
|
||||
WebString name;
|
||||
|
||||
// This flag indicates if the entry is directory or not.
|
||||
bool is_directory;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_SYSTEM_ENTRY_H_
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_WRITER_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_WRITER_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_common.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class WebString;
|
||||
|
||||
class WebFileWriter {
|
||||
public:
|
||||
virtual ~WebFileWriter() = default;
|
||||
|
||||
// Only one write or one truncate operation can be in progress at a time.
|
||||
// These functions are asynchronous and will report results through the
|
||||
// WebFileWriter's associated WebFileWriterClient.
|
||||
virtual void Write(long long position, const WebString& blob_uuid) {}
|
||||
virtual void Truncate(long long length) = 0;
|
||||
|
||||
// Cancel will attempt to abort a running write or truncate. However, it may
|
||||
// not be possible to cancel an in-progress action, or the call may have come
|
||||
// in too late. Partial writes are possible.
|
||||
// Do not call cancel when there is no write or truncate in progress.
|
||||
virtual void Cancel() = 0;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_WRITER_CLIENT_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_FILE_WRITER_CLIENT_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_common.h"
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class WebFileWriterClient {
|
||||
public:
|
||||
// Called for each chunk of a write, to indicate progress.
|
||||
// On the final chunk, when the write is finished, complete will be true.
|
||||
virtual void DidWrite(long long bytes, bool complete) = 0;
|
||||
|
||||
// Called once when the truncate completes successfully.
|
||||
virtual void DidTruncate() = 0;
|
||||
|
||||
// Called if the write or truncate fails, or if it is cancelled before the
|
||||
// write or truncate completes. Completion of an operation will be signalled
|
||||
// exactly once, either by DidFail, DidTruncate, or DidWrite(..., true).
|
||||
virtual void DidFail(WebFileError) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~WebFileWriterClient() = default;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif
|
@ -86,7 +86,7 @@ class WebDOMFileSystem {
|
||||
BLINK_EXPORT void Assign(const WebDOMFileSystem&);
|
||||
|
||||
BLINK_EXPORT WebString GetName() const;
|
||||
BLINK_EXPORT WebFileSystem::Type GetType() const;
|
||||
BLINK_EXPORT WebFileSystemType GetType() const;
|
||||
BLINK_EXPORT WebURL RootURL() const;
|
||||
|
||||
BLINK_EXPORT v8::Local<v8::Value> ToV8Value(
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_error.h"
|
||||
#include "third_party/blink/renderer/core/dom/dom_exception.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/assertions.h"
|
||||
@ -149,8 +148,10 @@ DOMExceptionCode FileErrorToExceptionCode(base::File::Error code) {
|
||||
return DOMExceptionCode::kNoError;
|
||||
case base::File::FILE_ERROR_FAILED:
|
||||
return DOMExceptionCode::kInvalidStateError;
|
||||
// TODO(https://crbug.com/883062): base::File::FILE_ERROR_EXISTS should map
|
||||
// to kPathExistsError, but that currently breaks tests. Fix the test
|
||||
// expectations and make the change.
|
||||
case base::File::FILE_ERROR_EXISTS:
|
||||
return DOMExceptionCode::kPathExistsError;
|
||||
case base::File::FILE_ERROR_NOT_EMPTY:
|
||||
case base::File::FILE_ERROR_INVALID_OPERATION:
|
||||
return DOMExceptionCode::kInvalidModificationError;
|
||||
@ -247,6 +248,26 @@ void ThrowDOMException(ExceptionState& exception_state,
|
||||
exception_state.ThrowDOMException(ErrorCodeToExceptionCode(code), message);
|
||||
}
|
||||
|
||||
void ThrowDOMException(ExceptionState& exception_state,
|
||||
base::File::Error error,
|
||||
String message) {
|
||||
if (error == base::File::FILE_OK)
|
||||
return;
|
||||
|
||||
// SecurityError is special-cased, as we want to route those exceptions
|
||||
// through ExceptionState::ThrowSecurityError.
|
||||
if (error == base::File::FILE_ERROR_SECURITY) {
|
||||
exception_state.ThrowSecurityError(kSecurityErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.IsNull()) {
|
||||
message = FileErrorToMessage(error);
|
||||
}
|
||||
|
||||
exception_state.ThrowDOMException(FileErrorToExceptionCode(error), message);
|
||||
}
|
||||
|
||||
DOMException* CreateDOMException(ErrorCode code) {
|
||||
DCHECK_NE(code, kOK);
|
||||
return DOMException::Create(ErrorCodeToExceptionCode(code),
|
||||
@ -259,20 +280,6 @@ DOMException* CreateDOMException(base::File::Error code) {
|
||||
FileErrorToMessage(code));
|
||||
}
|
||||
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorNotFound, kNotFoundErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorSecurity, kSecurityErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorAbort, kAbortErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorNotReadable, kNotReadableErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorEncoding, kEncodingErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorNoModificationAllowed,
|
||||
kNoModificationAllowedErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorInvalidState, kInvalidStateErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorSyntax, kSyntaxErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorInvalidModification, kInvalidModificationErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorQuotaExceeded, kQuotaExceededErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorTypeMismatch, kTypeMismatchErr);
|
||||
STATIC_ASSERT_ENUM(kWebFileErrorPathExists, kPathExistsErr);
|
||||
|
||||
} // namespace FileError
|
||||
|
||||
} // namespace blink
|
||||
|
@ -73,6 +73,9 @@ CORE_EXPORT extern const char kTypeMismatchErrorMessage[];
|
||||
CORE_EXPORT void ThrowDOMException(ExceptionState&,
|
||||
ErrorCode,
|
||||
String message = String());
|
||||
CORE_EXPORT void ThrowDOMException(ExceptionState& exception_state,
|
||||
base::File::Error error,
|
||||
String message = String());
|
||||
CORE_EXPORT DOMException* CreateDOMException(ErrorCode);
|
||||
CORE_EXPORT DOMException* CreateDOMException(base::File::Error);
|
||||
|
||||
|
1
third_party/blink/renderer/modules/BUILD.gn
vendored
1
third_party/blink/renderer/modules/BUILD.gn
vendored
@ -257,6 +257,7 @@ jumbo_source_set("unit_tests") {
|
||||
"document_metadata/copyless_paste_extractor_test.cc",
|
||||
"eventsource/event_source_parser_test.cc",
|
||||
"filesystem/dom_file_system_base_test.cc",
|
||||
"filesystem/file_writer_test.cc",
|
||||
"indexeddb/idb_key_path_test.cc",
|
||||
"indexeddb/idb_request_test.cc",
|
||||
"indexeddb/idb_test_helper.cc",
|
||||
|
@ -89,20 +89,20 @@ WebString WebDOMFileSystem::GetName() const {
|
||||
return private_->name();
|
||||
}
|
||||
|
||||
WebFileSystem::Type WebDOMFileSystem::GetType() const {
|
||||
WebFileSystemType WebDOMFileSystem::GetType() const {
|
||||
DCHECK(private_.Get());
|
||||
switch (private_->GetType()) {
|
||||
case blink::mojom::FileSystemType::kTemporary:
|
||||
return WebFileSystem::kTypeTemporary;
|
||||
return WebFileSystemType::kWebFileSystemTypeTemporary;
|
||||
case blink::mojom::FileSystemType::kPersistent:
|
||||
return WebFileSystem::kTypePersistent;
|
||||
return WebFileSystemType::kWebFileSystemTypePersistent;
|
||||
case blink::mojom::FileSystemType::kIsolated:
|
||||
return WebFileSystem::kTypeIsolated;
|
||||
return WebFileSystemType::kWebFileSystemTypeIsolated;
|
||||
case blink::mojom::FileSystemType::kExternal:
|
||||
return WebFileSystem::kTypeExternal;
|
||||
return WebFileSystemType::kWebFileSystemTypeExternal;
|
||||
default:
|
||||
NOTREACHED();
|
||||
return WebFileSystem::kTypeTemporary;
|
||||
return WebFileSystemType::kWebFileSystemTypeTemporary;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,8 @@ blink_modules_sources("filesystem") {
|
||||
"file_system_directory_handle.h",
|
||||
"file_system_directory_iterator.cc",
|
||||
"file_system_directory_iterator.h",
|
||||
"file_system_dispatcher.cc",
|
||||
"file_system_dispatcher.h",
|
||||
"file_system_file_handle.cc",
|
||||
"file_system_file_handle.h",
|
||||
"file_system_writer.cc",
|
||||
@ -72,4 +74,9 @@ blink_modules_sources("filesystem") {
|
||||
"worker_global_scope_file_system.cc",
|
||||
"worker_global_scope_file_system.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//components/services/filesystem/public/interfaces:interfaces_blink",
|
||||
"//third_party/blink/renderer/platform",
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
include_rules = [
|
||||
"+base/files/file.h",
|
||||
"-third_party/blink/renderer/modules",
|
||||
"+third_party/blink/renderer/modules/event_target_modules.h",
|
||||
"+third_party/blink/renderer/modules/filesystem",
|
||||
|
@ -77,7 +77,7 @@ class DirectoryReader::ErrorCallbackHelper final : public ErrorCallbackBase {
|
||||
return new ErrorCallbackHelper(reader);
|
||||
}
|
||||
|
||||
void Invoke(FileError::ErrorCode error) override { reader_->OnError(error); }
|
||||
void Invoke(base::File::Error error) override { reader_->OnError(error); }
|
||||
|
||||
void Trace(blink::Visitor* visitor) override {
|
||||
visitor->Trace(reader_);
|
||||
@ -103,7 +103,7 @@ void DirectoryReader::readEntries(V8EntriesCallback* entries_callback,
|
||||
ErrorCallbackHelper::Create(this));
|
||||
}
|
||||
|
||||
if (error_) {
|
||||
if (error_ != base::File::FILE_OK) {
|
||||
Filesystem()->ReportError(ScriptErrorCallback::Wrap(error_callback),
|
||||
error_);
|
||||
return;
|
||||
@ -113,7 +113,7 @@ void DirectoryReader::readEntries(V8EntriesCallback* entries_callback,
|
||||
// Non-null entries_callback_ means multiple readEntries() calls are made
|
||||
// concurrently. We don't allow doing it.
|
||||
Filesystem()->ReportError(ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kInvalidStateErr);
|
||||
base::File::FILE_ERROR_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ void DirectoryReader::AddEntries(const EntryHeapVector& entries) {
|
||||
}
|
||||
}
|
||||
|
||||
void DirectoryReader::OnError(FileError::ErrorCode error) {
|
||||
void DirectoryReader::OnError(base::File::Error error) {
|
||||
error_ = error;
|
||||
entries_callback_ = nullptr;
|
||||
if (auto* error_callback = error_callback_.Release()) {
|
||||
|
@ -67,11 +67,11 @@ class DirectoryReader : public DirectoryReaderBase {
|
||||
|
||||
void AddEntries(const EntryHeapVector& entries);
|
||||
|
||||
void OnError(FileError::ErrorCode);
|
||||
void OnError(base::File::Error error);
|
||||
|
||||
bool is_reading_;
|
||||
EntryHeapVector entries_;
|
||||
FileError::ErrorCode error_ = FileError::ErrorCode::kOK;
|
||||
base::File::Error error_ = base::File::FILE_OK;
|
||||
Member<V8PersistentCallbackInterface<V8EntriesCallback>> entries_callback_;
|
||||
Member<V8PersistentCallbackInterface<V8ErrorCallback>> error_callback_;
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ class DirectoryReaderSync::ErrorCallbackHelper final
|
||||
ErrorCallbackBase::Trace(visitor);
|
||||
}
|
||||
|
||||
void Invoke(FileError::ErrorCode error) override {
|
||||
void Invoke(base::File::Error error) override {
|
||||
reader_->error_code_ = error;
|
||||
}
|
||||
|
||||
@ -94,15 +94,16 @@ DirectoryReaderSync::DirectoryReaderSync(DOMFileSystemBase* file_system,
|
||||
|
||||
EntrySyncHeapVector DirectoryReaderSync::readEntries(
|
||||
ExceptionState& exception_state) {
|
||||
if (!callbacks_id_) {
|
||||
callbacks_id_ = Filesystem()->ReadDirectory(
|
||||
if (!has_called_read_directory_) {
|
||||
Filesystem()->ReadDirectory(
|
||||
this, full_path_, EntriesCallbackHelper::Create(this),
|
||||
ErrorCallbackHelper::Create(this), DOMFileSystemBase::kSynchronous);
|
||||
has_called_read_directory_ = true;
|
||||
}
|
||||
|
||||
DCHECK(!has_more_entries_);
|
||||
|
||||
if (error_code_ != FileError::kOK) {
|
||||
if (error_code_ != base::File::FILE_OK) {
|
||||
FileError::ThrowDOMException(exception_state, error_code_);
|
||||
return EntrySyncHeapVector();
|
||||
}
|
||||
|
@ -64,9 +64,9 @@ class DirectoryReaderSync : public DirectoryReaderBase {
|
||||
|
||||
DirectoryReaderSync(DOMFileSystemBase*, const String& full_path);
|
||||
|
||||
int callbacks_id_ = 0;
|
||||
bool has_called_read_directory_ = false;
|
||||
EntrySyncHeapVector entries_;
|
||||
FileError::ErrorCode error_code_ = FileError::kOK;
|
||||
base::File::Error error_code_ = base::File::FILE_OK;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -34,13 +34,13 @@
|
||||
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_security_origin.h"
|
||||
#include "third_party/blink/renderer/core/probe/core_probes.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/directory_entry.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/dom_file_path.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_entry.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer.h"
|
||||
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
|
||||
@ -126,18 +126,18 @@ bool DOMFileSystem::HasPendingActivity() const {
|
||||
}
|
||||
|
||||
void DOMFileSystem::ReportError(ErrorCallbackBase* error_callback,
|
||||
FileError::ErrorCode file_error) {
|
||||
ReportError(GetExecutionContext(), error_callback, file_error);
|
||||
base::File::Error error) {
|
||||
ReportError(GetExecutionContext(), error_callback, error);
|
||||
}
|
||||
|
||||
void DOMFileSystem::ReportError(ExecutionContext* execution_context,
|
||||
ErrorCallbackBase* error_callback,
|
||||
FileError::ErrorCode file_error) {
|
||||
base::File::Error error) {
|
||||
if (!error_callback)
|
||||
return;
|
||||
ScheduleCallback(execution_context,
|
||||
WTF::Bind(&ErrorCallbackBase::Invoke,
|
||||
WrapPersistent(error_callback), file_error));
|
||||
WrapPersistent(error_callback), error));
|
||||
}
|
||||
|
||||
void DOMFileSystem::CreateWriter(
|
||||
@ -146,17 +146,12 @@ void DOMFileSystem::CreateWriter(
|
||||
ErrorCallbackBase* error_callback) {
|
||||
DCHECK(file_entry);
|
||||
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
FileWriter* file_writer = FileWriter::Create(GetExecutionContext());
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
|
||||
FileWriterCallbacks::Create(file_writer, success_callback, error_callback,
|
||||
context_);
|
||||
FileSystem()->CreateFileWriter(CreateFileSystemURL(file_entry), file_writer,
|
||||
std::move(callbacks));
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().InitializeFileWriter(
|
||||
CreateFileSystemURL(file_entry), std::move(callbacks));
|
||||
}
|
||||
|
||||
void DOMFileSystem::CreateFile(
|
||||
@ -164,12 +159,8 @@ void DOMFileSystem::CreateFile(
|
||||
SnapshotFileCallback::OnDidCreateSnapshotFileCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback) {
|
||||
KURL file_system_url = CreateFileSystemURL(file_entry);
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystem()->CreateSnapshotFileAndReadMetadata(
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().CreateSnapshotFile(
|
||||
file_system_url,
|
||||
SnapshotFileCallback::Create(this, file_entry->name(), file_system_url,
|
||||
success_callback, error_callback, context_));
|
||||
|
@ -67,11 +67,11 @@ class MODULES_EXPORT DOMFileSystem final
|
||||
// DOMFileSystemBase overrides.
|
||||
void AddPendingCallbacks() override;
|
||||
void RemovePendingCallbacks() override;
|
||||
void ReportError(ErrorCallbackBase*, FileError::ErrorCode) override;
|
||||
void ReportError(ErrorCallbackBase*, base::File::Error error) override;
|
||||
|
||||
static void ReportError(ExecutionContext*,
|
||||
ErrorCallbackBase*,
|
||||
FileError::ErrorCode);
|
||||
base::File::Error error);
|
||||
|
||||
// ScriptWrappable overrides.
|
||||
bool HasPendingActivity() const final;
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <memory>
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
#include "third_party/blink/public/platform/web_security_origin.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file.h"
|
||||
@ -44,6 +43,7 @@
|
||||
#include "third_party/blink/renderer/modules/filesystem/entry.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/entry_base.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/assertions.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
|
||||
@ -217,15 +217,17 @@ void DOMFileSystemBase::GetMetadata(
|
||||
MetadataCallbacks::OnDidReadMetadataCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::Create(
|
||||
success_callback, error_callback, context_, this));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
FileSystem()->ReadMetadata(CreateFileSystemURL(entry), std::move(callbacks));
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
|
||||
if (synchronous_type == kSynchronous) {
|
||||
dispatcher.ReadMetadataSync(CreateFileSystemURL(entry),
|
||||
std::move(callbacks));
|
||||
} else {
|
||||
dispatcher.ReadMetadata(CreateFileSystemURL(entry), std::move(callbacks));
|
||||
}
|
||||
}
|
||||
|
||||
static bool VerifyAndGetDestinationPathForCopyOrMove(const EntryBase* source,
|
||||
@ -272,27 +274,26 @@ void DOMFileSystemBase::Move(
|
||||
EntryCallbacks::OnDidGetEntryCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
String destination_path;
|
||||
if (!VerifyAndGetDestinationPathForCopyOrMove(source, parent, new_name,
|
||||
destination_path)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::Create(
|
||||
success_callback, error_callback, context_, parent->filesystem(),
|
||||
destination_path, source->isDirectory()));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
|
||||
FileSystem()->Move(
|
||||
CreateFileSystemURL(source),
|
||||
parent->filesystem()->CreateFileSystemURL(destination_path),
|
||||
std::move(callbacks));
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
const KURL& src = CreateFileSystemURL(source);
|
||||
const KURL& dest =
|
||||
parent->filesystem()->CreateFileSystemURL(destination_path);
|
||||
if (synchronous_type == kSynchronous)
|
||||
dispatcher.MoveSync(src, dest, std::move(callbacks));
|
||||
else
|
||||
dispatcher.Move(src, dest, std::move(callbacks));
|
||||
}
|
||||
|
||||
void DOMFileSystemBase::Copy(
|
||||
@ -302,27 +303,26 @@ void DOMFileSystemBase::Copy(
|
||||
EntryCallbacks::OnDidGetEntryCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
String destination_path;
|
||||
if (!VerifyAndGetDestinationPathForCopyOrMove(source, parent, new_name,
|
||||
destination_path)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::Create(
|
||||
success_callback, error_callback, context_, parent->filesystem(),
|
||||
destination_path, source->isDirectory()));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
|
||||
FileSystem()->Copy(
|
||||
CreateFileSystemURL(source),
|
||||
parent->filesystem()->CreateFileSystemURL(destination_path),
|
||||
std::move(callbacks));
|
||||
const KURL& src = CreateFileSystemURL(source);
|
||||
const KURL& dest =
|
||||
parent->filesystem()->CreateFileSystemURL(destination_path);
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
if (synchronous_type == kSynchronous)
|
||||
dispatcher.CopySync(src, dest, std::move(callbacks));
|
||||
else
|
||||
dispatcher.Copy(src, dest, std::move(callbacks));
|
||||
}
|
||||
|
||||
void DOMFileSystemBase::Remove(
|
||||
@ -330,23 +330,22 @@ void DOMFileSystemBase::Remove(
|
||||
VoidCallbacks::OnDidSucceedCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(entry);
|
||||
// We don't allow calling remove() on the root directory.
|
||||
if (entry->fullPath() == String(DOMFilePath::kRoot)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(
|
||||
VoidCallbacks::Create(success_callback, error_callback, context_, this));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
|
||||
FileSystem()->Remove(CreateFileSystemURL(entry), std::move(callbacks));
|
||||
const KURL& url = CreateFileSystemURL(entry);
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
if (synchronous_type == kSynchronous)
|
||||
dispatcher.RemoveSync(url, /*recursive=*/false, std::move(callbacks));
|
||||
else
|
||||
dispatcher.Remove(url, /*recursive=*/false, std::move(callbacks));
|
||||
}
|
||||
|
||||
void DOMFileSystemBase::RemoveRecursively(
|
||||
@ -354,41 +353,34 @@ void DOMFileSystemBase::RemoveRecursively(
|
||||
VoidCallbacks::OnDidSucceedCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(entry);
|
||||
DCHECK(entry->isDirectory());
|
||||
// We don't allow calling remove() on the root directory.
|
||||
if (entry->fullPath() == String(DOMFilePath::kRoot)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(
|
||||
VoidCallbacks::Create(success_callback, error_callback, context_, this));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
|
||||
FileSystem()->RemoveRecursively(CreateFileSystemURL(entry),
|
||||
std::move(callbacks));
|
||||
const KURL& url = CreateFileSystemURL(entry);
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
if (synchronous_type == kSynchronous)
|
||||
dispatcher.RemoveSync(url, /*recursive=*/true, std::move(callbacks));
|
||||
else
|
||||
dispatcher.Remove(url, /*recursive=*/true, std::move(callbacks));
|
||||
}
|
||||
|
||||
void DOMFileSystemBase::GetParent(
|
||||
const EntryBase* entry,
|
||||
EntryCallbacks::OnDidGetEntryCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(entry);
|
||||
String path = DOMFilePath::GetDirectory(entry->fullPath());
|
||||
|
||||
FileSystem()->DirectoryExists(
|
||||
CreateFileSystemURL(path),
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().Exists(
|
||||
CreateFileSystemURL(path), /*is_directory=*/true,
|
||||
EntryCallbacks::Create(success_callback, error_callback, context_, this,
|
||||
path, true));
|
||||
}
|
||||
@ -400,27 +392,30 @@ void DOMFileSystemBase::GetFile(
|
||||
EntryCallbacks::OnDidGetEntryCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
String absolute_path;
|
||||
if (!PathToAbsolutePath(type_, entry, path, absolute_path)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::Create(
|
||||
success_callback, error_callback, context_, this, absolute_path, false));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
const KURL& url = CreateFileSystemURL(absolute_path);
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
|
||||
if (flags.createFlag())
|
||||
FileSystem()->CreateFile(CreateFileSystemURL(absolute_path),
|
||||
flags.exclusive(), std::move(callbacks));
|
||||
else
|
||||
FileSystem()->FileExists(CreateFileSystemURL(absolute_path),
|
||||
std::move(callbacks));
|
||||
if (flags.createFlag()) {
|
||||
if (synchronous_type == kSynchronous)
|
||||
dispatcher.CreateFileSync(url, flags.exclusive(), std::move(callbacks));
|
||||
else
|
||||
dispatcher.CreateFile(url, flags.exclusive(), std::move(callbacks));
|
||||
} else {
|
||||
if (synchronous_type == kSynchronous) {
|
||||
dispatcher.ExistsSync(url, /*is_directory=*/false, std::move(callbacks));
|
||||
} else {
|
||||
dispatcher.Exists(url, /*is_directory=*/false, std::move(callbacks));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DOMFileSystemBase::GetDirectory(
|
||||
@ -430,57 +425,53 @@ void DOMFileSystemBase::GetDirectory(
|
||||
EntryCallbacks::OnDidGetEntryCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return;
|
||||
}
|
||||
|
||||
String absolute_path;
|
||||
if (!PathToAbsolutePath(type_, entry, path, absolute_path)) {
|
||||
ReportError(error_callback, FileError::kInvalidModificationErr);
|
||||
ReportError(error_callback, base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::Create(
|
||||
success_callback, error_callback, context_, this, absolute_path, true));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
const KURL& url = CreateFileSystemURL(absolute_path);
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
|
||||
if (flags.createFlag())
|
||||
FileSystem()->CreateDirectory(CreateFileSystemURL(absolute_path),
|
||||
flags.exclusive(), std::move(callbacks));
|
||||
else
|
||||
FileSystem()->DirectoryExists(CreateFileSystemURL(absolute_path),
|
||||
std::move(callbacks));
|
||||
if (flags.createFlag()) {
|
||||
if (synchronous_type == kSynchronous) {
|
||||
dispatcher.CreateDirectorySync(url, flags.exclusive(),
|
||||
/*recursive=*/false, std::move(callbacks));
|
||||
} else {
|
||||
dispatcher.CreateDirectory(url, flags.exclusive(), /*recursive=*/false,
|
||||
std::move(callbacks));
|
||||
}
|
||||
} else {
|
||||
if (synchronous_type == kSynchronous) {
|
||||
dispatcher.ExistsSync(url, /*is_directory=*/true, std::move(callbacks));
|
||||
} else {
|
||||
dispatcher.Exists(url, /*is_directory=*/true, std::move(callbacks));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DOMFileSystemBase::ReadDirectory(
|
||||
void DOMFileSystemBase::ReadDirectory(
|
||||
DirectoryReaderBase* reader,
|
||||
const String& path,
|
||||
EntriesCallbacks::OnDidGetEntriesCallback* success_callback,
|
||||
ErrorCallbackBase* error_callback,
|
||||
SynchronousType synchronous_type) {
|
||||
if (!FileSystem()) {
|
||||
ReportError(error_callback, FileError::kAbortErr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DCHECK(DOMFilePath::IsAbsolute(path));
|
||||
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::Create(
|
||||
success_callback, error_callback, context_, reader, path));
|
||||
callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous);
|
||||
|
||||
return FileSystem()->ReadDirectory(CreateFileSystemURL(path),
|
||||
std::move(callbacks));
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
const KURL& url = CreateFileSystemURL(path);
|
||||
if (synchronous_type == kSynchronous) {
|
||||
dispatcher.ReadDirectorySync(url, std::move(callbacks));
|
||||
} else {
|
||||
dispatcher.ReadDirectory(url, std::move(callbacks));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_ASSERT_ENUM(WebFileSystem::kTypeTemporary,
|
||||
mojom::blink::FileSystemType::kTemporary);
|
||||
STATIC_ASSERT_ENUM(WebFileSystem::kTypePersistent,
|
||||
mojom::blink::FileSystemType::kPersistent);
|
||||
STATIC_ASSERT_ENUM(WebFileSystem::kTypeExternal,
|
||||
mojom::blink::FileSystemType::kExternal);
|
||||
STATIC_ASSERT_ENUM(WebFileSystem::kTypeIsolated,
|
||||
mojom::blink::FileSystemType::kIsolated);
|
||||
|
||||
} // namespace blink
|
||||
|
@ -78,7 +78,7 @@ class MODULES_EXPORT DOMFileSystemBase : public ScriptWrappable {
|
||||
virtual void RemovePendingCallbacks() {}
|
||||
|
||||
// Overridden by subclasses to handle sync vs async error-handling.
|
||||
virtual void ReportError(ErrorCallbackBase*, FileError::ErrorCode) = 0;
|
||||
virtual void ReportError(ErrorCallbackBase*, base::File::Error error) = 0;
|
||||
|
||||
const String& name() const { return name_; }
|
||||
mojom::blink::FileSystemType GetType() const { return type_; }
|
||||
@ -150,11 +150,11 @@ class MODULES_EXPORT DOMFileSystemBase : public ScriptWrappable {
|
||||
EntryCallbacks::OnDidGetEntryCallback*,
|
||||
ErrorCallbackBase*,
|
||||
SynchronousType = kAsynchronous);
|
||||
int ReadDirectory(DirectoryReaderBase*,
|
||||
const String& path,
|
||||
EntriesCallbacks::OnDidGetEntriesCallback*,
|
||||
ErrorCallbackBase*,
|
||||
SynchronousType = kAsynchronous);
|
||||
void ReadDirectory(DirectoryReaderBase*,
|
||||
const String& path,
|
||||
EntriesCallbacks::OnDidGetEntriesCallback*,
|
||||
ErrorCallbackBase*,
|
||||
SynchronousType = kAsynchronous);
|
||||
|
||||
void Trace(blink::Visitor*) override;
|
||||
|
||||
|
@ -34,13 +34,13 @@
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/directory_entry_sync.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/dom_file_path.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_entry_sync.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer_sync.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/sync_callback_helper.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
|
||||
@ -65,8 +65,8 @@ DOMFileSystemSync::DOMFileSystemSync(ExecutionContext* context,
|
||||
DOMFileSystemSync::~DOMFileSystemSync() = default;
|
||||
|
||||
void DOMFileSystemSync::ReportError(ErrorCallbackBase* error_callback,
|
||||
FileError::ErrorCode file_error) {
|
||||
error_callback->Invoke(file_error);
|
||||
base::File::Error error) {
|
||||
error_callback->Invoke(error);
|
||||
}
|
||||
|
||||
DirectoryEntrySync* DOMFileSystemSync::root() {
|
||||
@ -82,13 +82,13 @@ class CreateFileHelper final : public AsyncFileSystemCallbacks {
|
||||
static CreateFileResult* Create() { return new CreateFileResult(); }
|
||||
|
||||
bool failed_;
|
||||
int code_;
|
||||
base::File::Error error_;
|
||||
Member<File> file_;
|
||||
|
||||
void Trace(blink::Visitor* visitor) { visitor->Trace(file_); }
|
||||
|
||||
private:
|
||||
CreateFileResult() : failed_(false), code_(0) {}
|
||||
CreateFileResult() : failed_(false), error_(base::File::FILE_OK) {}
|
||||
};
|
||||
|
||||
static std::unique_ptr<AsyncFileSystemCallbacks> Create(
|
||||
@ -100,9 +100,9 @@ class CreateFileHelper final : public AsyncFileSystemCallbacks {
|
||||
new CreateFileHelper(result, name, url, type)));
|
||||
}
|
||||
|
||||
void DidFail(int code) override {
|
||||
void DidFail(base::File::Error error) override {
|
||||
result_->failed_ = true;
|
||||
result_->code_ = code;
|
||||
result_->error_ = error;
|
||||
}
|
||||
|
||||
~CreateFileHelper() override = default;
|
||||
@ -120,8 +120,6 @@ class CreateFileHelper final : public AsyncFileSystemCallbacks {
|
||||
DOMFileSystemBase::CreateFile(metadata, url_, type_, name_);
|
||||
}
|
||||
|
||||
bool ShouldBlockUntilCompletion() const override { return true; }
|
||||
|
||||
private:
|
||||
CreateFileHelper(CreateFileResult* result,
|
||||
const String& name,
|
||||
@ -142,12 +140,12 @@ File* DOMFileSystemSync::CreateFile(const FileEntrySync* file_entry,
|
||||
KURL file_system_url = CreateFileSystemURL(file_entry);
|
||||
CreateFileHelper::CreateFileResult* result(
|
||||
CreateFileHelper::CreateFileResult::Create());
|
||||
FileSystem()->CreateSnapshotFileAndReadMetadata(
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().CreateSnapshotFileSync(
|
||||
file_system_url, CreateFileHelper::Create(result, file_entry->name(),
|
||||
file_system_url, GetType()));
|
||||
if (result->failed_) {
|
||||
FileError::ThrowDOMException(
|
||||
exception_state, static_cast<FileError::ErrorCode>(result->code_),
|
||||
exception_state, result->error_,
|
||||
"Could not create '" + file_entry->name() + "'.");
|
||||
return nullptr;
|
||||
}
|
||||
@ -167,10 +165,9 @@ FileWriterSync* DOMFileSystemSync::CreateWriter(
|
||||
FileWriterCallbacks::Create(file_writer,
|
||||
sync_helper->GetSuccessCallback(),
|
||||
sync_helper->GetErrorCallback(), context_);
|
||||
callbacks->SetShouldBlockUntilCompletion(true);
|
||||
|
||||
FileSystem()->CreateFileWriter(CreateFileSystemURL(file_entry), file_writer,
|
||||
std::move(callbacks));
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().InitializeFileWriterSync(
|
||||
CreateFileSystemURL(file_entry), std::move(callbacks));
|
||||
|
||||
FileWriterBase* success = sync_helper->GetResultOrThrow(exception_state);
|
||||
return success ? file_writer : nullptr;
|
||||
|
@ -57,7 +57,7 @@ class DOMFileSystemSync final : public DOMFileSystemBase {
|
||||
|
||||
~DOMFileSystemSync() override;
|
||||
|
||||
void ReportError(ErrorCallbackBase*, FileError::ErrorCode) override;
|
||||
void ReportError(ErrorCallbackBase*, base::File::Error error) override;
|
||||
|
||||
DirectoryEntrySync* root();
|
||||
|
||||
|
@ -60,7 +60,7 @@ void DOMWindowFileSystem::webkitRequestFileSystem(
|
||||
if (!document->GetSecurityOrigin()->CanAccessFileSystem()) {
|
||||
DOMFileSystem::ReportError(document,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kSecurityErr);
|
||||
base::File::FILE_ERROR_SECURITY);
|
||||
return;
|
||||
} else if (document->GetSecurityOrigin()->IsLocal()) {
|
||||
UseCounter::Count(document, WebFeature::kFileAccessedFileSystem);
|
||||
@ -71,7 +71,7 @@ void DOMWindowFileSystem::webkitRequestFileSystem(
|
||||
if (!DOMFileSystemBase::IsValidType(file_system_type)) {
|
||||
DOMFileSystem::ReportError(document,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kInvalidModificationErr);
|
||||
base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -81,7 +81,8 @@ void DOMWindowFileSystem::webkitRequestFileSystem(
|
||||
FileSystemCallbacks::OnDidOpenFileSystemV8Impl::Create(
|
||||
success_callback),
|
||||
ScriptErrorCallback::Wrap(error_callback), document,
|
||||
file_system_type));
|
||||
file_system_type),
|
||||
LocalFileSystem::kAsynchronous);
|
||||
}
|
||||
|
||||
void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(
|
||||
@ -102,7 +103,7 @@ void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(
|
||||
!security_origin->CanRequest(completed_url)) {
|
||||
DOMFileSystem::ReportError(document,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kSecurityErr);
|
||||
base::File::FILE_ERROR_SECURITY);
|
||||
return;
|
||||
} else if (document->GetSecurityOrigin()->IsLocal()) {
|
||||
UseCounter::Count(document, WebFeature::kFileAccessedFileSystem);
|
||||
@ -111,7 +112,7 @@ void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(
|
||||
if (!completed_url.IsValid()) {
|
||||
DOMFileSystem::ReportError(document,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kEncodingErr);
|
||||
base::File::FILE_ERROR_INVALID_URL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -119,7 +120,8 @@ void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(
|
||||
document, completed_url,
|
||||
ResolveURICallbacks::Create(
|
||||
ResolveURICallbacks::OnDidGetEntryV8Impl::Create(success_callback),
|
||||
ScriptErrorCallback::Wrap(error_callback), document));
|
||||
ScriptErrorCallback::Wrap(error_callback), document),
|
||||
LocalFileSystem::kAsynchronous);
|
||||
}
|
||||
|
||||
static_assert(
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
|
||||
#include "third_party/blink/renderer/core/dom/dom_exception.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
@ -72,17 +71,15 @@ FileSystemCallbacksBase::~FileSystemCallbacksBase() {
|
||||
file_system_->RemovePendingCallbacks();
|
||||
}
|
||||
|
||||
void FileSystemCallbacksBase::DidFail(int code) {
|
||||
void FileSystemCallbacksBase::DidFail(base::File::Error error) {
|
||||
if (error_callback_) {
|
||||
InvokeOrScheduleCallback(&ErrorCallbackBase::Invoke,
|
||||
error_callback_.Release(),
|
||||
static_cast<FileError::ErrorCode>(code));
|
||||
error_callback_.Release(), error);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSystemCallbacksBase::ShouldScheduleCallback() const {
|
||||
return !ShouldBlockUntilCompletion() && execution_context_ &&
|
||||
execution_context_->IsContextPaused();
|
||||
return execution_context_ && execution_context_->IsContextPaused();
|
||||
}
|
||||
|
||||
template <typename CallbackMemberFunction,
|
||||
@ -122,7 +119,7 @@ void ScriptErrorCallback::Trace(blink::Visitor* visitor) {
|
||||
visitor->Trace(callback_);
|
||||
}
|
||||
|
||||
void ScriptErrorCallback::Invoke(FileError::ErrorCode error) {
|
||||
void ScriptErrorCallback::Invoke(base::File::Error error) {
|
||||
callback_->InvokeAndReportException(nullptr,
|
||||
FileError::CreateDOMException(error));
|
||||
};
|
||||
@ -140,7 +137,7 @@ void PromiseErrorCallback::Trace(Visitor* visitor) {
|
||||
visitor->Trace(resolver_);
|
||||
}
|
||||
|
||||
void PromiseErrorCallback::Invoke(FileError::ErrorCode error) {
|
||||
void PromiseErrorCallback::Invoke(base::File::Error error) {
|
||||
resolver_->Reject(FileError::CreateDOMException(error));
|
||||
}
|
||||
|
||||
@ -339,7 +336,7 @@ void ResolveURICallbacks::DidResolveURL(const String& name,
|
||||
String absolute_path;
|
||||
if (!DOMFileSystemBase::PathToAbsolutePath(type, root, file_path,
|
||||
absolute_path)) {
|
||||
DidFail(FileError::kInvalidModificationErr);
|
||||
DidFail(base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -423,16 +420,13 @@ FileWriterCallbacks::FileWriterCallbacks(
|
||||
file_writer_(file_writer),
|
||||
success_callback_(success_callback) {}
|
||||
|
||||
void FileWriterCallbacks::DidCreateFileWriter(
|
||||
std::unique_ptr<WebFileWriter> file_writer,
|
||||
long long length) {
|
||||
file_writer_->Initialize(std::move(file_writer), length);
|
||||
|
||||
void FileWriterCallbacks::DidCreateFileWriter(const KURL& path,
|
||||
long long length) {
|
||||
if (!success_callback_)
|
||||
return;
|
||||
|
||||
file_writer_->Initialize(path, length);
|
||||
InvokeOrScheduleCallback(&OnDidCreateFileWriterCallback::OnSuccess,
|
||||
success_callback_.Release(), file_writer_.Release());
|
||||
success_callback_.Release(), file_writer_);
|
||||
}
|
||||
|
||||
// SnapshotFileCallback -------------------------------------------------------
|
||||
|
@ -68,7 +68,7 @@ class ErrorCallbackBase : public GarbageCollectedFinalized<ErrorCallbackBase> {
|
||||
public:
|
||||
virtual ~ErrorCallbackBase() {}
|
||||
virtual void Trace(blink::Visitor* visitor) {}
|
||||
virtual void Invoke(FileError::ErrorCode) = 0;
|
||||
virtual void Invoke(base::File::Error error) = 0;
|
||||
};
|
||||
|
||||
class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
|
||||
@ -76,7 +76,7 @@ class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
|
||||
~FileSystemCallbacksBase() override;
|
||||
|
||||
// For ErrorCallback.
|
||||
void DidFail(int code) final;
|
||||
void DidFail(base::File::Error error) final;
|
||||
|
||||
// Other callback methods are implemented by each subclass.
|
||||
|
||||
@ -111,7 +111,7 @@ class ScriptErrorCallback final : public ErrorCallbackBase {
|
||||
~ScriptErrorCallback() override {}
|
||||
void Trace(blink::Visitor*) override;
|
||||
|
||||
void Invoke(FileError::ErrorCode) override;
|
||||
void Invoke(base::File::Error error) override;
|
||||
|
||||
private:
|
||||
explicit ScriptErrorCallback(V8ErrorCallback*);
|
||||
@ -122,7 +122,7 @@ class PromiseErrorCallback final : public ErrorCallbackBase {
|
||||
public:
|
||||
explicit PromiseErrorCallback(ScriptPromiseResolver*);
|
||||
void Trace(Visitor*) override;
|
||||
void Invoke(FileError::ErrorCode) override;
|
||||
void Invoke(base::File::Error error) override;
|
||||
|
||||
private:
|
||||
Member<ScriptPromiseResolver> resolver_;
|
||||
@ -371,8 +371,7 @@ class FileWriterCallbacks final : public FileSystemCallbacksBase {
|
||||
OnDidCreateFileWriterCallback*,
|
||||
ErrorCallbackBase*,
|
||||
ExecutionContext*);
|
||||
void DidCreateFileWriter(std::unique_ptr<WebFileWriter>,
|
||||
long long length) override;
|
||||
void DidCreateFileWriter(const KURL& path, long long length) override;
|
||||
|
||||
private:
|
||||
FileWriterCallbacks(FileWriterBase*,
|
||||
|
@ -59,7 +59,8 @@ ScriptPromise FileSystemDirectoryHandle::getSystemDirectory(
|
||||
FileSystemCallbacks::Create(
|
||||
new FileSystemCallbacks::OnDidOpenFileSystemPromiseImpl(resolver),
|
||||
new PromiseErrorCallback(resolver), context,
|
||||
mojom::blink::FileSystemType::kTemporary));
|
||||
mojom::blink::FileSystemType::kTemporary),
|
||||
LocalFileSystem::kAsynchronous);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
|
||||
#include "third_party/blink/renderer/core/dom/dom_exception.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/entry.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_base_handle.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_directory_iterator_entry.h"
|
||||
@ -39,7 +40,7 @@ class FileSystemDirectoryIterator::ErrorCallbackHelper final
|
||||
explicit ErrorCallbackHelper(FileSystemDirectoryIterator* reader)
|
||||
: reader_(reader) {}
|
||||
|
||||
void Invoke(FileError::ErrorCode error) override { reader_->OnError(error); }
|
||||
void Invoke(base::File::Error error) override { reader_->OnError(error); }
|
||||
|
||||
void Trace(Visitor* visitor) override {
|
||||
ErrorCallbackBase::Trace(visitor);
|
||||
@ -59,7 +60,7 @@ FileSystemDirectoryIterator::FileSystemDirectoryIterator(
|
||||
}
|
||||
|
||||
ScriptPromise FileSystemDirectoryIterator::next(ScriptState* script_state) {
|
||||
if (error_ != FileError::kOK) {
|
||||
if (error_ != base::File::FILE_OK) {
|
||||
return ScriptPromise::RejectWithDOMException(
|
||||
script_state, FileError::CreateDOMException(error_));
|
||||
}
|
||||
@ -98,7 +99,7 @@ void FileSystemDirectoryIterator::AddEntries(const EntryHeapVector& entries) {
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDirectoryIterator::OnError(FileError::ErrorCode error) {
|
||||
void FileSystemDirectoryIterator::OnError(base::File::Error error) {
|
||||
error_ = error;
|
||||
if (pending_next_) {
|
||||
pending_next_->Reject(FileError::CreateDOMException(error));
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_DIRECTORY_ITERATOR_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_DIRECTORY_ITERATOR_H_
|
||||
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
#include "base/files/file.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/directory_reader_base.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/dom_file_system.h"
|
||||
|
||||
@ -30,9 +30,9 @@ class FileSystemDirectoryIterator : public DirectoryReaderBase {
|
||||
class EntriesCallbackHelper;
|
||||
class ErrorCallbackHelper;
|
||||
void AddEntries(const EntryHeapVector& entries);
|
||||
void OnError(FileError::ErrorCode);
|
||||
void OnError(base::File::Error);
|
||||
|
||||
FileError::ErrorCode error_ = FileError::kOK;
|
||||
base::File::Error error_ = base::File::FILE_OK;
|
||||
HeapDeque<Member<Entry>> entries_;
|
||||
Member<ScriptPromiseResolver> pending_next_;
|
||||
};
|
||||
|
559
third_party/blink/renderer/modules/filesystem/file_system_dispatcher.cc
vendored
Normal file
559
third_party/blink/renderer/modules/filesystem/file_system_dispatcher.cc
vendored
Normal file
@ -0,0 +1,559 @@
|
||||
// Copyright 2018 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 "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "third_party/blink/public/platform/file_path_conversion.h"
|
||||
#include "third_party/blink/public/platform/interface_provider.h"
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/functional.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class FileSystemDispatcher::WriteListener
|
||||
: public mojom::blink::FileSystemOperationListener {
|
||||
public:
|
||||
WriteListener(const WriteCallback& success_callback,
|
||||
StatusCallback error_callback)
|
||||
: error_callback_(std::move(error_callback)),
|
||||
write_callback_(success_callback) {}
|
||||
|
||||
void ResultsRetrieved(
|
||||
Vector<filesystem::mojom::blink::DirectoryEntryPtr> entries,
|
||||
bool has_more) override {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void ErrorOccurred(base::File::Error error_code) override {
|
||||
std::move(error_callback_).Run(error_code);
|
||||
}
|
||||
|
||||
void DidWrite(int64_t byte_count, bool complete) override {
|
||||
write_callback_.Run(byte_count, complete);
|
||||
}
|
||||
|
||||
private:
|
||||
StatusCallback error_callback_;
|
||||
WriteCallback write_callback_;
|
||||
};
|
||||
|
||||
class FileSystemDispatcher::ReadDirectoryListener
|
||||
: public mojom::blink::FileSystemOperationListener {
|
||||
public:
|
||||
explicit ReadDirectoryListener(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks)
|
||||
: callbacks_(std::move(callbacks)) {}
|
||||
|
||||
void ResultsRetrieved(
|
||||
Vector<filesystem::mojom::blink::DirectoryEntryPtr> entries,
|
||||
bool has_more) override {
|
||||
for (const auto& entry : entries) {
|
||||
callbacks_->DidReadDirectoryEntry(
|
||||
FilePathToWebString(entry->name),
|
||||
entry->type == filesystem::mojom::blink::FsFileType::DIRECTORY);
|
||||
}
|
||||
callbacks_->DidReadDirectoryEntries(has_more);
|
||||
}
|
||||
|
||||
void ErrorOccurred(base::File::Error error_code) override {
|
||||
callbacks_->DidFail(error_code);
|
||||
}
|
||||
|
||||
void DidWrite(int64_t byte_count, bool complete) override { NOTREACHED(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks_;
|
||||
};
|
||||
|
||||
FileSystemDispatcher::FileSystemDispatcher() : next_operation_id_(1) {}
|
||||
|
||||
// static
|
||||
FileSystemDispatcher& FileSystemDispatcher::GetThreadSpecificInstance() {
|
||||
DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<FileSystemDispatcher>,
|
||||
file_system_dispatcher, ());
|
||||
return *file_system_dispatcher;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::OpenFileSystem(
|
||||
const KURL& origin_url,
|
||||
mojom::blink::FileSystemType type,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Open(
|
||||
origin_url, type,
|
||||
WTF::Bind(&FileSystemDispatcher::DidOpenFileSystem, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::OpenFileSystemSync(
|
||||
const KURL& origin_url,
|
||||
mojom::blink::FileSystemType type,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
String name;
|
||||
KURL root_url;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Open(origin_url, type, &name, &root_url, &error_code);
|
||||
DidOpenFileSystem(std::move(callbacks), std::move(name), root_url,
|
||||
error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ResolveURL(
|
||||
const KURL& filesystem_url,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().ResolveURL(
|
||||
filesystem_url, WTF::Bind(&FileSystemDispatcher::DidResolveURL,
|
||||
WTF::Unretained(this), std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ResolveURLSync(
|
||||
const KURL& filesystem_url,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
mojom::blink::FileSystemInfoPtr info;
|
||||
base::FilePath file_path;
|
||||
bool is_directory;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ResolveURL(filesystem_url, &info, &file_path,
|
||||
&is_directory, &error_code);
|
||||
DidResolveURL(std::move(callbacks), std::move(info), std::move(file_path),
|
||||
is_directory, error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Move(
|
||||
const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Move(
|
||||
src_path, dest_path,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::MoveSync(
|
||||
const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Move(src_path, dest_path, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Copy(
|
||||
const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Copy(
|
||||
src_path, dest_path,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CopySync(
|
||||
const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Copy(src_path, dest_path, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Remove(
|
||||
const KURL& path,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Remove(
|
||||
path, recursive,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::RemoveSync(
|
||||
const KURL& path,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Remove(path, recursive, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadMetadata(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().ReadMetadata(
|
||||
path, WTF::Bind(&FileSystemDispatcher::DidReadMetadata,
|
||||
WTF::Unretained(this), std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadMetadataSync(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Info file_info;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ReadMetadata(path, &file_info, &error_code);
|
||||
DidReadMetadata(std::move(callbacks), std::move(file_info), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFile(
|
||||
const KURL& path,
|
||||
bool exclusive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Create(
|
||||
path, exclusive, /*is_directory=*/false, /*is_recursive=*/false,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFileSync(
|
||||
const KURL& path,
|
||||
bool exclusive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Create(path, exclusive, /*is_directory=*/false,
|
||||
/*is_recursive=*/false, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateDirectory(
|
||||
const KURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Create(
|
||||
path, exclusive, /*is_directory=*/true, recursive,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateDirectorySync(
|
||||
const KURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Create(path, exclusive, /*is_directory=*/true,
|
||||
recursive, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Exists(
|
||||
const KURL& path,
|
||||
bool is_directory,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().Exists(
|
||||
path, is_directory,
|
||||
WTF::Bind(&FileSystemDispatcher::DidFinish, WTF::Unretained(this),
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ExistsSync(
|
||||
const KURL& path,
|
||||
bool is_directory,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().Exists(path, is_directory, &error_code);
|
||||
DidFinish(std::move(callbacks), error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadDirectory(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
mojom::blink::FileSystemOperationListenerPtr ptr;
|
||||
mojom::blink::FileSystemOperationListenerRequest request =
|
||||
mojo::MakeRequest(&ptr);
|
||||
op_listeners_.AddBinding(
|
||||
std::make_unique<ReadDirectoryListener>(std::move(callbacks)),
|
||||
std::move(request));
|
||||
GetFileSystemManager().ReadDirectory(path, std::move(ptr));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::ReadDirectorySync(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
Vector<filesystem::mojom::blink::DirectoryEntryPtr> entries;
|
||||
base::File::Error result = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ReadDirectorySync(path, &entries, &result);
|
||||
if (result == base::File::FILE_OK) {
|
||||
DidReadDirectory(std::move(callbacks), std::move(entries),
|
||||
std::move(result));
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::InitializeFileWriter(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().ReadMetadata(
|
||||
path, WTF::Bind(&FileSystemDispatcher::InitializeFileWriterCallback,
|
||||
WTF::Unretained(this), path, std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::InitializeFileWriterSync(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Info file_info;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().ReadMetadata(path, &file_info, &error_code);
|
||||
InitializeFileWriterCallback(path, std::move(callbacks), file_info,
|
||||
error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Truncate(const KURL& path,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
StatusCallback callback) {
|
||||
mojom::blink::FileSystemCancellableOperationPtr op_ptr;
|
||||
mojom::blink::FileSystemCancellableOperationRequest op_request =
|
||||
mojo::MakeRequest(&op_ptr);
|
||||
int operation_id = next_operation_id_++;
|
||||
op_ptr.set_connection_error_handler(
|
||||
WTF::Bind(&FileSystemDispatcher::RemoveOperationPtr,
|
||||
WTF::Unretained(this), operation_id));
|
||||
cancellable_operations_.insert(operation_id, std::move(op_ptr));
|
||||
GetFileSystemManager().Truncate(
|
||||
path, offset, std::move(op_request),
|
||||
WTF::Bind(&FileSystemDispatcher::DidTruncate, WTF::Unretained(this),
|
||||
operation_id, std::move(callback)));
|
||||
|
||||
if (request_id_out)
|
||||
*request_id_out = operation_id;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::TruncateSync(const KURL& path,
|
||||
int64_t offset,
|
||||
StatusCallback callback) {
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().TruncateSync(path, offset, &error_code);
|
||||
std::move(callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Write(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const WriteCallback& success_callback,
|
||||
StatusCallback error_callback) {
|
||||
mojom::blink::FileSystemCancellableOperationPtr op_ptr;
|
||||
mojom::blink::FileSystemCancellableOperationRequest op_request =
|
||||
mojo::MakeRequest(&op_ptr);
|
||||
int operation_id = next_operation_id_++;
|
||||
op_ptr.set_connection_error_handler(
|
||||
WTF::Bind(&FileSystemDispatcher::RemoveOperationPtr,
|
||||
WTF::Unretained(this), operation_id));
|
||||
cancellable_operations_.insert(operation_id, std::move(op_ptr));
|
||||
|
||||
mojom::blink::FileSystemOperationListenerPtr listener_ptr;
|
||||
mojom::blink::FileSystemOperationListenerRequest request =
|
||||
mojo::MakeRequest(&listener_ptr);
|
||||
op_listeners_.AddBinding(std::make_unique<WriteListener>(
|
||||
success_callback, std::move(error_callback)),
|
||||
std::move(request));
|
||||
|
||||
GetFileSystemManager().Write(path, blob_id, offset, std::move(op_request),
|
||||
std::move(listener_ptr));
|
||||
|
||||
if (request_id_out)
|
||||
*request_id_out = operation_id;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::WriteSync(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset,
|
||||
const WriteCallback& success_callback,
|
||||
StatusCallback error_callback) {
|
||||
int64_t byte_count;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
GetFileSystemManager().WriteSync(path, blob_id, offset, &byte_count,
|
||||
&error_code);
|
||||
if (error_code == base::File::FILE_OK)
|
||||
std::move(success_callback).Run(byte_count, /*complete=*/true);
|
||||
else
|
||||
std::move(error_callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::Cancel(int request_id_to_cancel,
|
||||
StatusCallback callback) {
|
||||
if (cancellable_operations_.find(request_id_to_cancel) ==
|
||||
cancellable_operations_.end()) {
|
||||
std::move(callback).Run(base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
cancellable_operations_.find(request_id_to_cancel)
|
||||
->value->Cancel(WTF::Bind(&FileSystemDispatcher::DidCancel,
|
||||
WTF::Unretained(this), std::move(callback),
|
||||
request_id_to_cancel));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateSnapshotFile(
|
||||
const KURL& file_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
GetFileSystemManager().CreateSnapshotFile(
|
||||
file_path, WTF::Bind(&FileSystemDispatcher::DidCreateSnapshotFile,
|
||||
WTF::Unretained(this), std::move(callbacks)));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateSnapshotFileSync(
|
||||
const KURL& file_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
base::File::Info file_info;
|
||||
base::FilePath platform_path;
|
||||
base::File::Error error_code = base::File::FILE_ERROR_FAILED;
|
||||
mojom::blink::ReceivedSnapshotListenerPtr listener;
|
||||
GetFileSystemManager().CreateSnapshotFile(
|
||||
file_path, &file_info, &platform_path, &error_code, &listener);
|
||||
DidCreateSnapshotFile(std::move(callbacks), std::move(file_info),
|
||||
std::move(platform_path), error_code,
|
||||
std::move(listener));
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::CreateFileWriter(
|
||||
const KURL& file_path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks> callbacks) {
|
||||
GetFileSystemManager().CreateWriter(
|
||||
file_path,
|
||||
WTF::Bind(
|
||||
[](std::unique_ptr<CreateFileWriterCallbacks> callbacks,
|
||||
base::File::Error result, mojom::blink::FileWriterPtr writer) {
|
||||
if (result != base::File::FILE_OK) {
|
||||
callbacks->OnError(result);
|
||||
} else {
|
||||
callbacks->OnSuccess(std::move(writer));
|
||||
}
|
||||
},
|
||||
std::move(callbacks)));
|
||||
}
|
||||
|
||||
mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
|
||||
if (!file_system_manager_ptr_) {
|
||||
Platform::Current()->GetInterfaceProvider()->GetInterface(
|
||||
mojo::MakeRequest(&file_system_manager_ptr_));
|
||||
}
|
||||
return *file_system_manager_ptr_;
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidOpenFileSystem(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const String& name,
|
||||
const KURL& root,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
callbacks->DidOpenFileSystem(name, root);
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidResolveURL(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
mojom::blink::FileSystemInfoPtr info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
DCHECK(info->root_url.IsValid());
|
||||
callbacks->DidResolveURL(info->name, info->root_url, info->mount_type,
|
||||
FilePathToWebString(file_path), is_directory);
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidFinish(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK)
|
||||
callbacks->DidSucceed();
|
||||
else
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidReadMetadata(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
callbacks->DidReadMetadata(FileMetadata::From(file_info));
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidReadDirectory(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
Vector<filesystem::mojom::blink::DirectoryEntryPtr> entries,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
for (const auto& entry : entries) {
|
||||
callbacks->DidReadDirectoryEntry(
|
||||
FilePathToWebString(entry->name),
|
||||
entry->type == filesystem::mojom::blink::FsFileType::DIRECTORY);
|
||||
}
|
||||
callbacks->DidReadDirectoryEntries(false);
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::InitializeFileWriterCallback(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::Error::FILE_OK) {
|
||||
if (file_info.is_directory || file_info.size < 0) {
|
||||
callbacks->DidFail(base::File::FILE_ERROR_FAILED);
|
||||
return;
|
||||
}
|
||||
callbacks->DidCreateFileWriter(path, file_info.size);
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidTruncate(int operation_id,
|
||||
StatusCallback callback,
|
||||
base::File::Error error_code) {
|
||||
if (error_code != base::File::FILE_ERROR_ABORT)
|
||||
RemoveOperationPtr(operation_id);
|
||||
std::move(callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidCancel(StatusCallback callback,
|
||||
int cancelled_operation_id,
|
||||
base::File::Error error_code) {
|
||||
if (error_code == base::File::FILE_OK)
|
||||
RemoveOperationPtr(cancelled_operation_id);
|
||||
std::move(callback).Run(error_code);
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::DidCreateSnapshotFile(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::File::Error error_code,
|
||||
mojom::blink::ReceivedSnapshotListenerPtr listener) {
|
||||
if (error_code == base::File::FILE_OK) {
|
||||
FileMetadata file_metadata = FileMetadata::From(file_info);
|
||||
file_metadata.platform_path = FilePathToWebString(platform_path);
|
||||
|
||||
std::unique_ptr<BlobData> blob_data = BlobData::Create();
|
||||
blob_data->AppendFile(file_metadata.platform_path, 0, file_metadata.length,
|
||||
InvalidFileTime());
|
||||
scoped_refptr<BlobDataHandle> snapshot_blob =
|
||||
BlobDataHandle::Create(std::move(blob_data), file_metadata.length);
|
||||
|
||||
callbacks->DidCreateSnapshotFile(file_metadata, snapshot_blob);
|
||||
|
||||
if (listener)
|
||||
listener->DidReceiveSnapshotFile();
|
||||
} else {
|
||||
callbacks->DidFail(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystemDispatcher::RemoveOperationPtr(int operation_id) {
|
||||
DCHECK(cancellable_operations_.find(operation_id) !=
|
||||
cancellable_operations_.end());
|
||||
cancellable_operations_.erase(operation_id);
|
||||
}
|
||||
|
||||
} // namespace blink
|
194
third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h
vendored
Normal file
194
third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_DISPATCHER_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_DISPATCHER_H_
|
||||
|
||||
#include "mojo/public/cpp/bindings/strong_binding_set.h"
|
||||
#include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink.h"
|
||||
#include "third_party/blink/public/platform/web_callbacks.h"
|
||||
#include "third_party/blink/renderer/platform/async_file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/platform/heap/handle.h"
|
||||
|
||||
namespace WTF {
|
||||
class String;
|
||||
}
|
||||
|
||||
namespace blink {
|
||||
|
||||
class KURL;
|
||||
|
||||
// Sends messages via mojo to the blink::mojom::FileSystemManager service
|
||||
// running in the browser process. It is currently created and stored in a
|
||||
// thread local variable. A thread specific instance can be obtained using
|
||||
// GetThreadSpecificInstance().
|
||||
class FileSystemDispatcher {
|
||||
public:
|
||||
using StatusCallback = base::OnceCallback<void(base::File::Error error)>;
|
||||
using WriteCallback =
|
||||
base::RepeatingCallback<void(int64_t bytes, bool complete)>;
|
||||
|
||||
static FileSystemDispatcher& GetThreadSpecificInstance();
|
||||
|
||||
void OpenFileSystem(const KURL& url,
|
||||
mojom::blink::FileSystemType type,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void OpenFileSystemSync(const KURL& url,
|
||||
mojom::blink::FileSystemType type,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void ResolveURL(const KURL& filesystem_url,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void ResolveURLSync(const KURL& filesystem_url,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void Move(const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void MoveSync(const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void Copy(const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void CopySync(const KURL& src_path,
|
||||
const KURL& dest_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void Remove(const KURL& path,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void RemoveSync(const KURL& path,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void ReadMetadata(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void ReadMetadataSync(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void CreateFile(const KURL& path,
|
||||
bool exclusive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void CreateFileSync(const KURL& path,
|
||||
bool exclusive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void CreateDirectory(const KURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void CreateDirectorySync(const KURL& path,
|
||||
bool exclusive,
|
||||
bool recursive,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void Exists(const KURL& path,
|
||||
bool for_directory,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void ExistsSync(const KURL& path,
|
||||
bool for_directory,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void ReadDirectory(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void ReadDirectorySync(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
void InitializeFileWriter(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>);
|
||||
void InitializeFileWriterSync(const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>);
|
||||
|
||||
void Truncate(const KURL& path,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
StatusCallback callback);
|
||||
void TruncateSync(const KURL& path, int64_t offset, StatusCallback callback);
|
||||
|
||||
void Write(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset,
|
||||
int* request_id_out,
|
||||
const WriteCallback& success_callback,
|
||||
StatusCallback error_callback);
|
||||
void WriteSync(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset,
|
||||
const WriteCallback& success_callback,
|
||||
StatusCallback error_callback);
|
||||
|
||||
void Cancel(int request_id_to_cancel, StatusCallback callback);
|
||||
|
||||
void CreateSnapshotFile(const KURL& file_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
void CreateSnapshotFileSync(
|
||||
const KURL& file_path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks);
|
||||
|
||||
using CreateFileWriterCallbacks =
|
||||
WebCallbacks<mojom::blink::FileWriterPtr, base::File::Error>;
|
||||
void CreateFileWriter(const KURL& file_path,
|
||||
std::unique_ptr<CreateFileWriterCallbacks>);
|
||||
|
||||
private:
|
||||
class WriteListener;
|
||||
class ReadDirectoryListener;
|
||||
friend class WTF::ThreadSpecific<FileSystemDispatcher>;
|
||||
|
||||
FileSystemDispatcher();
|
||||
|
||||
mojom::blink::FileSystemManager& GetFileSystemManager();
|
||||
|
||||
void DidOpenFileSystem(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const String& name,
|
||||
const KURL& root,
|
||||
base::File::Error error_code);
|
||||
void DidResolveURL(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
mojom::blink::FileSystemInfoPtr info,
|
||||
const base::FilePath& file_path,
|
||||
bool is_directory,
|
||||
base::File::Error error_code);
|
||||
void DidFinish(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
base::File::Error error_code);
|
||||
void DidReadMetadata(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error);
|
||||
void DidReadDirectory(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
Vector<filesystem::mojom::blink::DirectoryEntryPtr> entries,
|
||||
base::File::Error error_code);
|
||||
void InitializeFileWriterCallback(
|
||||
const KURL& path,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
base::File::Error error);
|
||||
void DidTruncate(int operation_id,
|
||||
StatusCallback callback,
|
||||
base::File::Error error_code);
|
||||
void DidCancel(StatusCallback callback,
|
||||
int cancelled_operation_id,
|
||||
base::File::Error error_code);
|
||||
void DidCreateSnapshotFile(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
const base::File::Info& file_info,
|
||||
const base::FilePath& platform_path,
|
||||
base::File::Error error_code,
|
||||
mojom::blink::ReceivedSnapshotListenerPtr listener);
|
||||
|
||||
void RemoveOperationPtr(int operation_id);
|
||||
|
||||
mojom::blink::FileSystemManagerPtr file_system_manager_ptr_;
|
||||
using OperationsMap =
|
||||
HashMap<int, mojom::blink::FileSystemCancellableOperationPtr>;
|
||||
OperationsMap cancellable_operations_;
|
||||
int next_operation_id_;
|
||||
mojo::StrongBindingSet<mojom::blink::FileSystemOperationListener>
|
||||
op_listeners_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_DISPATCHER_H_
|
@ -5,12 +5,13 @@
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_file_handle.h"
|
||||
|
||||
#include "third_party/blink/public/mojom/filesystem/file_writer.mojom-blink.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_callbacks.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
|
||||
#include "third_party/blink/renderer/core/dom/dom_exception.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/dom_file_system.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_writer.h"
|
||||
|
||||
namespace blink {
|
||||
@ -18,15 +19,13 @@ namespace blink {
|
||||
namespace {
|
||||
|
||||
class CreateWriterCallbacks
|
||||
: public WebCallbacks<mojo::ScopedMessagePipeHandle, base::File::Error> {
|
||||
: public WebCallbacks<mojom::blink::FileWriterPtr, base::File::Error> {
|
||||
public:
|
||||
explicit CreateWriterCallbacks(ScriptPromiseResolver* resolver)
|
||||
: resolver_(resolver) {}
|
||||
|
||||
void OnSuccess(mojo::ScopedMessagePipeHandle handle) override {
|
||||
mojom::blink::FileWriterPtr mojo_writer(mojom::blink::FileWriterPtrInfo(
|
||||
std::move(handle), mojom::blink::FileWriter::Version_));
|
||||
resolver_->Resolve(new FileSystemWriter(std::move(mojo_writer)));
|
||||
void OnSuccess(mojom::blink::FileWriterPtr writer) override {
|
||||
resolver_->Resolve(new FileSystemWriter(std::move(writer)));
|
||||
}
|
||||
|
||||
void OnError(base::File::Error error) override {
|
||||
@ -59,29 +58,19 @@ FileSystemFileHandle::FileSystemFileHandle(DOMFileSystemBase* file_system,
|
||||
: FileSystemBaseHandle(file_system, full_path) {}
|
||||
|
||||
ScriptPromise FileSystemFileHandle::createWriter(ScriptState* script_state) {
|
||||
if (!filesystem()->FileSystem()) {
|
||||
return ScriptPromise::RejectWithDOMException(
|
||||
script_state, FileError::CreateDOMException(FileError::kAbortErr));
|
||||
}
|
||||
|
||||
auto* resolver = ScriptPromiseResolver::Create(script_state);
|
||||
ScriptPromise result = resolver->Promise();
|
||||
filesystem()->FileSystem()->CreateFileWriter(
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().CreateFileWriter(
|
||||
filesystem()->CreateFileSystemURL(this),
|
||||
std::make_unique<CreateWriterCallbacks>(resolver));
|
||||
return result;
|
||||
}
|
||||
|
||||
ScriptPromise FileSystemFileHandle::getFile(ScriptState* script_state) {
|
||||
if (!filesystem()->FileSystem()) {
|
||||
return ScriptPromise::RejectWithDOMException(
|
||||
script_state, FileError::CreateDOMException(FileError::kAbortErr));
|
||||
}
|
||||
|
||||
auto* resolver = ScriptPromiseResolver::Create(script_state);
|
||||
ScriptPromise result = resolver->Promise();
|
||||
KURL file_system_url = filesystem()->CreateFileSystemURL(this);
|
||||
filesystem()->FileSystem()->CreateSnapshotFileAndReadMetadata(
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().CreateSnapshotFile(
|
||||
file_system_url,
|
||||
SnapshotFileCallback::Create(filesystem(), name(), file_system_url,
|
||||
new OnDidCreateSnapshotFilePromise(resolver),
|
||||
|
@ -30,11 +30,11 @@
|
||||
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer.h"
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/renderer/core/events/progress_event.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/blob.h"
|
||||
#include "third_party/blink/renderer/core/probe/core_probes.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/time.h"
|
||||
|
||||
@ -57,11 +57,11 @@ FileWriter::FileWriter(ExecutionContext* context)
|
||||
truncate_length_(-1),
|
||||
num_aborts_(0),
|
||||
recursion_depth_(0),
|
||||
last_progress_notification_time_ms_(0) {}
|
||||
last_progress_notification_time_ms_(0),
|
||||
request_id_(0) {}
|
||||
|
||||
FileWriter::~FileWriter() {
|
||||
DCHECK(!recursion_depth_);
|
||||
DCHECK(!Writer());
|
||||
}
|
||||
|
||||
const AtomicString& FileWriter::InterfaceName() const {
|
||||
@ -81,7 +81,6 @@ void FileWriter::write(Blob* data, ExceptionState& exception_state) {
|
||||
if (!GetExecutionContext())
|
||||
return;
|
||||
DCHECK(data);
|
||||
DCHECK(Writer());
|
||||
DCHECK_EQ(truncate_length_, -1);
|
||||
if (ready_state_ == kWriting) {
|
||||
SetError(FileError::kInvalidStateErr, exception_state);
|
||||
@ -111,7 +110,6 @@ void FileWriter::write(Blob* data, ExceptionState& exception_state) {
|
||||
void FileWriter::seek(long long position, ExceptionState& exception_state) {
|
||||
if (!GetExecutionContext())
|
||||
return;
|
||||
DCHECK(Writer());
|
||||
if (ready_state_ == kWriting) {
|
||||
SetError(FileError::kInvalidStateErr, exception_state);
|
||||
return;
|
||||
@ -125,7 +123,6 @@ void FileWriter::seek(long long position, ExceptionState& exception_state) {
|
||||
void FileWriter::truncate(long long position, ExceptionState& exception_state) {
|
||||
if (!GetExecutionContext())
|
||||
return;
|
||||
DCHECK(Writer());
|
||||
DCHECK_EQ(truncate_length_, -1);
|
||||
if (ready_state_ == kWriting || position < 0) {
|
||||
SetError(FileError::kInvalidStateErr, exception_state);
|
||||
@ -154,16 +151,15 @@ void FileWriter::truncate(long long position, ExceptionState& exception_state) {
|
||||
void FileWriter::abort(ExceptionState& exception_state) {
|
||||
if (!GetExecutionContext())
|
||||
return;
|
||||
DCHECK(Writer());
|
||||
if (ready_state_ != kWriting)
|
||||
return;
|
||||
++num_aborts_;
|
||||
|
||||
DoOperation(kOperationAbort);
|
||||
SignalCompletion(FileError::kAbortErr);
|
||||
SignalCompletion(base::File::FILE_ERROR_ABORT);
|
||||
}
|
||||
|
||||
void FileWriter::DidWrite(long long bytes, bool complete) {
|
||||
void FileWriter::DidWriteImpl(int64_t bytes, bool complete) {
|
||||
if (operation_in_progress_ == kOperationAbort) {
|
||||
CompleteAbort();
|
||||
return;
|
||||
@ -196,11 +192,11 @@ void FileWriter::DidWrite(long long bytes, bool complete) {
|
||||
|
||||
if (complete) {
|
||||
if (num_aborts == num_aborts_)
|
||||
SignalCompletion(FileError::kOK);
|
||||
SignalCompletion(base::File::FILE_OK);
|
||||
}
|
||||
}
|
||||
|
||||
void FileWriter::DidTruncate() {
|
||||
void FileWriter::DidTruncateImpl() {
|
||||
if (operation_in_progress_ == kOperationAbort) {
|
||||
CompleteAbort();
|
||||
return;
|
||||
@ -211,12 +207,12 @@ void FileWriter::DidTruncate() {
|
||||
if (position() > length())
|
||||
SetPosition(length());
|
||||
operation_in_progress_ = kOperationNone;
|
||||
SignalCompletion(FileError::kOK);
|
||||
SignalCompletion(base::File::FILE_OK);
|
||||
}
|
||||
|
||||
void FileWriter::DidFail(WebFileError code) {
|
||||
void FileWriter::DidFailImpl(base::File::Error error) {
|
||||
DCHECK_NE(kOperationNone, operation_in_progress_);
|
||||
DCHECK_NE(FileError::kOK, static_cast<FileError::ErrorCode>(code));
|
||||
DCHECK_NE(base::File::FILE_OK, error);
|
||||
if (operation_in_progress_ == kOperationAbort) {
|
||||
CompleteAbort();
|
||||
return;
|
||||
@ -225,7 +221,27 @@ void FileWriter::DidFail(WebFileError code) {
|
||||
DCHECK_EQ(kWriting, ready_state_);
|
||||
blob_being_written_.Clear();
|
||||
operation_in_progress_ = kOperationNone;
|
||||
SignalCompletion(static_cast<FileError::ErrorCode>(code));
|
||||
SignalCompletion(error);
|
||||
}
|
||||
|
||||
void FileWriter::DoTruncate(const KURL& path, int64_t offset) {
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().Truncate(
|
||||
path, offset, &request_id_,
|
||||
WTF::Bind(&FileWriter::DidFinish, WrapWeakPersistent(this)));
|
||||
}
|
||||
|
||||
void FileWriter::DoWrite(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset) {
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().Write(
|
||||
path, blob_id, offset, &request_id_,
|
||||
WTF::BindRepeating(&FileWriter::DidWrite, WrapWeakPersistent(this)),
|
||||
WTF::Bind(&FileWriter::DidFinish, WrapWeakPersistent(this)));
|
||||
}
|
||||
|
||||
void FileWriter::DoCancel() {
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().Cancel(
|
||||
request_id_, WTF::Bind(&FileWriter::DidFinish, WrapWeakPersistent(this)));
|
||||
}
|
||||
|
||||
void FileWriter::CompleteAbort() {
|
||||
@ -244,13 +260,13 @@ void FileWriter::DoOperation(Operation operation) {
|
||||
DCHECK_EQ(-1, truncate_length_);
|
||||
DCHECK(blob_being_written_.Get());
|
||||
DCHECK_EQ(kWriting, ready_state_);
|
||||
Writer()->Write(position(), blob_being_written_->Uuid());
|
||||
Write(position(), blob_being_written_->Uuid());
|
||||
break;
|
||||
case kOperationTruncate:
|
||||
DCHECK_EQ(kOperationNone, operation_in_progress_);
|
||||
DCHECK_GE(truncate_length_, 0);
|
||||
DCHECK_EQ(kWriting, ready_state_);
|
||||
Writer()->Truncate(truncate_length_);
|
||||
Truncate(truncate_length_);
|
||||
break;
|
||||
case kOperationNone:
|
||||
DCHECK_EQ(kOperationNone, operation_in_progress_);
|
||||
@ -261,7 +277,7 @@ void FileWriter::DoOperation(Operation operation) {
|
||||
case kOperationAbort:
|
||||
if (operation_in_progress_ == kOperationWrite ||
|
||||
operation_in_progress_ == kOperationTruncate)
|
||||
Writer()->Cancel();
|
||||
Cancel();
|
||||
else if (operation_in_progress_ != kOperationAbort)
|
||||
operation = kOperationNone;
|
||||
queued_operation_ = kOperationNone;
|
||||
@ -273,12 +289,12 @@ void FileWriter::DoOperation(Operation operation) {
|
||||
operation_in_progress_ = operation;
|
||||
}
|
||||
|
||||
void FileWriter::SignalCompletion(FileError::ErrorCode code) {
|
||||
void FileWriter::SignalCompletion(base::File::Error error) {
|
||||
ready_state_ = kDone;
|
||||
truncate_length_ = -1;
|
||||
if (FileError::kOK != code) {
|
||||
error_ = FileError::CreateDOMException(code);
|
||||
if (FileError::kAbortErr == code)
|
||||
if (error != base::File::FILE_OK) {
|
||||
error_ = FileError::CreateDOMException(error);
|
||||
if (base::File::FILE_ERROR_ABORT == error)
|
||||
FireEvent(EventTypeNames::abort);
|
||||
else
|
||||
FireEvent(EventTypeNames::error);
|
||||
@ -308,11 +324,10 @@ void FileWriter::SetError(FileError::ErrorCode error_code,
|
||||
void FileWriter::Dispose() {
|
||||
// Make sure we've actually got something to stop, and haven't already called
|
||||
// abort().
|
||||
if (Writer() && ready_state_ == kWriting) {
|
||||
if (ready_state_ == kWriting) {
|
||||
DoOperation(kOperationAbort);
|
||||
ready_state_ = kDone;
|
||||
}
|
||||
ResetWriter();
|
||||
}
|
||||
|
||||
void FileWriter::Trace(blink::Visitor* visitor) {
|
||||
|
@ -31,7 +31,6 @@
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_WRITER_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_WRITER_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_writer_client.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
|
||||
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
@ -49,8 +48,7 @@ class ExecutionContext;
|
||||
class FileWriter final : public EventTargetWithInlineData,
|
||||
public FileWriterBase,
|
||||
public ActiveScriptWrappable<FileWriter>,
|
||||
public ContextLifecycleObserver,
|
||||
public WebFileWriterClient {
|
||||
public ContextLifecycleObserver {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
USING_GARBAGE_COLLECTED_MIXIN(FileWriter);
|
||||
USING_PRE_FINALIZER(FileWriter, Dispose);
|
||||
@ -68,10 +66,15 @@ class FileWriter final : public EventTargetWithInlineData,
|
||||
ReadyState getReadyState() const { return ready_state_; }
|
||||
DOMException* error() const { return error_.Get(); }
|
||||
|
||||
// WebFileWriterClient
|
||||
void DidWrite(long long bytes, bool complete) override;
|
||||
void DidTruncate() override;
|
||||
void DidFail(WebFileError) override;
|
||||
// FileWriterBase
|
||||
void DidWriteImpl(int64_t bytes, bool complete) override;
|
||||
void DidTruncateImpl() override;
|
||||
void DidFailImpl(base::File::Error error) override;
|
||||
void DoTruncate(const KURL& path, int64_t offset) override;
|
||||
void DoWrite(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset) override;
|
||||
void DoCancel() override;
|
||||
|
||||
// ContextLifecycleObserver
|
||||
void ContextDestroyed(ExecutionContext*) override;
|
||||
@ -108,7 +111,7 @@ class FileWriter final : public EventTargetWithInlineData,
|
||||
|
||||
void DoOperation(Operation);
|
||||
|
||||
void SignalCompletion(FileError::ErrorCode);
|
||||
void SignalCompletion(base::File::Error error_code);
|
||||
|
||||
void FireEvent(const AtomicString& type);
|
||||
|
||||
@ -127,6 +130,7 @@ class FileWriter final : public EventTargetWithInlineData,
|
||||
long long recursion_depth_;
|
||||
double last_progress_notification_time_ms_;
|
||||
Member<Blob> blob_being_written_;
|
||||
int request_id_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer_base.h"
|
||||
|
||||
#include <memory>
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/renderer/core/events/progress_event.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/blob.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
@ -40,15 +39,16 @@ namespace blink {
|
||||
|
||||
FileWriterBase::~FileWriterBase() = default;
|
||||
|
||||
void FileWriterBase::Initialize(std::unique_ptr<WebFileWriter> writer,
|
||||
long long length) {
|
||||
DCHECK(!writer_);
|
||||
void FileWriterBase::Initialize(const KURL& path, long long length) {
|
||||
DCHECK_GE(length, 0);
|
||||
writer_ = std::move(writer);
|
||||
length_ = length;
|
||||
path_ = path;
|
||||
}
|
||||
|
||||
FileWriterBase::FileWriterBase() : position_(0) {}
|
||||
FileWriterBase::FileWriterBase()
|
||||
: position_(0),
|
||||
operation_(kOperationNone),
|
||||
cancel_state_(kCancelNotInProgress) {}
|
||||
|
||||
void FileWriterBase::SeekInternal(long long position) {
|
||||
if (position > length_)
|
||||
@ -60,14 +60,129 @@ void FileWriterBase::SeekInternal(long long position) {
|
||||
position_ = position;
|
||||
}
|
||||
|
||||
void FileWriterBase::ResetWriter() {
|
||||
writer_ = nullptr;
|
||||
void FileWriterBase::Truncate(long long length) {
|
||||
DCHECK_EQ(kOperationNone, operation_);
|
||||
DCHECK_EQ(kCancelNotInProgress, cancel_state_);
|
||||
operation_ = kOperationTruncate;
|
||||
DoTruncate(path_, length);
|
||||
}
|
||||
|
||||
void FileWriterBase::Dispose() {
|
||||
// Need to explicitly destroy m_writer in pre-finalizer, because otherwise it
|
||||
// may attempt to call methods on the FileWriter before we are finalized.
|
||||
ResetWriter();
|
||||
void FileWriterBase::Write(long long position, const String& id) {
|
||||
DCHECK_EQ(kOperationNone, operation_);
|
||||
DCHECK_EQ(kCancelNotInProgress, cancel_state_);
|
||||
operation_ = kOperationWrite;
|
||||
DoWrite(path_, id, position);
|
||||
}
|
||||
|
||||
// When we cancel a write/truncate, we always get back the result of the write
|
||||
// before the result of the cancel, no matter what happens.
|
||||
// So we'll get back either
|
||||
// success [of the write/truncate, in a DidWrite(XXX, true)/DidSucceed() call]
|
||||
// followed by failure [of the cancel]; or
|
||||
// failure [of the write, either from cancel or other reasons] followed by
|
||||
// the result of the cancel.
|
||||
// In the write case, there could also be queued up non-terminal DidWrite calls
|
||||
// before any of that comes back, but there will always be a terminal write
|
||||
// response [success or failure] after them, followed by the cancel result, so
|
||||
// we can ignore non-terminal write responses, take the terminal write success
|
||||
// or the first failure as the last write response, then know that the next
|
||||
// thing to come back is the cancel response. We only notify the
|
||||
// AsyncFileWriterClient when it's all over.
|
||||
void FileWriterBase::Cancel() {
|
||||
// Check for the cancel passing the previous operation's return in-flight.
|
||||
if (operation_ != kOperationWrite && operation_ != kOperationTruncate)
|
||||
return;
|
||||
if (cancel_state_ != kCancelNotInProgress)
|
||||
return;
|
||||
cancel_state_ = kCancelSent;
|
||||
DoCancel();
|
||||
}
|
||||
|
||||
void FileWriterBase::DidFinish(base::File::Error error_code) {
|
||||
if (error_code == base::File::FILE_OK)
|
||||
DidSucceed();
|
||||
else
|
||||
DidFail(error_code);
|
||||
}
|
||||
|
||||
void FileWriterBase::DidWrite(int64_t bytes, bool complete) {
|
||||
DCHECK_EQ(kOperationWrite, operation_);
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
if (complete)
|
||||
operation_ = kOperationNone;
|
||||
DidWriteImpl(bytes, complete);
|
||||
break;
|
||||
case kCancelSent:
|
||||
// This is the success call of the write, which we'll eat, even though
|
||||
// it succeeded before the cancel got there. We accepted the cancel call,
|
||||
// so the write will eventually return an error.
|
||||
if (complete)
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void FileWriterBase::DidSucceed() {
|
||||
// Write never gets a DidSucceed call, so this is either a cancel or truncate
|
||||
// response.
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
// A truncate succeeded, with no complications.
|
||||
DCHECK_EQ(kOperationTruncate, operation_);
|
||||
operation_ = kOperationNone;
|
||||
DidTruncateImpl();
|
||||
break;
|
||||
case kCancelSent:
|
||||
DCHECK_EQ(kOperationTruncate, operation_);
|
||||
// This is the success call of the truncate, which we'll eat, even though
|
||||
// it succeeded before the cancel got there. We accepted the cancel call,
|
||||
// so the truncate will eventually return an error.
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
// This is the success of the cancel operation.
|
||||
FinishCancel();
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void FileWriterBase::DidFail(base::File::Error error_code) {
|
||||
DCHECK_NE(kOperationNone, operation_);
|
||||
switch (cancel_state_) {
|
||||
case kCancelNotInProgress:
|
||||
// A write or truncate failed.
|
||||
operation_ = kOperationNone;
|
||||
DidFailImpl(error_code);
|
||||
break;
|
||||
case kCancelSent:
|
||||
// This is the failure of a write or truncate; the next message should be
|
||||
// the result of the cancel. We don't assume that it'll be a success, as
|
||||
// the write/truncate could have failed for other reasons.
|
||||
cancel_state_ = kCancelReceivedWriteResponse;
|
||||
break;
|
||||
case kCancelReceivedWriteResponse:
|
||||
// The cancel reported failure, meaning that the write or truncate
|
||||
// finished before the cancel got there. But we suppressed the
|
||||
// write/truncate's response, and will now report that it was cancelled.
|
||||
FinishCancel();
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void FileWriterBase::FinishCancel() {
|
||||
DCHECK_EQ(kCancelReceivedWriteResponse, cancel_state_);
|
||||
DCHECK_NE(kOperationNone, operation_);
|
||||
cancel_state_ = kCancelNotInProgress;
|
||||
operation_ = kOperationNone;
|
||||
DidFailImpl(base::File::FILE_ERROR_ABORT);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
@ -32,43 +32,72 @@
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_WRITER_BASE_H_
|
||||
|
||||
#include <memory>
|
||||
#include "base/files/file.h"
|
||||
#include "third_party/blink/renderer/modules/modules_export.h"
|
||||
#include "third_party/blink/renderer/platform/heap/handle.h"
|
||||
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class WebFileWriter;
|
||||
|
||||
class FileWriterBase : public GarbageCollectedMixin {
|
||||
USING_PRE_FINALIZER(FileWriterBase, Dispose);
|
||||
|
||||
class MODULES_EXPORT FileWriterBase : public GarbageCollectedMixin {
|
||||
public:
|
||||
virtual ~FileWriterBase();
|
||||
void Initialize(std::unique_ptr<WebFileWriter>, long long length);
|
||||
void Initialize(const KURL& path, long long length);
|
||||
|
||||
long long position() const { return position_; }
|
||||
long long length() const { return length_; }
|
||||
|
||||
void Trace(blink::Visitor* visitor) override {}
|
||||
|
||||
virtual void Truncate(long long length);
|
||||
virtual void Write(long long position, const String& id);
|
||||
virtual void Cancel();
|
||||
|
||||
protected:
|
||||
FileWriterBase();
|
||||
|
||||
WebFileWriter* Writer() { return writer_.get(); }
|
||||
|
||||
void SetPosition(long long position) { position_ = position; }
|
||||
|
||||
void SetLength(long long length) { length_ = length; }
|
||||
|
||||
void SeekInternal(long long position);
|
||||
|
||||
void ResetWriter();
|
||||
// This calls DidSucceed() or DidFail() based on the value of |error_code|.
|
||||
void DidFinish(base::File::Error error_code);
|
||||
void DidSucceed();
|
||||
void DidWrite(int64_t bytes, bool complete);
|
||||
void DidFail(base::File::Error error_code);
|
||||
|
||||
// Derived classes must provide these methods to asynchronously perform
|
||||
// the requested operation, and they must call the appropriate DidSomething
|
||||
// method upon completion and as progress is made in the Write case.
|
||||
virtual void DoTruncate(const KURL& path, int64_t offset) = 0;
|
||||
virtual void DoWrite(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset) = 0;
|
||||
virtual void DoCancel() = 0;
|
||||
|
||||
// These are conditionally called by the Did* methods.
|
||||
virtual void DidWriteImpl(int64_t bytes, bool complete) = 0;
|
||||
virtual void DidFailImpl(base::File::Error error_code) = 0;
|
||||
virtual void DidTruncateImpl() = 0;
|
||||
|
||||
private:
|
||||
void Dispose();
|
||||
enum OperationType { kOperationNone, kOperationWrite, kOperationTruncate };
|
||||
|
||||
enum CancelState {
|
||||
kCancelNotInProgress,
|
||||
kCancelSent,
|
||||
kCancelReceivedWriteResponse,
|
||||
};
|
||||
|
||||
void FinishCancel();
|
||||
|
||||
std::unique_ptr<WebFileWriter> writer_;
|
||||
long long position_;
|
||||
long long length_;
|
||||
KURL path_;
|
||||
OperationType operation_;
|
||||
CancelState cancel_state_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -30,20 +30,19 @@
|
||||
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer_sync.h"
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/blob.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
void FileWriterSync::write(Blob* data, ExceptionState& exception_state) {
|
||||
DCHECK(data);
|
||||
DCHECK(Writer());
|
||||
DCHECK(complete_);
|
||||
|
||||
PrepareForWrite();
|
||||
Writer()->Write(position(), data->Uuid());
|
||||
Write(position(), data->Uuid());
|
||||
DCHECK(complete_);
|
||||
if (error_) {
|
||||
FileError::ThrowDOMException(exception_state, error_);
|
||||
@ -55,14 +54,12 @@ void FileWriterSync::write(Blob* data, ExceptionState& exception_state) {
|
||||
}
|
||||
|
||||
void FileWriterSync::seek(long long position, ExceptionState& exception_state) {
|
||||
DCHECK(Writer());
|
||||
DCHECK(complete_);
|
||||
SeekInternal(position);
|
||||
}
|
||||
|
||||
void FileWriterSync::truncate(long long offset,
|
||||
ExceptionState& exception_state) {
|
||||
DCHECK(Writer());
|
||||
DCHECK(complete_);
|
||||
if (offset < 0) {
|
||||
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
|
||||
@ -70,7 +67,7 @@ void FileWriterSync::truncate(long long offset,
|
||||
return;
|
||||
}
|
||||
PrepareForWrite();
|
||||
Writer()->Truncate(offset);
|
||||
Truncate(offset);
|
||||
DCHECK(complete_);
|
||||
if (error_) {
|
||||
FileError::ThrowDOMException(exception_state, error_);
|
||||
@ -81,30 +78,50 @@ void FileWriterSync::truncate(long long offset,
|
||||
SetLength(offset);
|
||||
}
|
||||
|
||||
void FileWriterSync::DidWrite(long long bytes, bool complete) {
|
||||
DCHECK_EQ(FileError::kOK, error_);
|
||||
void FileWriterSync::DidWriteImpl(int64_t bytes, bool complete) {
|
||||
DCHECK_EQ(base::File::FILE_OK, error_);
|
||||
DCHECK(!complete_);
|
||||
complete_ = complete;
|
||||
}
|
||||
|
||||
void FileWriterSync::DidTruncate() {
|
||||
DCHECK_EQ(FileError::kOK, error_);
|
||||
void FileWriterSync::DidTruncateImpl() {
|
||||
DCHECK_EQ(base::File::FILE_OK, error_);
|
||||
DCHECK(!complete_);
|
||||
complete_ = true;
|
||||
}
|
||||
|
||||
void FileWriterSync::DidFail(WebFileError error) {
|
||||
DCHECK_EQ(FileError::kOK, error_);
|
||||
error_ = static_cast<FileError::ErrorCode>(error);
|
||||
void FileWriterSync::DidFailImpl(base::File::Error error) {
|
||||
DCHECK_EQ(base::File::FILE_OK, error_);
|
||||
error_ = error;
|
||||
DCHECK(!complete_);
|
||||
complete_ = true;
|
||||
}
|
||||
|
||||
FileWriterSync::FileWriterSync() : error_(FileError::kOK), complete_(true) {}
|
||||
void FileWriterSync::DoTruncate(const KURL& path, int64_t offset) {
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().TruncateSync(
|
||||
path, offset,
|
||||
WTF::Bind(&FileWriterSync::DidFinish, WrapWeakPersistent(this)));
|
||||
}
|
||||
|
||||
void FileWriterSync::DoWrite(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset) {
|
||||
FileSystemDispatcher::GetThreadSpecificInstance().WriteSync(
|
||||
path, blob_id, offset,
|
||||
WTF::BindRepeating(&FileWriterSync::DidWrite, WrapWeakPersistent(this)),
|
||||
WTF::Bind(&FileWriterSync::DidFinish, WrapWeakPersistent(this)));
|
||||
}
|
||||
|
||||
void FileWriterSync::DoCancel() {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
FileWriterSync::FileWriterSync()
|
||||
: error_(base::File::FILE_OK), complete_(true) {}
|
||||
|
||||
void FileWriterSync::PrepareForWrite() {
|
||||
DCHECK(complete_);
|
||||
error_ = FileError::kOK;
|
||||
error_ = base::File::FILE_OK;
|
||||
complete_ = false;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_WRITER_SYNC_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_WRITER_SYNC_H_
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_writer_client.h"
|
||||
#include "third_party/blink/renderer/core/fileapi/file_error.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_writer_base.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
|
||||
@ -42,9 +41,7 @@ namespace blink {
|
||||
class Blob;
|
||||
class ExceptionState;
|
||||
|
||||
class FileWriterSync final : public ScriptWrappable,
|
||||
public FileWriterBase,
|
||||
public WebFileWriterClient {
|
||||
class FileWriterSync final : public ScriptWrappable, public FileWriterBase {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
USING_GARBAGE_COLLECTED_MIXIN(FileWriterSync);
|
||||
|
||||
@ -53,21 +50,25 @@ class FileWriterSync final : public ScriptWrappable,
|
||||
~FileWriterSync() override;
|
||||
void Trace(blink::Visitor*) override;
|
||||
|
||||
// FileWriterBase
|
||||
void write(Blob*, ExceptionState&);
|
||||
void seek(long long position, ExceptionState&);
|
||||
void truncate(long long length, ExceptionState&);
|
||||
|
||||
// WebFileWriterClient, via FileWriterBase
|
||||
void DidWrite(long long bytes, bool complete) override;
|
||||
void DidTruncate() override;
|
||||
void DidFail(WebFileError) override;
|
||||
// FileWriterBase
|
||||
void DidWriteImpl(int64_t bytes, bool complete) override;
|
||||
void DidTruncateImpl() override;
|
||||
void DidFailImpl(base::File::Error error) override;
|
||||
void DoTruncate(const KURL& path, int64_t offset) override;
|
||||
void DoWrite(const KURL& path,
|
||||
const String& blob_id,
|
||||
int64_t offset) override;
|
||||
void DoCancel() override;
|
||||
|
||||
private:
|
||||
FileWriterSync();
|
||||
void PrepareForWrite();
|
||||
|
||||
FileError::ErrorCode error_;
|
||||
base::File::Error error_;
|
||||
bool complete_;
|
||||
};
|
||||
|
||||
|
353
third_party/blink/renderer/modules/filesystem/file_writer_test.cc
vendored
Normal file
353
third_party/blink/renderer/modules/filesystem/file_writer_test.cc
vendored
Normal file
@ -0,0 +1,353 @@
|
||||
// Copyright 2018 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 "third_party/blink/renderer/modules/filesystem/file_writer_base.h"
|
||||
#include "third_party/blink/renderer/platform/heap/persistent.h"
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
namespace {
|
||||
|
||||
// We use particular offsets to trigger particular behaviors
|
||||
// in the TestableFileWriter.
|
||||
const int kNoOffset = -1;
|
||||
const int kBasicFileTruncate_Offset = 1;
|
||||
const int kErrorFileTruncate_Offset = 2;
|
||||
const int kCancelFileTruncate_Offset = 3;
|
||||
const int kCancelFailedTruncate_Offset = 4;
|
||||
const int kBasicFileWrite_Offset = 1;
|
||||
const int kErrorFileWrite_Offset = 2;
|
||||
const int kMultiFileWrite_Offset = 3;
|
||||
const int kCancelFileWriteBeforeCompletion_Offset = 4;
|
||||
const int kCancelFileWriteAfterCompletion_Offset = 5;
|
||||
|
||||
KURL mock_path_as_kurl() {
|
||||
return KURL("MockPath");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class TestableFileWriter : public GarbageCollectedFinalized<TestableFileWriter>,
|
||||
public FileWriterBase {
|
||||
USING_GARBAGE_COLLECTED_MIXIN(TestableFileWriter);
|
||||
|
||||
public:
|
||||
explicit TestableFileWriter() { reset(); }
|
||||
|
||||
void reset() {
|
||||
received_truncate_ = false;
|
||||
received_truncate_path_ = KURL();
|
||||
received_truncate_offset_ = kNoOffset;
|
||||
received_write_ = false;
|
||||
received_write_path_ = KURL();
|
||||
received_write_offset_ = kNoOffset;
|
||||
received_write_blob_uuid_ = String();
|
||||
received_cancel_ = false;
|
||||
|
||||
received_did_write_count_ = 0;
|
||||
received_did_write_bytes_total_ = 0;
|
||||
received_did_write_complete_ = false;
|
||||
received_did_truncate_ = false;
|
||||
received_did_fail_ = false;
|
||||
fail_error_received_ = static_cast<base::File::Error>(0);
|
||||
}
|
||||
|
||||
void Trace(Visitor* visitor) override { FileWriterBase::Trace(visitor); }
|
||||
|
||||
bool received_truncate_;
|
||||
KURL received_truncate_path_;
|
||||
int64_t received_truncate_offset_;
|
||||
bool received_write_;
|
||||
KURL received_write_path_;
|
||||
String received_write_blob_uuid_;
|
||||
int64_t received_write_offset_;
|
||||
bool received_cancel_;
|
||||
|
||||
int received_did_write_count_;
|
||||
long long received_did_write_bytes_total_;
|
||||
bool received_did_write_complete_;
|
||||
bool received_did_truncate_;
|
||||
bool received_did_fail_;
|
||||
base::File::Error fail_error_received_;
|
||||
|
||||
protected:
|
||||
void DoTruncate(const KURL& path, int64_t offset) override {
|
||||
received_truncate_ = true;
|
||||
received_truncate_path_ = path;
|
||||
received_truncate_offset_ = offset;
|
||||
|
||||
if (offset == kBasicFileTruncate_Offset) {
|
||||
DidSucceed();
|
||||
} else if (offset == kErrorFileTruncate_Offset) {
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND);
|
||||
} else if (offset == kCancelFileTruncate_Offset) {
|
||||
Cancel();
|
||||
DidSucceed(); // truncate completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else if (offset == kCancelFailedTruncate_Offset) {
|
||||
Cancel();
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND); // truncate completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void DoWrite(const KURL& path,
|
||||
const String& blob_uuid,
|
||||
int64_t offset) override {
|
||||
received_write_ = true;
|
||||
received_write_path_ = path;
|
||||
received_write_offset_ = offset;
|
||||
received_write_blob_uuid_ = blob_uuid;
|
||||
|
||||
if (offset == kBasicFileWrite_Offset) {
|
||||
DidWrite(1, true);
|
||||
} else if (offset == kErrorFileWrite_Offset) {
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND);
|
||||
} else if (offset == kMultiFileWrite_Offset) {
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, true);
|
||||
} else if (offset == kCancelFileWriteBeforeCompletion_Offset) {
|
||||
DidWrite(1, false);
|
||||
Cancel();
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND); // write completion
|
||||
DidSucceed(); // cancel completion
|
||||
} else if (offset == kCancelFileWriteAfterCompletion_Offset) {
|
||||
DidWrite(1, false);
|
||||
Cancel();
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, false);
|
||||
DidWrite(1, true); // write completion
|
||||
DidFail(base::File::FILE_ERROR_NOT_FOUND); // cancel completion
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void DoCancel() override { received_cancel_ = true; }
|
||||
|
||||
void DidWriteImpl(int64_t bytes, bool complete) override {
|
||||
EXPECT_FALSE(received_did_write_complete_);
|
||||
++received_did_write_count_;
|
||||
received_did_write_bytes_total_ += bytes;
|
||||
if (complete)
|
||||
received_did_write_complete_ = true;
|
||||
}
|
||||
|
||||
void DidTruncateImpl() override {
|
||||
EXPECT_FALSE(received_did_truncate_);
|
||||
received_did_truncate_ = true;
|
||||
}
|
||||
|
||||
void DidFailImpl(base::File::Error error) override {
|
||||
EXPECT_FALSE(received_did_fail_);
|
||||
received_did_fail_ = true;
|
||||
fail_error_received_ = error;
|
||||
}
|
||||
};
|
||||
|
||||
class FileWriterTest : public testing::Test {
|
||||
public:
|
||||
FileWriterTest() = default;
|
||||
|
||||
FileWriterBase* writer() { return testable_writer_.Get(); }
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
testable_writer_ = new TestableFileWriter();
|
||||
testable_writer_->Initialize(mock_path_as_kurl(), 10);
|
||||
}
|
||||
|
||||
Persistent<TestableFileWriter> testable_writer_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FileWriterTest);
|
||||
};
|
||||
|
||||
TEST_F(FileWriterTest, BasicFileWrite) {
|
||||
const String kBlobId("1234");
|
||||
writer()->Write(kBasicFileWrite_Offset, kBlobId);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_, mock_path_as_kurl());
|
||||
EXPECT_EQ(kBasicFileWrite_Offset, testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_count_);
|
||||
EXPECT_TRUE(testable_writer_->received_did_write_complete_);
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, BasicFileTruncate) {
|
||||
writer()->Truncate(kBasicFileTruncate_Offset);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_kurl(), testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kBasicFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_EQ(0, testable_writer_->received_did_write_count_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, ErrorFileWrite) {
|
||||
const String kBlobId("1234");
|
||||
writer()->Write(kErrorFileWrite_Offset, kBlobId);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_, mock_path_as_kurl());
|
||||
EXPECT_EQ(kErrorFileWrite_Offset, testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_EQ(0, testable_writer_->received_did_write_count_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, ErrorFileTruncate) {
|
||||
writer()->Truncate(kErrorFileTruncate_Offset);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_kurl(), testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kErrorFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_EQ(0, testable_writer_->received_did_write_count_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, MultiFileWrite) {
|
||||
const String kBlobId("1234");
|
||||
writer()->Write(kMultiFileWrite_Offset, kBlobId);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_, mock_path_as_kurl());
|
||||
EXPECT_EQ(kMultiFileWrite_Offset, testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_cancel_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_EQ(3, testable_writer_->received_did_write_count_);
|
||||
EXPECT_TRUE(testable_writer_->received_did_write_complete_);
|
||||
EXPECT_EQ(3, testable_writer_->received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_fail_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileWriteBeforeCompletion) {
|
||||
const String kBlobId("1234");
|
||||
writer()->Write(kCancelFileWriteBeforeCompletion_Offset, kBlobId);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_, mock_path_as_kurl());
|
||||
EXPECT_EQ(kCancelFileWriteBeforeCompletion_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_ABORT,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_count_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_write_complete_);
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileWriteAfterCompletion) {
|
||||
const String kBlobId("1234");
|
||||
writer()->Write(kCancelFileWriteAfterCompletion_Offset, kBlobId);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_write_);
|
||||
EXPECT_EQ(testable_writer_->received_write_path_, mock_path_as_kurl());
|
||||
EXPECT_EQ(kCancelFileWriteAfterCompletion_Offset,
|
||||
testable_writer_->received_write_offset_);
|
||||
EXPECT_EQ(kBlobId, testable_writer_->received_write_blob_uuid_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_truncate_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_ABORT,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_count_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_write_complete_);
|
||||
EXPECT_EQ(1, testable_writer_->received_did_write_bytes_total_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFileTruncate) {
|
||||
writer()->Truncate(kCancelFileTruncate_Offset);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_kurl(), testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kCancelFileTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_ABORT,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_EQ(0, testable_writer_->received_did_write_count_);
|
||||
}
|
||||
|
||||
TEST_F(FileWriterTest, CancelFailedTruncate) {
|
||||
writer()->Truncate(kCancelFailedTruncate_Offset);
|
||||
|
||||
// Check that the Do* methods of the derived class get called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_truncate_);
|
||||
EXPECT_EQ(mock_path_as_kurl(), testable_writer_->received_truncate_path_);
|
||||
EXPECT_EQ(kCancelFailedTruncate_Offset,
|
||||
testable_writer_->received_truncate_offset_);
|
||||
EXPECT_TRUE(testable_writer_->received_cancel_);
|
||||
EXPECT_FALSE(testable_writer_->received_write_);
|
||||
|
||||
// Check that the Did*Impl methods of the client gets called correctly.
|
||||
EXPECT_TRUE(testable_writer_->received_did_fail_);
|
||||
EXPECT_EQ(base::File::FILE_ERROR_ABORT,
|
||||
testable_writer_->fail_error_received_);
|
||||
EXPECT_FALSE(testable_writer_->received_did_truncate_);
|
||||
EXPECT_EQ(0, testable_writer_->received_did_write_count_);
|
||||
}
|
||||
|
||||
} // namespace blink
|
@ -47,6 +47,7 @@
|
||||
#include "third_party/blink/renderer/modules/filesystem/directory_entry.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/dom_file_system.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_client.h"
|
||||
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
|
||||
#include "third_party/blink/renderer/platform/async_file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/platform/content_setting_callbacks.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/functional.h"
|
||||
@ -56,7 +57,7 @@ namespace blink {
|
||||
namespace {
|
||||
|
||||
void ReportFailure(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
FileError::ErrorCode error) {
|
||||
base::File::Error error) {
|
||||
callbacks->DidFail(error);
|
||||
}
|
||||
|
||||
@ -83,13 +84,14 @@ LocalFileSystem::~LocalFileSystem() = default;
|
||||
void LocalFileSystem::ResolveURL(
|
||||
ExecutionContext* context,
|
||||
const KURL& file_system_url,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
SynchronousType type) {
|
||||
CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
|
||||
RequestFileSystemAccessInternal(
|
||||
context,
|
||||
WTF::Bind(&LocalFileSystem::ResolveURLInternal,
|
||||
WrapCrossThreadPersistent(this), WrapPersistent(context),
|
||||
file_system_url, WrapPersistent(wrapper)),
|
||||
file_system_url, WrapPersistent(wrapper), type),
|
||||
WTF::Bind(&LocalFileSystem::FileSystemNotAllowedInternal,
|
||||
WrapCrossThreadPersistent(this), WrapPersistent(context),
|
||||
WrapPersistent(wrapper)));
|
||||
@ -99,13 +101,14 @@ void LocalFileSystem::RequestFileSystem(
|
||||
ExecutionContext* context,
|
||||
mojom::blink::FileSystemType type,
|
||||
long long size,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
|
||||
SynchronousType sync_type) {
|
||||
CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
|
||||
RequestFileSystemAccessInternal(
|
||||
context,
|
||||
WTF::Bind(&LocalFileSystem::FileSystemAllowedInternal,
|
||||
WrapCrossThreadPersistent(this), WrapPersistent(context), type,
|
||||
WrapPersistent(wrapper)),
|
||||
WrapPersistent(wrapper), sync_type),
|
||||
WTF::Bind(&LocalFileSystem::FileSystemNotAllowedInternal,
|
||||
WrapCrossThreadPersistent(this), WrapPersistent(context),
|
||||
WrapPersistent(wrapper)));
|
||||
@ -160,13 +163,15 @@ class ChooseEntryCallbacks : public WebFileSystem::ChooseEntryCallbacks {
|
||||
|
||||
void LocalFileSystem::ChooseEntry(ScriptPromiseResolver* resolver) {
|
||||
if (!base::FeatureList::IsEnabled(blink::features::kWritableFilesAPI)) {
|
||||
resolver->Reject(FileError::CreateDOMException(FileError::kAbortErr));
|
||||
resolver->Reject(
|
||||
FileError::CreateDOMException(base::File::FILE_ERROR_ABORT));
|
||||
return;
|
||||
}
|
||||
|
||||
WebFileSystem* file_system = GetFileSystem();
|
||||
if (!file_system) {
|
||||
resolver->Reject(FileError::CreateDOMException(FileError::kAbortErr));
|
||||
resolver->Reject(
|
||||
FileError::CreateDOMException(base::File::FILE_ERROR_ABORT));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -205,7 +210,7 @@ void LocalFileSystem::FileSystemNotAvailable(ExecutionContext* context,
|
||||
context->GetTaskRunner(TaskType::kFileReading)
|
||||
->PostTask(FROM_HERE,
|
||||
WTF::Bind(&ReportFailure, WTF::Passed(callbacks->Release()),
|
||||
FileError::kAbortErr));
|
||||
base::File::FILE_ERROR_ABORT));
|
||||
}
|
||||
|
||||
void LocalFileSystem::FileSystemNotAllowedInternal(ExecutionContext* context,
|
||||
@ -213,34 +218,42 @@ void LocalFileSystem::FileSystemNotAllowedInternal(ExecutionContext* context,
|
||||
context->GetTaskRunner(TaskType::kFileReading)
|
||||
->PostTask(FROM_HERE,
|
||||
WTF::Bind(&ReportFailure, WTF::Passed(callbacks->Release()),
|
||||
FileError::kAbortErr));
|
||||
base::File::FILE_ERROR_ABORT));
|
||||
}
|
||||
|
||||
void LocalFileSystem::FileSystemAllowedInternal(
|
||||
ExecutionContext* context,
|
||||
mojom::blink::FileSystemType type,
|
||||
CallbackWrapper* callbacks) {
|
||||
WebFileSystem* file_system = GetFileSystem();
|
||||
if (!file_system) {
|
||||
FileSystemNotAvailable(context, callbacks);
|
||||
return;
|
||||
}
|
||||
CallbackWrapper* callbacks,
|
||||
SynchronousType sync_type) {
|
||||
KURL storage_partition =
|
||||
KURL(NullURL(), context->GetSecurityOrigin()->ToString());
|
||||
file_system->OpenFileSystem(storage_partition,
|
||||
static_cast<WebFileSystemType>(type),
|
||||
callbacks->Release());
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> async_callbacks =
|
||||
callbacks->Release();
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
if (sync_type == kSynchronous) {
|
||||
dispatcher.OpenFileSystemSync(storage_partition, type,
|
||||
std::move(async_callbacks));
|
||||
} else {
|
||||
dispatcher.OpenFileSystem(storage_partition, type,
|
||||
std::move(async_callbacks));
|
||||
}
|
||||
}
|
||||
|
||||
void LocalFileSystem::ResolveURLInternal(ExecutionContext* context,
|
||||
const KURL& file_system_url,
|
||||
CallbackWrapper* callbacks) {
|
||||
WebFileSystem* file_system = GetFileSystem();
|
||||
if (!file_system) {
|
||||
FileSystemNotAvailable(context, callbacks);
|
||||
return;
|
||||
CallbackWrapper* callbacks,
|
||||
SynchronousType sync_type) {
|
||||
FileSystemDispatcher& dispatcher =
|
||||
FileSystemDispatcher::GetThreadSpecificInstance();
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> async_callbacks =
|
||||
callbacks->Release();
|
||||
if (sync_type == kSynchronous) {
|
||||
dispatcher.ResolveURLSync(file_system_url, std::move(async_callbacks));
|
||||
} else {
|
||||
dispatcher.ResolveURL(file_system_url, std::move(async_callbacks));
|
||||
}
|
||||
file_system->ResolveURL(file_system_url, callbacks->Release());
|
||||
}
|
||||
|
||||
LocalFileSystem::LocalFileSystem(LocalFrame& frame,
|
||||
|
@ -59,6 +59,8 @@ class LocalFileSystem final : public GarbageCollectedFinalized<LocalFileSystem>,
|
||||
WTF_MAKE_NONCOPYABLE(LocalFileSystem);
|
||||
|
||||
public:
|
||||
enum SynchronousType { kAsynchronous, kSynchronous };
|
||||
|
||||
static const char kSupplementName[];
|
||||
|
||||
LocalFileSystem(LocalFrame&, std::unique_ptr<FileSystemClient>);
|
||||
@ -67,11 +69,13 @@ class LocalFileSystem final : public GarbageCollectedFinalized<LocalFileSystem>,
|
||||
|
||||
void ResolveURL(ExecutionContext*,
|
||||
const KURL&,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>);
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>,
|
||||
SynchronousType sync_type);
|
||||
void RequestFileSystem(ExecutionContext*,
|
||||
mojom::blink::FileSystemType,
|
||||
long long size,
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>);
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>,
|
||||
SynchronousType sync_type);
|
||||
|
||||
void ChooseEntry(ScriptPromiseResolver*);
|
||||
|
||||
@ -92,8 +96,12 @@ class LocalFileSystem final : public GarbageCollectedFinalized<LocalFileSystem>,
|
||||
void FileSystemNotAllowedInternal(ExecutionContext*, CallbackWrapper*);
|
||||
void FileSystemAllowedInternal(ExecutionContext*,
|
||||
mojom::blink::FileSystemType,
|
||||
CallbackWrapper*);
|
||||
void ResolveURLInternal(ExecutionContext*, const KURL&, CallbackWrapper*);
|
||||
CallbackWrapper*,
|
||||
SynchronousType sync_type);
|
||||
void ResolveURLInternal(ExecutionContext*,
|
||||
const KURL&,
|
||||
CallbackWrapper*,
|
||||
SynchronousType sync_type);
|
||||
|
||||
const std::unique_ptr<FileSystemClient> client_;
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ class DOMFileSystemCallbacksSyncHelper final
|
||||
ErrorCallbackBase* GetErrorCallback() { return new ErrorCallbackImpl(this); }
|
||||
|
||||
CallbackArg* GetResultOrThrow(ExceptionState& exception_state) {
|
||||
if (error_code_ != FileError::ErrorCode::kOK) {
|
||||
if (error_code_ != base::File::FILE_OK) {
|
||||
FileError::ThrowDOMException(exception_state, error_code_);
|
||||
return nullptr;
|
||||
}
|
||||
@ -90,8 +90,8 @@ class DOMFileSystemCallbacksSyncHelper final
|
||||
visitor->Trace(helper_);
|
||||
ErrorCallbackBase::Trace(visitor);
|
||||
}
|
||||
void Invoke(FileError::ErrorCode error_code) override {
|
||||
DCHECK_NE(error_code, FileError::ErrorCode::kOK);
|
||||
void Invoke(base::File::Error error_code) override {
|
||||
DCHECK_NE(error_code, base::File::FILE_OK);
|
||||
helper_->error_code_ = error_code;
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ class DOMFileSystemCallbacksSyncHelper final
|
||||
DOMFileSystemCallbacksSyncHelper() = default;
|
||||
|
||||
Member<CallbackArg> result_;
|
||||
FileError::ErrorCode error_code_ = FileError::ErrorCode::kOK;
|
||||
base::File::Error error_code_ = base::File::FILE_OK;
|
||||
|
||||
friend class SuccessCallbackImpl;
|
||||
friend class ErrorCallbackImpl;
|
||||
|
@ -55,7 +55,7 @@ void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(
|
||||
if (!secure_context->GetSecurityOrigin()->CanAccessFileSystem()) {
|
||||
DOMFileSystem::ReportError(&worker,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kSecurityErr);
|
||||
base::File::FILE_ERROR_SECURITY);
|
||||
return;
|
||||
} else if (secure_context->GetSecurityOrigin()->IsLocal()) {
|
||||
UseCounter::Count(secure_context, WebFeature::kFileAccessedFileSystem);
|
||||
@ -66,7 +66,7 @@ void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(
|
||||
if (!DOMFileSystemBase::IsValidType(file_system_type)) {
|
||||
DOMFileSystem::ReportError(&worker,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kInvalidModificationErr);
|
||||
base::File::FILE_ERROR_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,8 +75,8 @@ void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(
|
||||
FileSystemCallbacks::Create(
|
||||
FileSystemCallbacks::OnDidOpenFileSystemV8Impl::Create(
|
||||
success_callback),
|
||||
ScriptErrorCallback::Wrap(error_callback), &worker,
|
||||
file_system_type));
|
||||
ScriptErrorCallback::Wrap(error_callback), &worker, file_system_type),
|
||||
LocalFileSystem::kAsynchronous);
|
||||
}
|
||||
|
||||
DOMFileSystemSync* WorkerGlobalScopeFileSystem::webkitRequestFileSystemSync(
|
||||
@ -107,10 +107,10 @@ DOMFileSystemSync* WorkerGlobalScopeFileSystem::webkitRequestFileSystemSync(
|
||||
FileSystemCallbacks::Create(sync_helper->GetSuccessCallback(),
|
||||
sync_helper->GetErrorCallback(), &worker,
|
||||
file_system_type);
|
||||
callbacks->SetShouldBlockUntilCompletion(true);
|
||||
|
||||
LocalFileSystem::From(worker)->RequestFileSystem(&worker, file_system_type,
|
||||
size, std::move(callbacks));
|
||||
LocalFileSystem::From(worker)->RequestFileSystem(
|
||||
&worker, file_system_type, size, std::move(callbacks),
|
||||
LocalFileSystem::kSynchronous);
|
||||
DOMFileSystem* file_system = sync_helper->GetResultOrThrow(exception_state);
|
||||
return file_system ? DOMFileSystemSync::Create(file_system) : nullptr;
|
||||
}
|
||||
@ -126,7 +126,7 @@ void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(
|
||||
!secure_context->GetSecurityOrigin()->CanRequest(completed_url)) {
|
||||
DOMFileSystem::ReportError(&worker,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kSecurityErr);
|
||||
base::File::FILE_ERROR_SECURITY);
|
||||
return;
|
||||
} else if (secure_context->GetSecurityOrigin()->IsLocal()) {
|
||||
UseCounter::Count(secure_context, WebFeature::kFileAccessedFileSystem);
|
||||
@ -135,7 +135,7 @@ void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(
|
||||
if (!completed_url.IsValid()) {
|
||||
DOMFileSystem::ReportError(&worker,
|
||||
ScriptErrorCallback::Wrap(error_callback),
|
||||
FileError::kEncodingErr);
|
||||
base::File::FILE_ERROR_INVALID_URL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -143,7 +143,8 @@ void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(
|
||||
&worker, completed_url,
|
||||
ResolveURICallbacks::Create(
|
||||
ResolveURICallbacks::OnDidGetEntryV8Impl::Create(success_callback),
|
||||
ScriptErrorCallback::Wrap(error_callback), &worker));
|
||||
ScriptErrorCallback::Wrap(error_callback), &worker),
|
||||
LocalFileSystem::kAsynchronous);
|
||||
}
|
||||
|
||||
EntrySync* WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemSyncURL(
|
||||
@ -170,10 +171,10 @@ EntrySync* WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemSyncURL(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
|
||||
ResolveURICallbacks::Create(sync_helper->GetSuccessCallback(),
|
||||
sync_helper->GetErrorCallback(), &worker);
|
||||
callbacks->SetShouldBlockUntilCompletion(true);
|
||||
|
||||
LocalFileSystem::From(worker)->ResolveURL(&worker, completed_url,
|
||||
std::move(callbacks));
|
||||
std::move(callbacks),
|
||||
LocalFileSystem::kSynchronous);
|
||||
|
||||
Entry* entry = sync_helper->GetResultOrThrow(exception_state);
|
||||
return entry ? EntrySync::Create(entry) : nullptr;
|
||||
|
1
third_party/blink/renderer/platform/BUILD.gn
vendored
1
third_party/blink/renderer/platform/BUILD.gn
vendored
@ -528,7 +528,6 @@ jumbo_component("platform") {
|
||||
"exported/web_encrypted_media_client.cc",
|
||||
"exported/web_encrypted_media_key_information.cc",
|
||||
"exported/web_encrypted_media_request.cc",
|
||||
"exported/web_file_system_callbacks.cc",
|
||||
"exported/web_font.cc",
|
||||
"exported/web_font_description.cc",
|
||||
"exported/web_http_body.cc",
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/renderer/platform/blob/blob_data.h"
|
||||
#include "third_party/blink/renderer/platform/file_metadata.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/allocator.h"
|
||||
@ -43,12 +42,12 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
class PLATFORM_EXPORT AsyncFileSystemCallbacks {
|
||||
class AsyncFileSystemCallbacks {
|
||||
USING_FAST_MALLOC(AsyncFileSystemCallbacks);
|
||||
WTF_MAKE_NONCOPYABLE(AsyncFileSystemCallbacks);
|
||||
|
||||
public:
|
||||
AsyncFileSystemCallbacks() : block_until_completion_(false) {}
|
||||
AsyncFileSystemCallbacks() = default;
|
||||
|
||||
// Called when a requested operation is completed successfully.
|
||||
virtual void DidSucceed() { NOTREACHED(); }
|
||||
@ -87,28 +86,14 @@ class PLATFORM_EXPORT AsyncFileSystemCallbacks {
|
||||
virtual void DidReadDirectoryEntries(bool has_more) { NOTREACHED(); }
|
||||
|
||||
// Called when an AsyncFileWrter has been created successfully.
|
||||
virtual void DidCreateFileWriter(std::unique_ptr<WebFileWriter>,
|
||||
long long length) {
|
||||
virtual void DidCreateFileWriter(const KURL& path, long long length) {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
// Called when there was an error.
|
||||
virtual void DidFail(int code) = 0;
|
||||
|
||||
// Returns true if the caller expects that the calling thread blocks
|
||||
// until completion.
|
||||
virtual bool ShouldBlockUntilCompletion() const {
|
||||
return block_until_completion_;
|
||||
}
|
||||
|
||||
void SetShouldBlockUntilCompletion(bool flag) {
|
||||
block_until_completion_ = flag;
|
||||
}
|
||||
virtual void DidFail(base::File::Error) = 0;
|
||||
|
||||
virtual ~AsyncFileSystemCallbacks() = default;
|
||||
|
||||
private:
|
||||
bool block_until_completion_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "third_party/blink/public/platform/web_file_system_callbacks.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "third_party/blink/public/platform/web_file_info.h"
|
||||
#include "third_party/blink/public/platform/web_file_system.h"
|
||||
#include "third_party/blink/public/platform/web_file_system_entry.h"
|
||||
#include "third_party/blink/public/platform/web_file_writer.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/renderer/platform/async_file_system_callbacks.h"
|
||||
#include "third_party/blink/renderer/platform/file_metadata.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class WebFileSystemCallbacksPrivate
|
||||
: public RefCounted<WebFileSystemCallbacksPrivate> {
|
||||
public:
|
||||
static scoped_refptr<WebFileSystemCallbacksPrivate> Create(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
|
||||
return base::AdoptRef(
|
||||
new WebFileSystemCallbacksPrivate(std::move(callbacks)));
|
||||
}
|
||||
|
||||
AsyncFileSystemCallbacks* Callbacks() { return callbacks_.get(); }
|
||||
|
||||
private:
|
||||
WebFileSystemCallbacksPrivate(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks)
|
||||
: callbacks_(std::move(callbacks)) {}
|
||||
std::unique_ptr<AsyncFileSystemCallbacks> callbacks_;
|
||||
};
|
||||
|
||||
WebFileSystemCallbacks::WebFileSystemCallbacks(
|
||||
std::unique_ptr<AsyncFileSystemCallbacks>&& callbacks) {
|
||||
private_ = WebFileSystemCallbacksPrivate::Create(std::move(callbacks));
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::Reset() {
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::Assign(const WebFileSystemCallbacks& other) {
|
||||
private_ = other.private_;
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidSucceed() {
|
||||
DCHECK(!private_.IsNull());
|
||||
private_->Callbacks()->DidSucceed();
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidReadMetadata(const WebFileInfo& web_file_info) {
|
||||
DCHECK(!private_.IsNull());
|
||||
FileMetadata file_metadata;
|
||||
file_metadata.modification_time = web_file_info.modification_time;
|
||||
file_metadata.length = web_file_info.length;
|
||||
file_metadata.type = static_cast<FileMetadata::Type>(web_file_info.type);
|
||||
file_metadata.platform_path = web_file_info.platform_path;
|
||||
private_->Callbacks()->DidReadMetadata(file_metadata);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidCreateSnapshotFile(
|
||||
const WebFileInfo& web_file_info) {
|
||||
DCHECK(!private_.IsNull());
|
||||
// It's important to create a BlobDataHandle that refers to the platform file
|
||||
// path prior to return from this method so the underlying file will not be
|
||||
// deleted.
|
||||
std::unique_ptr<BlobData> blob_data = BlobData::Create();
|
||||
blob_data->AppendFile(web_file_info.platform_path, 0, web_file_info.length,
|
||||
InvalidFileTime());
|
||||
scoped_refptr<BlobDataHandle> snapshot_blob =
|
||||
BlobDataHandle::Create(std::move(blob_data), web_file_info.length);
|
||||
|
||||
FileMetadata file_metadata;
|
||||
file_metadata.modification_time = web_file_info.modification_time;
|
||||
file_metadata.length = web_file_info.length;
|
||||
file_metadata.type = static_cast<FileMetadata::Type>(web_file_info.type);
|
||||
file_metadata.platform_path = web_file_info.platform_path;
|
||||
private_->Callbacks()->DidCreateSnapshotFile(file_metadata, snapshot_blob);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidReadDirectory(
|
||||
const WebVector<WebFileSystemEntry>& entries,
|
||||
bool has_more) {
|
||||
DCHECK(!private_.IsNull());
|
||||
for (size_t i = 0; i < entries.size(); ++i)
|
||||
private_->Callbacks()->DidReadDirectoryEntry(entries[i].name,
|
||||
entries[i].is_directory);
|
||||
private_->Callbacks()->DidReadDirectoryEntries(has_more);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidOpenFileSystem(const WebString& name,
|
||||
const WebURL& root_url) {
|
||||
DCHECK(!private_.IsNull());
|
||||
private_->Callbacks()->DidOpenFileSystem(name, root_url);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidResolveURL(const WebString& name,
|
||||
const WebURL& root_url,
|
||||
WebFileSystemType type,
|
||||
const WebString& file_path,
|
||||
bool is_directory) {
|
||||
DCHECK(!private_.IsNull());
|
||||
private_->Callbacks()->DidResolveURL(
|
||||
name, root_url, static_cast<mojom::blink::FileSystemType>(type),
|
||||
file_path, is_directory);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidCreateFileWriter(WebFileWriter* web_file_writer,
|
||||
long long length) {
|
||||
DCHECK(!private_.IsNull());
|
||||
private_->Callbacks()->DidCreateFileWriter(base::WrapUnique(web_file_writer),
|
||||
length);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
void WebFileSystemCallbacks::DidFail(WebFileError error) {
|
||||
DCHECK(!private_.IsNull());
|
||||
private_->Callbacks()->DidFail(error);
|
||||
private_.Reset();
|
||||
}
|
||||
|
||||
bool WebFileSystemCallbacks::ShouldBlockUntilCompletion() const {
|
||||
DCHECK(!private_.IsNull());
|
||||
return private_->Callbacks()->ShouldBlockUntilCompletion();
|
||||
}
|
||||
|
||||
} // namespace blink
|
@ -36,13 +36,27 @@
|
||||
#include "third_party/blink/public/platform/file_path_conversion.h"
|
||||
#include "third_party/blink/public/platform/interface_provider.h"
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/public/platform/web_file_info.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// static
|
||||
FileMetadata FileMetadata::From(const base::File::Info& file_info) {
|
||||
FileMetadata file_metadata;
|
||||
if (file_info.last_modified.is_null())
|
||||
file_metadata.modification_time = std::numeric_limits<double>::quiet_NaN();
|
||||
else
|
||||
file_metadata.modification_time = file_info.last_modified.ToJsTime();
|
||||
file_metadata.length = file_info.size;
|
||||
if (file_info.is_directory)
|
||||
file_metadata.type = FileMetadata::kTypeDirectory;
|
||||
else
|
||||
file_metadata.type = FileMetadata::kTypeFile;
|
||||
return file_metadata;
|
||||
}
|
||||
|
||||
bool GetFileSize(const String& path, long long& result) {
|
||||
FileMetadata metadata;
|
||||
if (!GetFileMetadata(path, metadata))
|
||||
@ -90,8 +104,4 @@ KURL FilePathToURL(const String& path) {
|
||||
gurl.parsed_for_possibly_invalid_spec(), gurl.is_valid());
|
||||
}
|
||||
|
||||
STATIC_ASSERT_ENUM(WebFileInfo::kTypeUnknown, FileMetadata::kTypeUnknown);
|
||||
STATIC_ASSERT_ENUM(WebFileInfo::kTypeFile, FileMetadata::kTypeFile);
|
||||
STATIC_ASSERT_ENUM(WebFileInfo::kTypeDirectory, FileMetadata::kTypeDirectory);
|
||||
|
||||
} // namespace blink
|
||||
|
@ -32,6 +32,7 @@
|
||||
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FILE_METADATA_H_
|
||||
|
||||
#include <time.h>
|
||||
#include "base/files/file.h"
|
||||
#include "third_party/blink/renderer/platform/platform_export.h"
|
||||
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/allocator.h"
|
||||
@ -54,6 +55,8 @@ class FileMetadata {
|
||||
FileMetadata()
|
||||
: modification_time(InvalidFileTime()), length(-1), type(kTypeUnknown) {}
|
||||
|
||||
PLATFORM_EXPORT static FileMetadata From(const base::File::Info& file_info);
|
||||
|
||||
// The last modification time of the file, in milliseconds.
|
||||
// The value NaN means that the time is not known.
|
||||
double modification_time;
|
||||
|
@ -5,6 +5,7 @@
|
||||
typemaps = [
|
||||
"//mojo/public/cpp/base/file_info.typemap",
|
||||
"//mojo/public/cpp/base/file_path.typemap",
|
||||
"//mojo/public/cpp/base/file_error.typemap",
|
||||
"//mojo/public/cpp/base/shared_memory.typemap",
|
||||
"//mojo/public/cpp/base/unguessable_token.typemap",
|
||||
"//third_party/blink/renderer/core/messaging/blink_cloneable_message.typemap",
|
||||
|
Reference in New Issue
Block a user