Commit 1020fc37 authored by Olivier Yiptong's avatar Olivier Yiptong Committed by Commit Bot

FontAccess: Consolidate cache building

This change consolidates the cache building code in the base class:
FontEnumerationCache. Aside from being the right thing to do, this will
allow for easier finalization features e.g. the sorting of fonts before
caching, and any finalization step.

Bug: 1043306
Change-Id: Ie43885a376e3412157799c0e1c2dbcf7576c45f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422456Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809597}
parent 47d6b448
......@@ -93,4 +93,20 @@ bool FontEnumerationCache::IsFontEnumerationCacheValid() const {
enumeration_cache_memory_.mapping.size();
}
void FontEnumerationCache::BuildEnumerationCache(
std::unique_ptr<blink::FontEnumerationTable> table) {
DCHECK(!enumeration_cache_built_.IsSet());
enumeration_cache_memory_ =
base::ReadOnlySharedMemoryRegion::Create(table->ByteSizeLong());
if (!IsFontEnumerationCacheValid() ||
!table->SerializeToArray(enumeration_cache_memory_.mapping.memory(),
enumeration_cache_memory_.mapping.size())) {
enumeration_cache_memory_ = base::MappedReadOnlyRegion();
}
enumeration_cache_built_.Set();
}
} // namespace content
......@@ -74,6 +74,10 @@ class CONTENT_EXPORT FontEnumerationCache {
bool IsFontEnumerationCacheValid() const;
// Build the cache given a properly formed enumeration cache table.
void BuildEnumerationCache(
std::unique_ptr<blink::FontEnumerationTable> table);
base::MappedReadOnlyRegion enumeration_cache_memory_;
base::AtomicFlag enumeration_cache_built_;
base::AtomicFlag enumeration_cache_build_started_;
......
......@@ -144,17 +144,7 @@ void FontEnumerationCacheFontconfig::PrepareFontEnumerationCache() {
"Fonts.AccessAPI.EnumerationCache.Fontconfig.DuplicateFontCount",
dupe_count);
enumeration_cache_memory_ = base::ReadOnlySharedMemoryRegion::Create(
font_enumeration_table->ByteSizeLong());
if (!IsFontEnumerationCacheValid() ||
!font_enumeration_table->SerializeToArray(
enumeration_cache_memory_.mapping.memory(),
enumeration_cache_memory_.mapping.size())) {
enumeration_cache_memory_ = base::MappedReadOnlyRegion();
}
enumeration_cache_built_.Set();
BuildEnumerationCache(std::move(font_enumeration_table));
UMA_HISTOGRAM_MEDIUM_TIMES("Fonts.AccessAPI.EnumerationTime",
start_timer.Elapsed());
......
......@@ -103,17 +103,7 @@ void FontEnumerationCacheMac::PrepareFontEnumerationCache() {
*added_font_meta = metadata;
}
enumeration_cache_memory_ = base::ReadOnlySharedMemoryRegion::Create(
font_enumeration_table->ByteSizeLong());
if (!IsFontEnumerationCacheValid() ||
!font_enumeration_table->SerializeToArray(
enumeration_cache_memory_.mapping.memory(),
enumeration_cache_memory_.mapping.size())) {
enumeration_cache_memory_ = base::MappedReadOnlyRegion();
}
enumeration_cache_built_.Set();
BuildEnumerationCache(std::move(font_enumeration_table));
UMA_HISTOGRAM_MEDIUM_TIMES("Fonts.AccessAPI.EnumerationTime",
start_timer.Elapsed());
......
......@@ -314,17 +314,7 @@ void FontEnumerationCacheWin::FinalizeEnumerationCache() {
// out of scope.
std::unique_ptr<blink::FontEnumerationTable> enumeration_table(
std::move(font_enumeration_table_));
enumeration_cache_memory_ = base::ReadOnlySharedMemoryRegion::Create(
enumeration_table->ByteSizeLong());
if (!IsFontEnumerationCacheValid() ||
!enumeration_table->SerializeToArray(
enumeration_cache_memory_.mapping.memory(),
enumeration_cache_memory_.mapping.size())) {
enumeration_cache_memory_ = base::MappedReadOnlyRegion();
}
enumeration_cache_built_.Set();
BuildEnumerationCache(std::move(enumeration_table));
UMA_HISTOGRAM_MEDIUM_TIMES("Fonts.AccessAPI.EnumerationTime",
enumeration_timer_->Elapsed());
......
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