Commit 5fac0e42 authored by Daniel Murphy's avatar Daniel Murphy

[SessionStorageS13N] Added sequence checker to LocalStorageCachedAreas

R=pwnall@chromium.org

Bug: 857464
Change-Id: I36d154ddcbafd4592b0fb4e73e201c2ffdcdf197
Reviewed-on: https://chromium-review.googlesource.com/1141062
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575843}
parent 6cbfd306
......@@ -31,10 +31,13 @@ LocalStorageCachedAreas::LocalStorageCachedAreas(
: kTotalCacheLimitInBytes),
main_thread_scheduler_(main_thread_scheduler) {}
LocalStorageCachedAreas::~LocalStorageCachedAreas() {}
LocalStorageCachedAreas::~LocalStorageCachedAreas() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
scoped_refptr<LocalStorageCachedArea> LocalStorageCachedAreas::GetCachedArea(
const url::Origin& origin) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return GetCachedArea(kLocalStorageNamespaceId, origin,
main_thread_scheduler_);
}
......@@ -43,6 +46,7 @@ scoped_refptr<LocalStorageCachedArea>
LocalStorageCachedAreas::GetSessionStorageArea(const std::string& namespace_id,
const url::Origin& origin) {
DCHECK_NE(kLocalStorageNamespaceId, namespace_id);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return GetCachedArea(namespace_id, origin, main_thread_scheduler_);
}
......@@ -52,6 +56,7 @@ void LocalStorageCachedAreas::CloneNamespace(
DCHECK(base::FeatureList::IsEnabled(features::kMojoSessionStorage));
DCHECK_EQ(kSessionStorageNamespaceIdLength, source_namespace.size());
DCHECK_EQ(kSessionStorageNamespaceIdLength, destination_namespace.size());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto namespace_it = cached_namespaces_.find(source_namespace);
if (namespace_it == cached_namespaces_.end()) {
......@@ -68,6 +73,7 @@ void LocalStorageCachedAreas::CloneNamespace(
}
size_t LocalStorageCachedAreas::TotalCacheSize() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
size_t total = 0;
for (const auto& it : cached_namespaces_)
total += it.second.TotalCacheSize();
......@@ -75,6 +81,7 @@ size_t LocalStorageCachedAreas::TotalCacheSize() const {
}
void LocalStorageCachedAreas::ClearAreasIfNeeded() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (TotalCacheSize() < total_cache_limit_)
return;
......@@ -86,6 +93,7 @@ scoped_refptr<LocalStorageCachedArea> LocalStorageCachedAreas::GetCachedArea(
const std::string& namespace_id,
const url::Origin& origin,
blink::scheduler::WebThreadScheduler* scheduler) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class CacheMetrics {
......
......@@ -11,6 +11,7 @@
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/dom_storage/session_storage_namespace.mojom.h"
#include "url/origin.h"
......@@ -53,7 +54,10 @@ class CONTENT_EXPORT LocalStorageCachedAreas {
size_t TotalCacheSize() const;
void set_cache_limit_for_testing(size_t limit) { total_cache_limit_ = limit; }
void set_cache_limit_for_testing(size_t limit) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
total_cache_limit_ = limit;
}
private:
void ClearAreasIfNeeded();
......@@ -63,6 +67,8 @@ class CONTENT_EXPORT LocalStorageCachedAreas {
const url::Origin& origin,
blink::scheduler::WebThreadScheduler* scheduler);
SEQUENCE_CHECKER(sequence_checker_);
blink::mojom::StoragePartitionService* const storage_partition_service_;
struct DOMStorageNamespace {
......
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