Commit 27a70557 authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

Quota: Remove direct QuotaManager access from PepperFileSystemBrowserHost.

QuotaManager will move behind a mojo interface. This interface's methods
must all be async, in order to avoid deadlock (storage service ->
browser access may be synch, so browser -> storage service access must
be async). In preparation for this change, only the quota system may
access QuotaManager directly. All other features will use
QuotaManagerProxy, which will only expose async methods.

This CL applies the plan to PepperFileSystemBrowserHost.

Bug: 1168597
Change-Id: I227b0ee9aad87b59a569f469370be4d0903280cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2645492Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846429}
parent d0fdadf3
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/task/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "content/browser/renderer_host/pepper/pepper_file_io_host.h"
#include "content/browser/renderer_host/pepper/quota_reservation.h"
#include "content/common/pepper_file_util.h"
......@@ -209,10 +210,16 @@ void PepperFileSystemBrowserHost::OpenExistingFileSystem(
}
SetFileSystemContext(file_system_context);
if (ShouldCreateQuotaReservation())
CreateQuotaReservation(std::move(callback));
ShouldCreateQuotaReservation(base::BindOnce(
[](base::WeakPtr<PepperFileSystemBrowserHost> host,
base::OnceClosure callback,
bool should_create_quota_reservation) {
if (host && should_create_quota_reservation)
host->CreateQuotaReservation(std::move(callback));
else
std::move(callback).Run();
},
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void PepperFileSystemBrowserHost::OpenFileSystem(
......@@ -246,13 +253,24 @@ void PepperFileSystemBrowserHost::OpenFileSystemComplete(
opened_ = true;
root_url_ = root;
if (ShouldCreateQuotaReservation()) {
CreateQuotaReservation(
base::BindOnce(&PepperFileSystemBrowserHost::SendReplyForFileSystem,
weak_factory_.GetWeakPtr(), reply_context,
static_cast<int32_t>(PP_OK)));
ShouldCreateQuotaReservation(base::BindOnce(
[](base::WeakPtr<PepperFileSystemBrowserHost> host,
ppapi::host::ReplyMessageContext reply_context,
bool should_create_quota_reservation) {
if (!host)
return;
if (should_create_quota_reservation) {
host->CreateQuotaReservation(base::BindOnce(
&PepperFileSystemBrowserHost::SendReplyForFileSystem,
host->weak_factory_.GetWeakPtr(), reply_context,
static_cast<int32_t>(PP_OK)));
} else {
host->SendReplyForFileSystem(reply_context, PP_OK);
}
},
weak_factory_.GetWeakPtr(), reply_context));
return;
}
SendReplyForFileSystem(reply_context, pp_error);
}
......@@ -414,21 +432,29 @@ void PepperFileSystemBrowserHost::SetFileSystemContext(
}
}
bool PepperFileSystemBrowserHost::ShouldCreateQuotaReservation() const {
void PepperFileSystemBrowserHost::ShouldCreateQuotaReservation(
base::OnceCallback<void(bool)> callback) const {
// Some file system types don't have quota.
if (!ppapi::FileSystemTypeHasQuota(type_))
return false;
if (!ppapi::FileSystemTypeHasQuota(type_)) {
std::move(callback).Run(false);
return;
}
// For file system types with quota, some origins have unlimited storage.
storage::QuotaManagerProxy* quota_manager_proxy =
file_system_context_->quota_manager_proxy();
CHECK(quota_manager_proxy);
CHECK(quota_manager_proxy->quota_manager());
storage::FileSystemType file_system_type =
PepperFileSystemTypeToFileSystemType(type_);
return !quota_manager_proxy->quota_manager()->IsStorageUnlimited(
quota_manager_proxy->IsStorageUnlimited(
url::Origin::Create(root_url_),
storage::FileSystemTypeToQuotaStorageType(file_system_type));
storage::FileSystemTypeToQuotaStorageType(file_system_type),
base::SequencedTaskRunnerHandle::Get(),
base::BindOnce(
[](base::OnceCallback<void(bool)> callback, bool is_storage_unlimited) {
std::move(callback).Run(!is_storage_unlimited);
},
std::move(callback)));
}
void PepperFileSystemBrowserHost::CreateQuotaReservation(
......
......@@ -126,7 +126,7 @@ class CONTENT_EXPORT PepperFileSystemBrowserHost
void SetFileSystemContext(
scoped_refptr<storage::FileSystemContext> file_system_context);
bool ShouldCreateQuotaReservation() const;
void ShouldCreateQuotaReservation(base::OnceCallback<void(bool)> callback) const;
void CreateQuotaReservation(base::OnceClosure callback);
void GotQuotaReservation(base::OnceClosure callback,
scoped_refptr<QuotaReservation> quota_reservation);
......
......@@ -203,6 +203,31 @@ void QuotaManagerProxy::GetUsageAndQuota(
std::move(callback)));
}
void QuotaManagerProxy::IsStorageUnlimited(
const url::Origin& origin,
blink::mojom::StorageType type,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(bool)> callback) {
if (!quota_manager_task_runner_->RunsTasksInCurrentSequence()) {
quota_manager_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&QuotaManagerProxy::IsStorageUnlimited, this,
origin, type,
std::move(callback_task_runner), std::move(callback)));
return;
}
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_sequence_checker_);
bool is_storage_unlimited =
quota_manager_ ? quota_manager_->IsStorageUnlimited(origin, type) : false;
if (callback_task_runner->RunsTasksInCurrentSequence()) {
std::move(callback).Run(is_storage_unlimited);
return;
}
callback_task_runner->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), is_storage_unlimited));
}
std::unique_ptr<QuotaOverrideHandle>
QuotaManagerProxy::GetQuotaOverrideHandle() {
return std::make_unique<QuotaOverrideHandle>(this);
......
......@@ -92,6 +92,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerProxy
blink::mojom::StorageType type,
UsageAndQuotaCallback callback);
virtual void IsStorageUnlimited(
const url::Origin& origin,
blink::mojom::StorageType type,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(bool)> callback);
// DevTools Quota Override methods:
std::unique_ptr<QuotaOverrideHandle> GetQuotaOverrideHandle();
// Called by QuotaOverrideHandle upon construction to asynchronously
......
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