Commit 74ee0178 authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

NativeIO: NativeIOManager owns NativeIOQuotaClient.

This CL takes advantage of the fact that NativeIOQuotaClient is now
mojofied and no longer ref-counted, and simpifies NativeIO's ownership
graph.

Bug: 1016065
Change-Id: I6eb6fa259111101e95459b5c0655261b0d7e43d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644638Reviewed-by: default avatarJarryd Goodman <jarrydg@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846323}
parent 2499f4b5
......@@ -36,14 +36,13 @@ NativeIOManager::NativeIOManager(
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy)
: root_path_(GetNativeIORootPath(profile_root)),
special_storage_policy_(std::move(special_storage_policy)),
quota_manager_proxy_(std::move(quota_manager_proxy)) {
if (quota_manager_proxy) {
quota_manager_proxy_(std::move(quota_manager_proxy)),
quota_client_receiver_(&quota_client_) {
if (quota_manager_proxy_) {
// Quota client assumes all backends have registered.
mojo::PendingRemote<storage::mojom::QuotaClient> quota_client;
mojo::MakeSelfOwnedReceiver(std::make_unique<NativeIOQuotaClient>(),
quota_client.InitWithNewPipeAndPassReceiver());
quota_manager_proxy->RegisterClient(
std::move(quota_client), storage::QuotaClientType::kNativeIO,
quota_manager_proxy_->RegisterClient(
quota_client_receiver_.BindNewPipeAndPassRemote(),
storage::QuotaClientType::kNativeIO,
{blink::mojom::StorageType::kTemporary});
}
}
......
......@@ -11,8 +11,11 @@
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/sequence_checker.h"
#include "components/services/storage/public/mojom/quota_client.mojom-forward.h"
#include "content/browser/native_io/native_io_quota_client.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "third_party/blink/public/mojom/native_io/native_io.mojom-forward.h"
......@@ -72,6 +75,8 @@ class CONTENT_EXPORT NativeIOManager {
std::string message = "");
private:
SEQUENCE_CHECKER(sequence_checker_);
std::map<url::Origin, std::unique_ptr<NativeIOHost>> hosts_;
// Points to the root directory for NativeIO files.
......@@ -84,7 +89,14 @@ class CONTENT_EXPORT NativeIOManager {
const scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
SEQUENCE_CHECKER(sequence_checker_);
NativeIOQuotaClient quota_client_;
// Once the QuotaClient receiver is destroyed, the underlying mojo connection
// is closed. Callbacks associated with mojo calls received over this
// connection may only be dropped after the connection is closed. For this
// reason, it's preferable to have the receiver be destroyed as early as
// possible during the NativeIOManager destruction process.
mojo::Receiver<storage::mojom::QuotaClient> quota_client_receiver_;
};
} // namespace content
......
......@@ -177,6 +177,8 @@ class NativeIOManagerTest : public testing::Test {
}
void TearDown() override {
quota_manager_proxy()->SimulateQuotaManagerDestroyed();
// Let the client go away before dropping a ref of the quota manager proxy.
quota_manager_ = nullptr;
quota_manager_proxy_ = nullptr;
......
......@@ -10,10 +10,7 @@
namespace content {
NativeIOQuotaClient::NativeIOQuotaClient() {
// Constructed on the UI thread and used on the IO thread.
DETACH_FROM_SEQUENCE(sequence_checker_);
}
NativeIOQuotaClient::NativeIOQuotaClient() = default;
NativeIOQuotaClient::~NativeIOQuotaClient() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -15,11 +15,10 @@
namespace content {
class NativeIOManager;
enum class NativeIOOwner;
// NativeIOQuotaClient is owned by the QuotaManager. There is one per
// NativeIOManager/NativeIOOwner tuple. Created and accessed on
// the IO thread.
// Integrates NativeIO with the quota system.
//
// Each NativeIOManager owns exactly one NativeIOQuotaClient.
class CONTENT_EXPORT NativeIOQuotaClient : public storage::mojom::QuotaClient {
public:
NativeIOQuotaClient();
......
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