From db59a3096b4f44aaacabdc5b455fbc0a3a6b8fb1 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 3 Feb 2022 14:23:23 +0100 Subject: Adaptations for Chrome 96 Change-Id: I40039658762b8788a0be57bd186efab71f3e4448 Reviewed-by: Peter Varga --- src/core/profile_adapter.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/core/profile_adapter.cpp') diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index 27edae132..fcb2c0bce 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -41,6 +41,7 @@ #include "base/files/file_util.h" #include "base/task/cancelable_task_tracker.h" +#include "base/threading/thread_restrictions.h" #include "base/time/time_to_iso8601.h" #include "components/favicon/core/favicon_service.h" #include "components/history/content/browser/history_database_helper.h" @@ -172,6 +173,26 @@ ProfileQt *ProfileAdapter::profile() return m_profile.data(); } +bool ProfileAdapter::ensureDataPathExists() +{ + Q_ASSERT(!m_offTheRecord); + base::ScopedAllowBlocking allowBlock; + const base::FilePath &path = toFilePath(dataPath()); + if (path.empty()) + return false; + if (base::DirectoryExists(path)) + return true; + + base::File::Error error; + if (base::CreateDirectoryAndGetError(path, &error)) + return true; + + std::string errorstr = base::File::ErrorToString(error); + qWarning("Cannot create directory %s. Error: %s.", path.AsUTF8Unsafe().c_str(), + errorstr.c_str()); + return false; +} + VisitedLinksManagerQt *ProfileAdapter::visitedLinksManager() { if (!m_visitedLinksManager) @@ -658,8 +679,8 @@ void ProfileAdapter::resetVisitedLinksManager() void ProfileAdapter::reinitializeHistoryService() { - Q_ASSERT(!m_profile->IsOffTheRecord()); - if (m_profile->ensureDirectoryExists()) { + Q_ASSERT(!m_offTheRecord); + if (ensureDataPathExists()) { favicon::FaviconService *faviconService = FaviconServiceFactoryQt::GetForBrowserContext(m_profile.data()); history::HistoryService *historyService = static_cast( -- cgit v1.2.1