Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a QuotaManager observer interface which can be implemented to listen for quota manager changes. Currently only listens for buckets being created, updated, or deleted. A mojom version of the interface has also been added for observers that exist on separate sequences/processes. Bug: 1406017 Change-Id: I4d36c74b0be890aa1257ec0127da7b6a603d92e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4193281 Reviewed-by: Will Harris <wfh@chromium.org> Reviewed-by: Evan Stade <estade@chromium.org> Commit-Queue: Nathan Memmott <memmott@chromium.org> Reviewed-by: Ayu Ishii <ayui@chromium.org> Cr-Commit-Position: refs/heads/main@{#1117829}
- Loading branch information
Nathan Memmott
authored and
Chromium LUCI CQ
committed
Mar 15, 2023
1 parent
87362ae
commit 65cacb7
Showing
19 changed files
with
552 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
components/services/storage/public/mojom/buckets/bucket_info.mojom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
module storage.mojom; | ||
|
||
import "mojo/public/mojom/base/time.mojom"; | ||
import "third_party/blink/public/mojom/storage_key/storage_key.mojom"; | ||
import "third_party/blink/public/mojom/quota/quota_types.mojom"; | ||
|
||
// Snapshot of a bucket's information in the quota database. | ||
// | ||
// Properties that can be updated by the Storage Buckets API, like | ||
// `expiration` and `quota`, may get out of sync with the database. The | ||
// database is the source of truth. | ||
struct BucketInfo { | ||
int64 id; | ||
blink.mojom.StorageKey storage_key; | ||
blink.mojom.StorageType type; | ||
string name; | ||
mojo_base.mojom.Time expiration; | ||
uint64 quota; | ||
bool persistent; | ||
blink.mojom.BucketDurability durability; | ||
}; |
33 changes: 33 additions & 0 deletions
33
components/services/storage/public/mojom/buckets/bucket_info_mojom_traits.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/services/storage/public/mojom/buckets/bucket_info_mojom_traits.h" | ||
|
||
#include "third_party/blink/public/common/storage_key/storage_key_mojom_traits.h" | ||
|
||
namespace mojo { | ||
|
||
// static | ||
bool StructTraits<storage::mojom::BucketInfoDataView, storage::BucketInfo>:: | ||
Read(storage::mojom::BucketInfoDataView data, storage::BucketInfo* out) { | ||
blink::StorageKey storage_key; | ||
if (!data.ReadStorageKey(&storage_key)) { | ||
return false; | ||
} | ||
std::string name; | ||
if (!data.ReadName(&name)) { | ||
return false; | ||
} | ||
base::Time expiration; | ||
if (!data.ReadExpiration(&expiration)) { | ||
return false; | ||
} | ||
|
||
*out = storage::BucketInfo(storage::BucketId(data.id()), storage_key, | ||
data.type(), name, expiration, data.quota(), | ||
data.persistent(), data.durability()); | ||
return true; | ||
} | ||
|
||
} // namespace mojo |
50 changes: 50 additions & 0 deletions
50
components/services/storage/public/mojom/buckets/bucket_info_mojom_traits.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_SERVICES_STORAGE_PUBLIC_MOJOM_BUCKETS_BUCKET_INFO_MOJOM_TRAITS_H_ | ||
#define COMPONENTS_SERVICES_STORAGE_PUBLIC_MOJOM_BUCKETS_BUCKET_INFO_MOJOM_TRAITS_H_ | ||
|
||
#include "components/services/storage/public/cpp/buckets/bucket_info.h" | ||
#include "components/services/storage/public/mojom/buckets/bucket_info.mojom-shared.h" | ||
#include "mojo/public/cpp/bindings/struct_traits.h" | ||
|
||
namespace mojo { | ||
|
||
template <> | ||
class StructTraits<storage::mojom::BucketInfoDataView, storage::BucketInfo> { | ||
public: | ||
static int64_t id(const storage::BucketInfo& bucket) { | ||
return bucket.id.value(); | ||
} | ||
static const blink::StorageKey& storage_key( | ||
const storage::BucketInfo& bucket) { | ||
return bucket.storage_key; | ||
} | ||
static blink::mojom::StorageType type(const storage::BucketInfo& bucket) { | ||
return bucket.type; | ||
} | ||
static base::StringPiece name(const storage::BucketInfo& bucket) { | ||
return base::StringPiece(bucket.name.c_str(), bucket.name.length()); | ||
} | ||
static const base::Time& expiration(const storage::BucketInfo& bucket) { | ||
return bucket.expiration; | ||
} | ||
static uint64_t quota(const storage::BucketInfo& bucket) { | ||
return bucket.quota; | ||
} | ||
static bool persistent(const storage::BucketInfo& bucket) { | ||
return bucket.persistent; | ||
} | ||
static blink::mojom::BucketDurability durability( | ||
const storage::BucketInfo& bucket) { | ||
return bucket.durability; | ||
} | ||
|
||
static bool Read(storage::mojom::BucketInfoDataView data, | ||
storage::BucketInfo* out); | ||
}; | ||
|
||
} // namespace mojo | ||
|
||
#endif // COMPONENTS_SERVICES_STORAGE_PUBLIC_MOJOM_BUCKETS_BUCKET_INFO_MOJOM_TRAITS_H_ |
48 changes: 48 additions & 0 deletions
48
components/services/storage/public/mojom/buckets/bucket_info_mojom_traits_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/services/storage/public/mojom/buckets/bucket_info_mojom_traits.h" | ||
|
||
#include "components/services/storage/public/cpp/buckets/bucket_id.h" | ||
#include "components/services/storage/public/cpp/buckets/bucket_info.h" | ||
#include "components/services/storage/public/cpp/buckets/constants.h" | ||
#include "components/services/storage/public/mojom/buckets/bucket_info.mojom.h" | ||
#include "mojo/public/cpp/test_support/test_utils.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/blink/public/common/storage_key/storage_key.h" | ||
|
||
namespace storage { | ||
namespace { | ||
|
||
TEST(BucketInfoMojomTraitsTest, SerializeAndDeserialize) { | ||
BucketInfo test_keys[] = { | ||
BucketInfo( | ||
BucketId(1), | ||
blink::StorageKey::CreateFromStringForTesting("http://example/"), | ||
blink::mojom::StorageType::kTemporary, "default", base::Time(), 0, | ||
true, blink::mojom::BucketDurability::kRelaxed), | ||
BucketInfo( | ||
BucketId(123), | ||
blink::StorageKey::CreateFromStringForTesting("http://google.com/"), | ||
blink::mojom::StorageType::kTemporary, "inbox", | ||
base::Time::Now() + base::Days(1), 100, true, | ||
blink::mojom::BucketDurability::kStrict), | ||
BucketInfo( | ||
BucketId(1000), | ||
blink::StorageKey::CreateFromStringForTesting("http://test.com/"), | ||
blink::mojom::StorageType::kTemporary, "drafts", | ||
base::Time::Now() - base::Days(1), 1234, false, | ||
blink::mojom::BucketDurability::kStrict), | ||
}; | ||
|
||
for (auto& original : test_keys) { | ||
BucketInfo copied; | ||
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<mojom::BucketInfo>(original, | ||
copied)); | ||
EXPECT_EQ(original, copied); | ||
} | ||
} | ||
|
||
} // namespace | ||
} // namespace storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.