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 @@ ...@@ -4,10 +4,12 @@
#include "content/browser/font_access/font_enumeration_cache.h" #include "content/browser/font_access/font_enumeration_cache.h"
#include "base/feature_list.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/common/features.h"
namespace content { namespace content {
...@@ -21,6 +23,26 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() { ...@@ -21,6 +23,26 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
} }
#endif #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() { void FontEnumerationCache::ResetStateForTesting() {
callbacks_task_runner_ = callbacks_task_runner_ =
base::MakeRefCounted<base::DeferredSequencedTaskRunner>(); base::MakeRefCounted<base::DeferredSequencedTaskRunner>();
......
...@@ -39,10 +39,9 @@ class CONTENT_EXPORT FontEnumerationCache { ...@@ -39,10 +39,9 @@ class CONTENT_EXPORT FontEnumerationCache {
// Enqueue a request to get notified about the availability of the shared // Enqueue a request to get notified about the availability of the shared
// memory region holding the font enumeration cache. // memory region holding the font enumeration cache.
virtual void QueueShareMemoryRegionWhenReady( void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner, scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback);
callback) = 0;
// Returns whether the cache population has completed and the shared memory // Returns whether the cache population has completed and the shared memory
// region is ready. // region is ready.
...@@ -51,6 +50,8 @@ class CONTENT_EXPORT FontEnumerationCache { ...@@ -51,6 +50,8 @@ class CONTENT_EXPORT FontEnumerationCache {
void ResetStateForTesting(); void ResetStateForTesting();
protected: protected:
virtual void SchedulePrepareFontEnumerationCache() = 0;
// Retrieve the prepared memory region if it is available. // Retrieve the prepared memory region if it is available.
base::ReadOnlySharedMemoryRegion DuplicateMemoryRegion(); base::ReadOnlySharedMemoryRegion DuplicateMemoryRegion();
......
...@@ -63,26 +63,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() { ...@@ -63,26 +63,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get(); 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() { bool FontEnumerationCacheFontconfig::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess)); DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
...@@ -26,20 +26,19 @@ class CONTENT_EXPORT FontEnumerationCacheFontconfig ...@@ -26,20 +26,19 @@ class CONTENT_EXPORT FontEnumerationCacheFontconfig
static FontEnumerationCacheFontconfig* GetInstance(); static FontEnumerationCacheFontconfig* GetInstance();
// FontEnumerationCache methods. // FontEnumerationCache interface.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
bool IsFontEnumerationCacheReady() override; bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private: private:
friend class base::NoDestructor<FontEnumerationCacheFontconfig>; friend class base::NoDestructor<FontEnumerationCacheFontconfig>;
// This gives FontEnumerationCache::GetInstance access to the class // This gives FontEnumerationCache::GetInstance access to the class
// constructor. // constructor.
friend class FontEnumerationCache; friend class FontEnumerationCache;
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache(); void PrepareFontEnumerationCache();
DISALLOW_COPY_AND_ASSIGN(FontEnumerationCacheFontconfig); DISALLOW_COPY_AND_ASSIGN(FontEnumerationCacheFontconfig);
......
...@@ -31,20 +31,19 @@ class CONTENT_EXPORT FontEnumerationCacheMac : public FontEnumerationCache { ...@@ -31,20 +31,19 @@ class CONTENT_EXPORT FontEnumerationCacheMac : public FontEnumerationCache {
static FontEnumerationCacheMac* GetInstance(); static FontEnumerationCacheMac* GetInstance();
// FontEnumerationCache methods. // FontEnumerationCache interface.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
bool IsFontEnumerationCacheReady() override; bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private: private:
friend class base::NoDestructor<FontEnumerationCacheMac>; friend class base::NoDestructor<FontEnumerationCacheMac>;
// This gives FontEnumerationCache::GetInstance access to the class // This gives FontEnumerationCache::GetInstance access to the class
// constructor. // constructor.
friend class FontEnumerationCache; friend class FontEnumerationCache;
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache(); void PrepareFontEnumerationCache();
}; };
......
...@@ -45,26 +45,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() { ...@@ -45,26 +45,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get(); 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() { bool FontEnumerationCacheMac::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess)); DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
...@@ -185,26 +185,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() { ...@@ -185,26 +185,6 @@ FontEnumerationCache* FontEnumerationCache::GetInstance() {
return instance.get(); 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() { bool FontEnumerationCacheWin::IsFontEnumerationCacheReady() {
DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess)); DCHECK(base::FeatureList::IsEnabled(blink::features::kFontAccess));
......
...@@ -45,13 +45,13 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache { ...@@ -45,13 +45,13 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache {
}; };
static FontEnumerationCacheWin* GetInstance(); static FontEnumerationCacheWin* GetInstance();
// FontEnumerationCache methods. // FontEnumerationCache interface.
void QueueShareMemoryRegionWhenReady(
scoped_refptr<base::TaskRunner> task_runner,
blink::mojom::FontAccessManager::EnumerateLocalFontsCallback callback)
override;
bool IsFontEnumerationCacheReady() override; bool IsFontEnumerationCacheReady() override;
protected:
// FontEnumerationCache interface.
void SchedulePrepareFontEnumerationCache() override;
private: private:
friend class base::NoDestructor<FontEnumerationCacheWin>; friend class base::NoDestructor<FontEnumerationCacheWin>;
// This gives FontEnumerationCache::GetInstance access to the class // This gives FontEnumerationCache::GetInstance access to the class
...@@ -59,7 +59,6 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache { ...@@ -59,7 +59,6 @@ class CONTENT_EXPORT FontEnumerationCacheWin : public FontEnumerationCache {
friend class FontEnumerationCache; friend class FontEnumerationCache;
void InitializeDirectWrite(); void InitializeDirectWrite();
void SchedulePrepareFontEnumerationCache();
void PrepareFontEnumerationCache(); void PrepareFontEnumerationCache();
void AppendFontDataAndFinalizeIfNeeded( void AppendFontDataAndFinalizeIfNeeded(
std::unique_ptr<FamilyDataResult> family_data_result); 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