Commit dd4ba9e0 authored by Brandon Maslen's avatar Brandon Maslen Committed by Commit Bot

Add GetStoragePartitionCount to BrowserContext

During another change/need to iterate over all storage
partitions it was noticed that other places in Chromium
have the same requirement. This change exposts a
GetStoragePartitionCount method off of

having to iterate over the collection of partitions to
achieve the same result. In addition the existing call
site of this method has been updated to call the
BrowserContext version.

content: :BrowserContext in order to avoid other classes
Change-Id: Ie60b726841f6955f7df5128cbe89955ea0e3a98d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2057808
Commit-Queue: Brandon Maslen <brandm@microsoft.com>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742810}
parent cb395349
......@@ -27,27 +27,6 @@ namespace {
base::LazyInstance<BackgroundSyncLauncher>::DestructorAtExit
g_background_sync_launcher = LAZY_INSTANCE_INITIALIZER;
unsigned int GetStoragePartitionCount(BrowserContext* browser_context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(browser_context);
int num_partitions = 0;
BrowserContext::ForEachStoragePartition(
browser_context,
base::BindRepeating(
[](int* num_partitions, StoragePartition* storage_partition) {
(*num_partitions)++;
},
&num_partitions));
// It's valid for a profile to not have any storage partitions. This DCHECK
// is to ensure that we're not waking up Chrome for no reason, because that's
// expensive and unnecessary.
DCHECK(num_partitions);
return num_partitions;
}
} // namespace
// static
......@@ -89,7 +68,7 @@ void BackgroundSyncLauncher::FireBackgroundSyncEventsImpl(
if (sync_type == blink::mojom::BackgroundSyncType::PERIODIC)
last_browser_wakeup_for_periodic_sync_ = base::Time::Now();
base::RepeatingClosure done_closure = base::BarrierClosure(
GetStoragePartitionCount(browser_context),
content::BrowserContext::GetStoragePartitionCount(browser_context),
base::BindOnce(base::android::RunRunnableAndroid,
base::android::ScopedJavaGlobalRef<jobject>(j_runnable)));
......@@ -138,7 +117,7 @@ void BackgroundSyncLauncher::GetSoonestWakeupDeltaImpl(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::RepeatingClosure done_closure = base::BarrierClosure(
GetStoragePartitionCount(browser_context),
content::BrowserContext::GetStoragePartitionCount(browser_context),
base::BindOnce(&BackgroundSyncLauncher::SendSoonestWakeupDelta,
base::Unretained(this), sync_type, std::move(callback)));
......
......@@ -355,6 +355,14 @@ void BrowserContext::ForEachStoragePartition(
partition_map->ForEach(std::move(callback));
}
size_t BrowserContext::GetStoragePartitionCount(
BrowserContext* browser_context) {
StoragePartitionImplMap* partition_map =
static_cast<StoragePartitionImplMap*>(
browser_context->GetUserData(kStoragePartitionMapKeyName));
return partition_map ? partition_map->size() : 0;
}
StoragePartition* BrowserContext::GetDefaultStoragePartition(
BrowserContext* browser_context) {
return GetStoragePartition(browser_context, nullptr);
......
......@@ -62,6 +62,8 @@ class CONTENT_EXPORT StoragePartitionImplMap
void ForEach(BrowserContext::StoragePartitionCallback callback);
size_t size() const { return partitions_.size(); }
private:
FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplMapTest, GarbageCollect);
......
......@@ -139,6 +139,9 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
base::RepeatingCallback<void(StoragePartition*)>;
static void ForEachStoragePartition(BrowserContext* browser_context,
StoragePartitionCallback callback);
// Returns the number of StoragePartitions that exist for the given
// |browser_context|.
static size_t GetStoragePartitionCount(BrowserContext* browser_context);
static void AsyncObliterateStoragePartition(
BrowserContext* browser_context,
const std::string& partition_domain,
......
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