Commit bb2045cf authored by Richard Stotz's avatar Richard Stotz Committed by Commit Bot

NativeIO: Minimal quota plumbing.

This CL adds a non-functional QuotaClient to NativeIO and attaches it to
NativeIOContext.

Bug: 1137788
Change-Id: If61bbcc08df6b2c5179882f7aa8b9f5b1a0645bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467899Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Richard Stotz <rstz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827746}
parent 7336b16e
...@@ -1136,6 +1136,8 @@ source_set("browser") { ...@@ -1136,6 +1136,8 @@ source_set("browser") {
"native_io/native_io_file_host.h", "native_io/native_io_file_host.h",
"native_io/native_io_host.cc", "native_io/native_io_host.cc",
"native_io/native_io_host.h", "native_io/native_io_host.h",
"native_io/native_io_quota_client.cc",
"native_io/native_io_quota_client.h",
"navigation_subresource_loader_params.cc", "navigation_subresource_loader_params.cc",
"navigation_subresource_loader_params.h", "navigation_subresource_loader_params.h",
"net/browser_online_state_observer.cc", "net/browser_online_state_observer.cc",
......
...@@ -9,8 +9,12 @@ ...@@ -9,8 +9,12 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "content/browser/native_io/native_io_host.h" #include "content/browser/native_io/native_io_host.h"
#include "content/browser/native_io/native_io_quota_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h" #include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "storage/browser/quota/quota_client_type.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "storage/common/database/database_identifier.h" #include "storage/common/database/database_identifier.h"
#include "third_party/blink/public/mojom/native_io/native_io.mojom.h" #include "third_party/blink/public/mojom/native_io/native_io.mojom.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -31,8 +35,19 @@ base::FilePath GetNativeIORootPath(const base::FilePath& profile_root) { ...@@ -31,8 +35,19 @@ base::FilePath GetNativeIORootPath(const base::FilePath& profile_root) {
} // namespace } // namespace
NativeIOContext::NativeIOContext(const base::FilePath& profile_root) NativeIOContext::NativeIOContext(
: root_path_(GetNativeIORootPath(profile_root)) {} const base::FilePath& profile_root,
storage::SpecialStoragePolicy* special_storage_policy,
storage::QuotaManagerProxy* quota_manager_proxy)
: root_path_(GetNativeIORootPath(profile_root)),
special_storage_policy_(special_storage_policy) {
if (quota_manager_proxy) {
quota_manager_proxy->RegisterClient(
base::MakeRefCounted<NativeIOQuotaClient>(),
storage::QuotaClientType::kNativeIO,
{blink::mojom::StorageType::kTemporary});
}
}
NativeIOContext::~NativeIOContext() { NativeIOContext::~NativeIOContext() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_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" #include "third_party/blink/public/mojom/native_io/native_io.mojom-forward.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -32,7 +34,10 @@ class CONTENT_EXPORT NativeIOContext { ...@@ -32,7 +34,10 @@ class CONTENT_EXPORT NativeIOContext {
// |profile_root| is empty for in-memory (Incognito) profiles. Otherwise, // |profile_root| is empty for in-memory (Incognito) profiles. Otherwise,
// |profile_root| must point to an existing directory. NativeIO will store its // |profile_root| must point to an existing directory. NativeIO will store its
// data in a subdirectory of the profile root. // data in a subdirectory of the profile root.
explicit NativeIOContext(const base::FilePath& profile_root); explicit NativeIOContext(
const base::FilePath& profile_root,
storage::SpecialStoragePolicy* special_storage_policy,
storage::QuotaManagerProxy* quota_manager_proxy);
~NativeIOContext(); ~NativeIOContext();
...@@ -50,7 +55,6 @@ class CONTENT_EXPORT NativeIOContext { ...@@ -50,7 +55,6 @@ class CONTENT_EXPORT NativeIOContext {
// |host| must be owned by this context. This method should only be called by // |host| must be owned by this context. This method should only be called by
// NativeIOHost. // NativeIOHost.
void OnHostReceiverDisconnect(NativeIOHost* host); void OnHostReceiverDisconnect(NativeIOHost* host);
private: private:
// Computes the path to the directory storing an origin's NativeIO files. // Computes the path to the directory storing an origin's NativeIO files.
// //
...@@ -64,6 +68,8 @@ class CONTENT_EXPORT NativeIOContext { ...@@ -64,6 +68,8 @@ class CONTENT_EXPORT NativeIOContext {
// This path is empty for in-memory (Incognito) profiles. // This path is empty for in-memory (Incognito) profiles.
const base::FilePath root_path_; const base::FilePath root_path_;
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
}; };
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/cpp/test_support/test_utils.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/native_io/native_io.mojom.h" #include "third_party/blink/public/mojom/native_io/native_io.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -139,7 +142,15 @@ class NativeIOContextTest : public testing::Test { ...@@ -139,7 +142,15 @@ class NativeIOContextTest : public testing::Test {
public: public:
void SetUp() override { void SetUp() override {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
context_ = std::make_unique<NativeIOContext>(data_dir_.GetPath()); quota_manager_ = base::MakeRefCounted<storage::MockQuotaManager>(
/*is_incognito=*/false, data_dir_.GetPath(),
base::ThreadTaskRunnerHandle::Get().get(),
/*special storage policy=*/nullptr);
quota_manager_proxy_ = base::MakeRefCounted<storage::MockQuotaManagerProxy>(
quota_manager(), base::ThreadTaskRunnerHandle::Get().get());
context_ = std::make_unique<NativeIOContext>(
data_dir_.GetPath(),
/*special storage policy=*/nullptr, quota_manager_proxy());
context_->BindReceiver(url::Origin::Create(GURL(kExampleOrigin)), context_->BindReceiver(url::Origin::Create(GURL(kExampleOrigin)),
example_host_remote_.BindNewPipeAndPassReceiver()); example_host_remote_.BindNewPipeAndPassReceiver());
...@@ -152,7 +163,23 @@ class NativeIOContextTest : public testing::Test { ...@@ -152,7 +163,23 @@ class NativeIOContextTest : public testing::Test {
std::move(google_host_remote_.get())); std::move(google_host_remote_.get()));
} }
void TearDown() override {
// Let the client go away before dropping a ref of the quota manager proxy.
quota_manager_proxy()->SimulateQuotaManagerDestroyed();
quota_manager_ = nullptr;
quota_manager_proxy_ = nullptr;
}
protected: protected:
storage::MockQuotaManager* quota_manager() {
return static_cast<storage::MockQuotaManager*>(quota_manager_.get());
}
storage::MockQuotaManagerProxy* quota_manager_proxy() {
return static_cast<storage::MockQuotaManagerProxy*>(
quota_manager_proxy_.get());
}
// This must be above NativeIOContext, to ensure that no file is accessed when // This must be above NativeIOContext, to ensure that no file is accessed when
// the temporary directory is deleted. // the temporary directory is deleted.
base::ScopedTempDir data_dir_; base::ScopedTempDir data_dir_;
...@@ -178,6 +205,10 @@ class NativeIOContextTest : public testing::Test { ...@@ -178,6 +205,10 @@ class NativeIOContextTest : public testing::Test {
"has.dot", "has.dot",
"has/slash", "has/slash",
}; };
private:
scoped_refptr<storage::QuotaManager> quota_manager_;
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
}; };
TEST_F(NativeIOContextTest, OpenFile_BadNames) { TEST_F(NativeIOContextTest, OpenFile_BadNames) {
......
// Copyright 2020 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/browser/native_io/native_io_quota_client.h"
#include "content/public/browser/browser_thread.h"
#include "url/origin.h"
namespace content {
NativeIOQuotaClient::NativeIOQuotaClient() = default;
NativeIOQuotaClient::~NativeIOQuotaClient() = default;
void NativeIOQuotaClient::OnQuotaManagerDestroyed() {}
void NativeIOQuotaClient::GetOriginUsage(const url::Origin& origin,
blink::mojom::StorageType type,
GetOriginUsageCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
// TODO(crbug.com/1137788): Implement quota accounting.
std::move(callback).Run(0);
return;
}
void NativeIOQuotaClient::GetOriginsForType(
blink::mojom::StorageType type,
GetOriginsForTypeCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
std::vector<url::Origin> origins;
// TODO(crbug.com/1137788): Implement quota accounting.
std::move(callback).Run(std::move(origins));
}
void NativeIOQuotaClient::GetOriginsForHost(
blink::mojom::StorageType type,
const std::string& host,
GetOriginsForHostCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
std::vector<url::Origin> origins;
// TODO(crbug.com/1137788): Implement quota accounting.
std::move(callback).Run(std::move(origins));
}
void NativeIOQuotaClient::DeleteOriginData(const url::Origin& origin,
blink::mojom::StorageType type,
DeleteOriginDataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
// TODO(crbug.com/1137788): Implement quota accounting.
std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk);
}
void NativeIOQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
// TODO(crbug.com/1137788): Implement quota accounting.
std::move(callback).Run();
}
} // namespace content
// Copyright 2020 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_BROWSER_NATIVE_IO_NATIVE_IO_QUOTA_CLIENT_H_
#define CONTENT_BROWSER_NATIVE_IO_NATIVE_IO_QUOTA_CLIENT_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/native_io/native_io_quota_client.h"
#include "content/common/content_export.h"
#include "storage/browser/quota/quota_client.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "url/origin.h"
namespace content {
class NativeIOContext;
enum class NativeIOOwner;
// NativeIOQuotaClient is owned by the QuotaManager. There is one per
// NativeIOContext/NativeIOOwner tuple. Created and accessed on
// the IO thread.
class CONTENT_EXPORT NativeIOQuotaClient : public storage::QuotaClient {
public:
NativeIOQuotaClient();
// QuotaClient.
void OnQuotaManagerDestroyed() override;
void GetOriginUsage(const url::Origin& origin,
blink::mojom::StorageType type,
GetOriginUsageCallback callback) override;
void GetOriginsForType(blink::mojom::StorageType type,
GetOriginsForTypeCallback callback) override;
void GetOriginsForHost(blink::mojom::StorageType type,
const std::string& host,
GetOriginsForHostCallback callback) override;
void DeleteOriginData(
const url::Origin& origin,
blink::mojom::StorageType type,
storage::QuotaClient::DeleteOriginDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
static storage::QuotaClientType GetClientTypeFromOwner(NativeIOOwner owner);
private:
~NativeIOQuotaClient() override;
DISALLOW_COPY_AND_ASSIGN(NativeIOQuotaClient);
};
} // namespace content
#endif // CONTENT_BROWSER_NATIVE_IO_NATIVE_IO_QUOTA_CLIENT_H_
...@@ -798,8 +798,13 @@ storage::QuotaClientTypes StoragePartitionImpl::GenerateQuotaClientTypes( ...@@ -798,8 +798,13 @@ storage::QuotaClientTypes StoragePartitionImpl::GenerateQuotaClientTypes(
uint32_t remove_mask) { uint32_t remove_mask) {
storage::QuotaClientTypes quota_client_types; storage::QuotaClientTypes quota_client_types;
if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) {
quota_client_types.insert(storage::QuotaClientType::kFileSystem); quota_client_types.insert(storage::QuotaClientType::kFileSystem);
// TODO(crbug.com/1137788): Add a removal mask for NativeIO after adopting a
// more inclusive name.
quota_client_types.insert(storage::QuotaClientType::kNativeIO);
}
if (remove_mask & StoragePartition::REMOVE_DATA_MASK_WEBSQL) if (remove_mask & StoragePartition::REMOVE_DATA_MASK_WEBSQL)
quota_client_types.insert(storage::QuotaClientType::kDatabase); quota_client_types.insert(storage::QuotaClientType::kDatabase);
if (remove_mask & StoragePartition::REMOVE_DATA_MASK_APPCACHE) if (remove_mask & StoragePartition::REMOVE_DATA_MASK_APPCACHE)
...@@ -812,7 +817,6 @@ storage::QuotaClientTypes StoragePartitionImpl::GenerateQuotaClientTypes( ...@@ -812,7 +817,6 @@ storage::QuotaClientTypes StoragePartitionImpl::GenerateQuotaClientTypes(
quota_client_types.insert(storage::QuotaClientType::kServiceWorkerCache); quota_client_types.insert(storage::QuotaClientType::kServiceWorkerCache);
if (remove_mask & StoragePartition::REMOVE_DATA_MASK_BACKGROUND_FETCH) if (remove_mask & StoragePartition::REMOVE_DATA_MASK_BACKGROUND_FETCH)
quota_client_types.insert(storage::QuotaClientType::kBackgroundFetch); quota_client_types.insert(storage::QuotaClientType::kBackgroundFetch);
return quota_client_types; return quota_client_types;
} }
...@@ -1225,7 +1229,9 @@ void StoragePartitionImpl::Initialize( ...@@ -1225,7 +1229,9 @@ void StoragePartitionImpl::Initialize(
} }
dedicated_worker_service_ = std::make_unique<DedicatedWorkerServiceImpl>(); dedicated_worker_service_ = std::make_unique<DedicatedWorkerServiceImpl>();
native_io_context_ = std::make_unique<NativeIOContext>(path); native_io_context_ = std::make_unique<NativeIOContext>(
path, browser_context_->GetSpecialStoragePolicy(),
quota_manager_proxy.get());
shared_worker_service_ = std::make_unique<SharedWorkerServiceImpl>( shared_worker_service_ = std::make_unique<SharedWorkerServiceImpl>(
this, service_worker_context_, appcache_service_); this, service_worker_context_, appcache_service_);
......
...@@ -853,9 +853,11 @@ TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { ...@@ -853,9 +853,11 @@ TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
} }
TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) { TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) {
EXPECT_THAT(StoragePartitionImpl::GenerateQuotaClientTypes( EXPECT_THAT(
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS), StoragePartitionImpl::GenerateQuotaClientTypes(
testing::ElementsAre(storage::QuotaClientType::kFileSystem)); StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS),
testing::UnorderedElementsAre(storage::QuotaClientType::kFileSystem,
storage::QuotaClientType::kNativeIO));
EXPECT_THAT(StoragePartitionImpl::GenerateQuotaClientTypes( EXPECT_THAT(StoragePartitionImpl::GenerateQuotaClientTypes(
StoragePartition::REMOVE_DATA_MASK_WEBSQL), StoragePartition::REMOVE_DATA_MASK_WEBSQL),
testing::ElementsAre(storage::QuotaClientType::kDatabase)); testing::ElementsAre(storage::QuotaClientType::kDatabase));
...@@ -867,11 +869,11 @@ TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) { ...@@ -867,11 +869,11 @@ TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) {
testing::ElementsAre(storage::QuotaClientType::kIndexedDatabase)); testing::ElementsAre(storage::QuotaClientType::kIndexedDatabase));
EXPECT_THAT( EXPECT_THAT(
StoragePartitionImpl::GenerateQuotaClientTypes(kAllQuotaRemoveMask), StoragePartitionImpl::GenerateQuotaClientTypes(kAllQuotaRemoveMask),
testing::UnorderedElementsAre( testing::UnorderedElementsAre(storage::QuotaClientType::kFileSystem,
storage::QuotaClientType::kFileSystem, storage::QuotaClientType::kDatabase,
storage::QuotaClientType::kDatabase, storage::QuotaClientType::kAppcache,
storage::QuotaClientType::kAppcache, storage::QuotaClientType::kIndexedDatabase,
storage::QuotaClientType::kIndexedDatabase)); storage::QuotaClientType::kNativeIO));
} }
void PopulateTestQuotaManagedPersistentData(storage::MockQuotaManager* manager, void PopulateTestQuotaManagedPersistentData(storage::MockQuotaManager* manager,
......
...@@ -17,6 +17,7 @@ const QuotaClientTypes& AllQuotaClientTypes() { ...@@ -17,6 +17,7 @@ const QuotaClientTypes& AllQuotaClientTypes() {
QuotaClientType::kServiceWorkerCache, QuotaClientType::kServiceWorkerCache,
QuotaClientType::kServiceWorker, QuotaClientType::kServiceWorker,
QuotaClientType::kBackgroundFetch, QuotaClientType::kBackgroundFetch,
QuotaClientType::kNativeIO,
}}; }};
return *all; return *all;
} }
......
...@@ -22,6 +22,7 @@ enum class QuotaClientType { ...@@ -22,6 +22,7 @@ enum class QuotaClientType {
kServiceWorker = 5, kServiceWorker = 5,
kBackgroundFetch = 6, kBackgroundFetch = 6,
kAppcache = 7, kAppcache = 7,
kNativeIO = 8,
}; };
// Set of QuotaClientType values. // Set of QuotaClientType values.
......
...@@ -235,6 +235,9 @@ void UsageTracker::AccumulateClientHostUsage(base::OnceClosure callback, ...@@ -235,6 +235,9 @@ void UsageTracker::AccumulateClientHostUsage(base::OnceClosure callback,
case QuotaClientType::kBackgroundFetch: case QuotaClientType::kBackgroundFetch:
info->usage_breakdown->backgroundFetch += usage; info->usage_breakdown->backgroundFetch += usage;
break; break;
case QuotaClientType::kNativeIO:
info->usage_breakdown->nativeIO += usage;
break;
} }
std::move(callback).Run(); std::move(callback).Run();
......
...@@ -32,4 +32,5 @@ struct UsageBreakdown { ...@@ -32,4 +32,5 @@ struct UsageBreakdown {
int64 serviceWorkerCache = 0; int64 serviceWorkerCache = 0;
int64 serviceWorker = 0; int64 serviceWorker = 0;
int64 backgroundFetch = 0; int64 backgroundFetch = 0;
int64 nativeIO = 0;
}; };
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