Commit 2cb0b8ff authored by Olivier Yiptong's avatar Olivier Yiptong Committed by Commit Bot

FontAccess: Move QueueShareMemoryRegionWhenReady to FontEnumerationCache

This change consolidates all QueueShareMemoryRegionWhenReady() overrides
in the base class implementation, because, it turns out, it's the same
code on all platforms.

Bug: 1043306
Change-Id: If26b5e9b5e2361e4e66b21bcfdd2e93484c1a15b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421637
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Auto-Submit: Olivier Yiptong <oyiptong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809468}
parent 28ee59cf
......@@ -4,10 +4,12 @@
#include "content/browser/font_access/font_enumeration_cache.h"
#include "base/feature_list.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/common/features.h"
namespace content {
......@@ -21,6 +23,26 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
}
#endif
void FontEnumerationCache::QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback) {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
callbacks_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&FontEnumerationCache::RunPendingCallback,
// Safe because this is an initialized singleton.
base::Unretained(this),
CallbackOnTaskRunner(std::move(task_runner), std::move(callback))));
if (!enumeration_cache_build_started_.IsSet()) {
enumeration_cache_build_started_.Set();
SchedulePrepareFontEnumerationCache();
}
}
void FontEnumerationCache::ResetStateForTesting() {
callbacks_task_runner_ =
base::MakeRefCounted<base::DeferredSequencedTaskRunner>();
......
......@@ -39,10 +39,9 @@ class CONTENT_EXPORT FontEnumerationCache {
// Enqueue a request to get notified about the availability of the shared
// memory region holding the font enumeration cache.
virtual void QueueShareMemoryRegionWhenReady(
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback
callback) = 0;
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback);
// Returns whether the cache population has completed and the shared memory
// region is ready.
......@@ -51,6 +50,8 @@ class CONTENT_EXPORT FontEnumerationCache {
void ResetStateForTesting();
protected:
virtual void SchedulePrepareFontEnumerationCache() = 0;
// Retrieve the prepared memory region if it is available.
base::ReadOnlySharedMemoryRegion DuplicateMemoryRegion();
......
......@@ -63,26 +63,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get();
}
void FontEnumerationCacheFontconfig::QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback) {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
callbacks_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&FontEnumerationCacheFontconfig::RunPendingCallback,
// Safe because this is an initialized singleton.
base::Unretained(this),
CallbackOnTaskRunner(std::move(task_runner), std::move(callback))));
if (!enumeration_cache_build_started_.IsSet()) {
enumeration_cache_build_started_.Set();
SchedulePrepareFontEnumerationCache();
}
}
bool FontEnumerationCacheFontconfig::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
......@@ -26,20 +26,19 @@ class CONTENT_EXPORT FontEnumerationCacheFontconfig
static FontEnumerationCacheFontconfig* GetInstance();
// FontEnumerationCache methods.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
// FontEnumerationCache interface.
bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private:
friend class base::NoDestructor<FontEnumerationCacheFontconfig>;
// This gives FontEnumerationCache::GetInstance access to the class
// constructor.
friend class FontEnumerationCache;
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache();
DISALLOW_COPY_AND_ASSIGN(FontEnumerationCacheFontconfig);
......
......@@ -31,20 +31,19 @@ class CONTENT_EXPORT FontEnumerationCacheMac : public FontEnumerationCache {
static FontEnumerationCacheMac* GetInstance();
// FontEnumerationCache methods.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
// FontEnumerationCache interface.
bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private:
friend class base::NoDestructor<FontEnumerationCacheMac>;
// This gives FontEnumerationCache::GetInstance access to the class
// constructor.
friend class FontEnumerationCache;
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache();
};
......
......@@ -45,26 +45,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get();
}
void FontEnumerationCacheMac::QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback) {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
callbacks_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&FontEnumerationCacheMac::RunPendingCallback,
// Safe because this is an initialized singleton.
base::Unretained(this),
CallbackOnTaskRunner(std::move(task_runner), std::move(callback))));
if (!enumeration_cache_build_started_.IsSet()) {
enumeration_cache_build_started_.Set();
SchedulePrepareFontEnumerationCache();
}
}
bool FontEnumerationCacheMac::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
......@@ -185,26 +185,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get();
}
void FontEnumerationCacheWin::QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback) {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
callbacks_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&FontEnumerationCacheWin::RunPendingCallback,
// Safe because this is an initialized singleton.
base::Unretained(this),
CallbackOnTaskRunner(std::move(task_runner), std::move(callback))));
if (!enumeration_cache_build_started_.IsSet()) {
enumeration_cache_build_started_.Set();
SchedulePrepareFontEnumerationCache();
}
}
bool FontEnumerationCacheWin::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
......@@ -45,13 +45,13 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache {
};
static FontEnumerationCacheWin* GetInstance();
// FontEnumerationCache methods.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
// FontEnumerationCache interface.
bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private:
friend class base::NoDestructor<FontEnumerationCacheWin>;
// This gives FontEnumerationCache::GetInstance access to the class
......@@ -59,7 +59,6 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache {
friend class FontEnumerationCache;
void InitializeDirectWrite();
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache();
void AppendFontDataAndFinalizeIfNeeded(
std::unique_ptr<FamilyDataResult> family_data_result);
......
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