Commit e14a69ef authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[NativeFS] Remove some no longer needed thread hopping.

Now all code runs on the UI thread we no longer need to do thread hopping
in these places.

Bug: 1011534
Change-Id: I17107d20963f7f7d900294b13576c628fa24faa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860313
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarOlivier Yiptong <oyiptong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710161}
parent 7db45830
...@@ -115,14 +115,11 @@ FileSystemChooser::Options::Options( ...@@ -115,14 +115,11 @@ FileSystemChooser::Options::Options(
file_types_(ConvertAcceptsToFileTypeInfo(accepts, include_accepts_all)) {} file_types_(ConvertAcceptsToFileTypeInfo(accepts, include_accepts_all)) {}
// static // static
void FileSystemChooser::CreateAndShow( void FileSystemChooser::CreateAndShow(WebContents* web_contents,
WebContents* web_contents, const Options& options,
const Options& options, ResultCallback callback) {
ResultCallback callback,
scoped_refptr<base::TaskRunner> callback_runner) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto* listener = new FileSystemChooser(options.type(), std::move(callback), auto* listener = new FileSystemChooser(options.type(), std::move(callback));
std::move(callback_runner));
listener->dialog_ = ui::SelectFileDialog::Create( listener->dialog_ = ui::SelectFileDialog::Create(
listener, listener,
GetContentClient()->browser()->CreateSelectFilePolicy(web_contents)); GetContentClient()->browser()->CreateSelectFilePolicy(web_contents));
...@@ -157,11 +154,8 @@ void FileSystemChooser::CreateAndShow( ...@@ -157,11 +154,8 @@ void FileSystemChooser::CreateAndShow(
FileSystemChooser::FileSystemChooser( FileSystemChooser::FileSystemChooser(
blink::mojom::ChooseFileSystemEntryType type, blink::mojom::ChooseFileSystemEntryType type,
ResultCallback callback, ResultCallback callback)
scoped_refptr<base::TaskRunner> callback_runner) : callback_(std::move(callback)), type_(type) {}
: callback_(std::move(callback)),
callback_runner_(std::move(callback_runner)),
type_(type) {}
FileSystemChooser::~FileSystemChooser() { FileSystemChooser::~FileSystemChooser() {
if (dialog_) if (dialog_)
...@@ -181,22 +175,16 @@ void FileSystemChooser::MultiFilesSelected( ...@@ -181,22 +175,16 @@ void FileSystemChooser::MultiFilesSelected(
DCHECK(isolated_context); DCHECK(isolated_context);
RecordFileSelectionResult(type_, files.size()); RecordFileSelectionResult(type_, files.size());
callback_runner_->PostTask( std::move(callback_).Run(native_file_system_error::Ok(), std::move(files));
FROM_HERE,
base::BindOnce(std::move(callback_), native_file_system_error::Ok(),
std::move(files)));
delete this; delete this;
} }
void FileSystemChooser::FileSelectionCanceled(void* params) { void FileSystemChooser::FileSelectionCanceled(void* params) {
RecordFileSelectionResult(type_, 0); RecordFileSelectionResult(type_, 0);
callback_runner_->PostTask( std::move(callback_).Run(
FROM_HERE, native_file_system_error::FromStatus(
base::BindOnce( blink::mojom::NativeFileSystemStatus::kOperationAborted),
std::move(callback_), std::vector<base::FilePath>());
native_file_system_error::FromStatus(
blink::mojom::NativeFileSystemStatus::kOperationAborted),
std::vector<base::FilePath>()));
delete this; delete this;
} }
......
...@@ -49,12 +49,10 @@ class CONTENT_EXPORT FileSystemChooser : public ui::SelectFileDialog::Listener { ...@@ -49,12 +49,10 @@ class CONTENT_EXPORT FileSystemChooser : public ui::SelectFileDialog::Listener {
static void CreateAndShow(WebContents* web_contents, static void CreateAndShow(WebContents* web_contents,
const Options& options, const Options& options,
ResultCallback callback, ResultCallback callback);
scoped_refptr<base::TaskRunner> callback_runner);
FileSystemChooser(blink::mojom::ChooseFileSystemEntryType type, FileSystemChooser(blink::mojom::ChooseFileSystemEntryType type,
ResultCallback callback, ResultCallback callback);
scoped_refptr<base::TaskRunner> callback_runner);
private: private:
~FileSystemChooser() override; ~FileSystemChooser() override;
...@@ -68,7 +66,6 @@ class CONTENT_EXPORT FileSystemChooser : public ui::SelectFileDialog::Listener { ...@@ -68,7 +66,6 @@ class CONTENT_EXPORT FileSystemChooser : public ui::SelectFileDialog::Listener {
void FileSelectionCanceled(void* params) override; void FileSelectionCanceled(void* params) override;
ResultCallback callback_; ResultCallback callback_;
scoped_refptr<base::TaskRunner> callback_runner_;
blink::mojom::ChooseFileSystemEntryType type_; blink::mojom::ChooseFileSystemEntryType type_;
scoped_refptr<ui::SelectFileDialog> dialog_; scoped_refptr<ui::SelectFileDialog> dialog_;
......
...@@ -34,8 +34,7 @@ class FileSystemChooserTest : public testing::Test { ...@@ -34,8 +34,7 @@ class FileSystemChooserTest : public testing::Test {
std::move(accepts), include_accepts_all), std::move(accepts), include_accepts_all),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](blink::mojom::NativeFileSystemErrorPtr, [&](blink::mojom::NativeFileSystemErrorPtr,
std::vector<base::FilePath>) { loop.Quit(); }), std::vector<base::FilePath>) { loop.Quit(); }));
base::SequencedTaskRunnerHandle::Get());
loop.Run(); loop.Run();
} }
......
...@@ -44,21 +44,16 @@ namespace { ...@@ -44,21 +44,16 @@ namespace {
void ShowFilePickerOnUIThread(const url::Origin& requesting_origin, void ShowFilePickerOnUIThread(const url::Origin& requesting_origin,
int render_process_id, int render_process_id,
int frame_id, int frame_id,
bool require_user_gesture,
const FileSystemChooser::Options& options, const FileSystemChooser::Options& options,
FileSystemChooser::ResultCallback callback, FileSystemChooser::ResultCallback callback) {
scoped_refptr<base::TaskRunner> callback_runner) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHost* rfh = RenderFrameHost::FromID(render_process_id, frame_id); RenderFrameHost* rfh = RenderFrameHost::FromID(render_process_id, frame_id);
WebContents* web_contents = WebContents::FromRenderFrameHost(rfh); WebContents* web_contents = WebContents::FromRenderFrameHost(rfh);
if (!web_contents) { if (!web_contents) {
callback_runner->PostTask( std::move(callback).Run(native_file_system_error::FromStatus(
FROM_HERE, NativeFileSystemStatus::kOperationAborted),
base::BindOnce(std::move(callback), std::vector<base::FilePath>());
native_file_system_error::FromStatus(
NativeFileSystemStatus::kOperationAborted),
std::vector<base::FilePath>()));
return; return;
} }
...@@ -66,48 +61,18 @@ void ShowFilePickerOnUIThread(const url::Origin& requesting_origin, ...@@ -66,48 +61,18 @@ void ShowFilePickerOnUIThread(const url::Origin& requesting_origin,
url::Origin::Create(web_contents->GetLastCommittedURL()); url::Origin::Create(web_contents->GetLastCommittedURL());
if (embedding_origin != requesting_origin) { if (embedding_origin != requesting_origin) {
// Third party iframes are not allowed to show a file picker. // Third party iframes are not allowed to show a file picker.
callback_runner->PostTask( std::move(callback).Run(
FROM_HERE, native_file_system_error::FromStatus(
base::BindOnce( NativeFileSystemStatus::kPermissionDenied,
std::move(callback), "Third party iframes are not allowed to show a file picker."),
native_file_system_error::FromStatus( std::vector<base::FilePath>());
NativeFileSystemStatus::kPermissionDenied,
"Third party iframes are not allowed to show a file picker."),
std::vector<base::FilePath>()));
return;
}
// Renderer process should already check for user activation before sending
// IPC, but just to be sure double check here as well. This is not treated
// as a BadMessage because it is possible for the transient user activation
// to expire between the renderer side check and this check.
if (require_user_gesture && !rfh->HasTransientUserActivation()) {
callback_runner->PostTask(
FROM_HERE,
base::BindOnce(
std::move(callback),
native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied,
"User activation is required to show a file picker."),
std::vector<base::FilePath>()));
return; return;
} }
// Drop fullscreen mode so that the user sees the URL bar. // Drop fullscreen mode so that the user sees the URL bar.
web_contents->ForSecurityDropFullscreen(); web_contents->ForSecurityDropFullscreen();
FileSystemChooser::CreateAndShow(web_contents, options, std::move(callback), FileSystemChooser::CreateAndShow(web_contents, options, std::move(callback));
std::move(callback_runner));
}
bool HasTransientUserActivation(int render_process_id, int frame_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHost* rfh = RenderFrameHost::FromID(render_process_id, frame_id);
if (!rfh)
return false;
return rfh->HasTransientUserActivation();
} }
bool CreateOrTruncateFile(const base::FilePath& path) { bool CreateOrTruncateFile(const base::FilePath& path) {
...@@ -238,17 +203,36 @@ void NativeFileSystemManagerImpl::ChooseEntries( ...@@ -238,17 +203,36 @@ void NativeFileSystemManagerImpl::ChooseEntries(
return; return;
} }
RenderFrameHost* rfh =
RenderFrameHost::FromID(context.process_id, context.frame_id);
if (!rfh) {
std::move(callback).Run(
native_file_system_error::FromStatus(
NativeFileSystemStatus::kOperationAborted),
std::vector<blink::mojom::NativeFileSystemEntryPtr>());
return;
}
// Renderer process should already check for user activation before sending
// IPC, but just to be sure double check here as well. This is not treated
// as a BadMessage because it is possible for the transient user activation
// to expire between the renderer side check and this check.
if (!rfh->HasTransientUserActivation()) {
std::move(callback).Run(
native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied,
"User activation is required to show a file picker."),
std::vector<blink::mojom::NativeFileSystemEntryPtr>());
return;
}
FileSystemChooser::Options options(type, std::move(accepts), FileSystemChooser::Options options(type, std::move(accepts),
include_accepts_all); include_accepts_all);
base::PostTask( ShowFilePickerOnUIThread(
FROM_HERE, {BrowserThread::UI}, context.origin, context.process_id, context.frame_id, options,
base::BindOnce( base::BindOnce(&NativeFileSystemManagerImpl::DidChooseEntries,
&ShowFilePickerOnUIThread, context.origin, context.process_id, weak_factory_.GetWeakPtr(), context, options,
context.frame_id, /*require_user_gesture=*/true, options, std::move(callback)));
base::BindOnce(&NativeFileSystemManagerImpl::DidChooseEntries,
weak_factory_.GetWeakPtr(), context, options,
std::move(callback)),
base::SequencedTaskRunnerHandle::Get()));
} }
void NativeFileSystemManagerImpl::GetFileHandleFromToken( void NativeFileSystemManagerImpl::GetFileHandleFromToken(
...@@ -384,16 +368,14 @@ NativeFileSystemManagerImpl::CreateFileWriter( ...@@ -384,16 +368,14 @@ NativeFileSystemManagerImpl::CreateFileWriter(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
mojo::PendingRemote<blink::mojom::NativeFileSystemFileWriter> result; mojo::PendingRemote<blink::mojom::NativeFileSystemFileWriter> result;
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver = result.InitWithNewPipeAndPassReceiver(); RenderFrameHost* rfh = RenderFrameHost::FromID(binding_context.process_id,
binding_context.frame_id);
base::PostTaskAndReplyWithResult( bool has_transient_user_activation = rfh && rfh->HasTransientUserActivation();
FROM_HERE, {BrowserThread::UI}, writer_receivers_.Add(std::make_unique<NativeFileSystemFileWriterImpl>(
base::BindOnce(&HasTransientUserActivation, binding_context.process_id, this, binding_context, url, swap_url, handle_state,
binding_context.frame_id), has_transient_user_activation),
base::BindOnce(&NativeFileSystemManagerImpl::CreateFileWriterImpl, result.InitWithNewPipeAndPassReceiver());
weak_factory_.GetWeakPtr(), binding_context, url, swap_url,
handle_state, std::move(writer_receiver)));
return result; return result;
} }
...@@ -566,16 +548,12 @@ void NativeFileSystemManagerImpl::DidVerifySensitiveDirectoryAccess( ...@@ -566,16 +548,12 @@ void NativeFileSystemManagerImpl::DidVerifySensitiveDirectoryAccess(
return; return;
} }
if (result == SensitiveDirectoryResult::kTryAgain) { if (result == SensitiveDirectoryResult::kTryAgain) {
base::PostTask( ShowFilePickerOnUIThread(
FROM_HERE, {BrowserThread::UI}, binding_context.origin, binding_context.process_id,
base::BindOnce( binding_context.frame_id, options,
&ShowFilePickerOnUIThread, binding_context.origin, base::BindOnce(&NativeFileSystemManagerImpl::DidChooseEntries,
binding_context.process_id, binding_context.frame_id, weak_factory_.GetWeakPtr(), binding_context, options,
/*require_user_gesture=*/false, options, std::move(callback)));
base::BindOnce(&NativeFileSystemManagerImpl::DidChooseEntries,
weak_factory_.GetWeakPtr(), binding_context, options,
std::move(callback)),
base::SequencedTaskRunnerHandle::Get()));
return; return;
} }
...@@ -764,18 +742,4 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl( ...@@ -764,18 +742,4 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl(
url.base_name); url.base_name);
} }
void NativeFileSystemManagerImpl::CreateFileWriterImpl(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state,
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver,
bool has_transient_user_activation) {
writer_receivers_.Add(std::make_unique<NativeFileSystemFileWriterImpl>(
this, binding_context, url, swap_url, handle_state,
has_transient_user_activation),
std::move(writer_receiver));
}
} // namespace content } // namespace content
...@@ -248,15 +248,6 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl ...@@ -248,15 +248,6 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
const base::FilePath& file_path, const base::FilePath& file_path,
NativeFileSystemPermissionContext::UserAction user_action); NativeFileSystemPermissionContext::UserAction user_action);
void CreateFileWriterImpl(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state,
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver,
bool has_transient_user_activation);
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
const scoped_refptr<storage::FileSystemContext> context_; const scoped_refptr<storage::FileSystemContext> context_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment