From ff8f4a7217189645a98b8affc45641cafe232f73 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 19 May 2021 17:34:06 -0400 Subject: [PATCH] Remove the TID_FILE default value Clients should instead make an informed decision about which blocking thread to use. See cef_thread_id_t documentation for guidance. --- include/cef_api_hash.h | 8 ++++---- include/internal/cef_types.h | 1 - include/wrapper/cef_helpers.h | 15 ++++++++++++--- libcef_dll/wrapper/cef_resource_manager.cc | 16 +++++++++------- tests/cefclient/browser/image_cache.cc | 6 +++--- tests/shared/browser/extension_util.cc | 6 +++--- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index dd7676577..ef01ff5b9 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "d026196d35d8894a836ab3a3d033b84195cdb835" +#define CEF_API_HASH_UNIVERSAL "b2f96ef79b0a316e88dae7c885675ab4e012a1fd" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "4150bd26e7bf639a9b1f3e5860af8c76eeae8570" +#define CEF_API_HASH_PLATFORM "a6f28bd2c6d7248655ede7f2ad0eb01c3b53bbb5" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "5cc32f88bd134410eff86b21095138b339d572f2" +#define CEF_API_HASH_PLATFORM "3398ee95844446efa42cc366fb08c37f739b7fbd" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "b227b3fdd6142a9d8ff0f2252a71425f15960800" +#define CEF_API_HASH_PLATFORM "00a4ab72830b926411b311f5985e31e8146cedba" #endif #ifdef __cplusplus diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 0ec9fcb5c..b66a71fcc 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -1458,7 +1458,6 @@ typedef enum { // CefShutdown() are guaranteed to run. /// TID_FILE_BACKGROUND, - TID_FILE = TID_FILE_BACKGROUND, /// // Used for blocking tasks (e.g. file system access) that affect UI or diff --git a/include/wrapper/cef_helpers.h b/include/wrapper/cef_helpers.h index 15489034d..57ab3fbfd 100644 --- a/include/wrapper/cef_helpers.h +++ b/include/wrapper/cef_helpers.h @@ -48,7 +48,12 @@ #define CEF_REQUIRE_UI_THREAD() DCHECK(CefCurrentlyOn(TID_UI)); #define CEF_REQUIRE_IO_THREAD() DCHECK(CefCurrentlyOn(TID_IO)); -#define CEF_REQUIRE_FILE_THREAD() DCHECK(CefCurrentlyOn(TID_FILE)); +#define CEF_REQUIRE_FILE_BACKGROUND_THREAD() \ + DCHECK(CefCurrentlyOn(TID_FILE_BACKGROUND)); +#define CEF_REQUIRE_FILE_USER_VISIBLE_THREAD() \ + DCHECK(CefCurrentlyOn(TID_FILE_USER_VISIBLE)); +#define CEF_REQUIRE_FILE_USER_BLOCKING_THREAD() \ + DCHECK(CefCurrentlyOn(TID_FILE_USER_BLOCKING)); #define CEF_REQUIRE_RENDERER_THREAD() DCHECK(CefCurrentlyOn(TID_RENDERER)); // Use this struct in conjuction with refcounted types to ensure that an @@ -86,7 +91,12 @@ struct CefDeleteOnThread { struct CefDeleteOnUIThread : public CefDeleteOnThread {}; struct CefDeleteOnIOThread : public CefDeleteOnThread {}; -struct CefDeleteOnFileThread : public CefDeleteOnThread {}; +struct CefDeleteOnFileBackgroundThread + : public CefDeleteOnThread {}; +struct CefDeleteOnFileUserVisibleThread + : public CefDeleteOnThread {}; +struct CefDeleteOnFileUserBlockingThread + : public CefDeleteOnThread {}; struct CefDeleteOnRendererThread : public CefDeleteOnThread {}; // Same as IMPLEMENT_REFCOUNTING() but using the specified Destructor. @@ -114,7 +124,6 @@ struct CefDeleteOnRendererThread : public CefDeleteOnThread {}; #define IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(ClassName) \ IMPLEMENT_REFCOUNTING_EX(ClassName, CefDeleteOnIOThread) - /// // Helper class to manage a scoped copy of |argv|. /// diff --git a/libcef_dll/wrapper/cef_resource_manager.cc b/libcef_dll/wrapper/cef_resource_manager.cc index 0f5c647aa..44c3f209f 100644 --- a/libcef_dll/wrapper/cef_resource_manager.cc +++ b/libcef_dll/wrapper/cef_resource_manager.cc @@ -116,8 +116,9 @@ class DirectoryProvider : public CefResourceManager::Provider { const std::string& file_path = GetFilePath(url); // Open |file_path| on the FILE thread. - CefPostTask(TID_FILE, base::Bind(&DirectoryProvider::OpenOnFileThread, - file_path, request)); + CefPostTask( + TID_FILE_USER_BLOCKING, + base::Bind(&DirectoryProvider::OpenOnFileThread, file_path, request)); return true; } @@ -134,7 +135,7 @@ class DirectoryProvider : public CefResourceManager::Provider { static void OpenOnFileThread( const std::string& file_path, scoped_refptr request) { - CEF_REQUIRE_FILE_THREAD(); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); CefRefPtr stream = CefStreamReader::CreateForFile(file_path); @@ -198,9 +199,10 @@ class ArchiveProvider : public CefResourceManager::Provider { pending_requests_.push_back(request); // Load the archive file on the FILE thread. - CefPostTask(TID_FILE, base::Bind(&ArchiveProvider::LoadOnFileThread, - weak_ptr_factory_.GetWeakPtr(), - archive_path_, password_)); + CefPostTask( + TID_FILE_USER_BLOCKING, + base::Bind(&ArchiveProvider::LoadOnFileThread, + weak_ptr_factory_.GetWeakPtr(), archive_path_, password_)); return true; } @@ -218,7 +220,7 @@ class ArchiveProvider : public CefResourceManager::Provider { static void LoadOnFileThread(base::WeakPtr ptr, const std::string& archive_path, const std::string& password) { - CEF_REQUIRE_FILE_THREAD(); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); CefRefPtr archive; diff --git a/tests/cefclient/browser/image_cache.cc b/tests/cefclient/browser/image_cache.cc index 9bd75542b..446da68da 100644 --- a/tests/cefclient/browser/image_cache.cc +++ b/tests/cefclient/browser/image_cache.cc @@ -168,7 +168,7 @@ ImageCache::ImageType ImageCache::GetImageType(const std::string& path) { void ImageCache::LoadMissing(const ImageInfoSet& image_info, const ImageSet& images, const LoadImagesCallback& callback) { - DCHECK(!CefCurrentlyOn(TID_UI) && !CefCurrentlyOn(TID_IO)); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); DCHECK_EQ(image_info.size(), images.size()); @@ -195,7 +195,7 @@ void ImageCache::LoadMissing(const ImageInfoSet& image_info, // static bool ImageCache::LoadImageContents(const ImageInfo& info, ImageContent* content) { - DCHECK(!CefCurrentlyOn(TID_UI) && !CefCurrentlyOn(TID_IO)); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); ImageRepSet::const_iterator it = info.reps_.begin(); for (; it != info.reps_.end(); ++it) { @@ -220,7 +220,7 @@ bool ImageCache::LoadImageContents(const std::string& path, bool internal, ImageType* type, std::string* contents) { - DCHECK(!CefCurrentlyOn(TID_UI) && !CefCurrentlyOn(TID_IO)); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); *type = GetImageType(path); if (*type == TYPE_NONE) diff --git a/tests/shared/browser/extension_util.cc b/tests/shared/browser/extension_util.cc index 6b527a7ff..8bef3d384 100644 --- a/tests/shared/browser/extension_util.cc +++ b/tests/shared/browser/extension_util.cc @@ -70,9 +70,9 @@ void RunManifestCallback(const ManifestCallback& callback, // Asynchronously reads the manifest and executes |callback| on the UI thread. void GetInternalManifest(const std::string& extension_path, const ManifestCallback& callback) { - if (!CefCurrentlyOn(TID_FILE)) { + if (!CefCurrentlyOn(TID_FILE_USER_BLOCKING)) { // Execute on the browser FILE thread. - CefPostTask(TID_FILE, + CefPostTask(TID_FILE_USER_BLOCKING, base::Bind(GetInternalManifest, extension_path, callback)); return; } @@ -149,7 +149,7 @@ std::string GetExtensionResourcePath(const std::string& extension_path, bool GetExtensionResourceContents(const std::string& extension_path, std::string& contents) { - CEF_REQUIRE_FILE_THREAD(); + CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); if (IsInternalExtension(extension_path)) { const std::string& contents_path =