Skip to content
Open
40 changes: 32 additions & 8 deletions indra/media_plugins/cef/media_plugin_cef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
#include "volume_catcher.h"
#include "media_plugin_base.h"

// _getpid()/getpid()
#if LL_WINDOWS
#include <process.h>
#else
#include <unistd.h>
#endif

#include "dullahan.h"

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -729,17 +736,34 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
std::string user_data_path_cache = message_in.getValue("cache_path");
std::string subfolder = message_in.getValue("username");

mRootCachePath = user_data_path_cache + "cef_cache";
if (!subfolder.empty())
{
std::string delim;
// media plugin doesn't have access to gDirUtilp
std::string path_separator;
#if LL_WINDOWS
// media plugin doesn't have access to gDirUtilp
delim = "\\";
path_separator = "\\";
#else
delim = "/";
path_separator = "/";
#endif
mCachePath = mRootCachePath + delim + subfolder;

mRootCachePath = user_data_path_cache + "cef_cache";

// Issue #4498 Introduce an additional sub-folder underneath the main cache
// folder so that each CEF media instance gets its own (as per the CEF API
// official position). These folders will be removed at startup by Viewer code
// so that their non-trivial size does not exhaust available disk space. This
// begs the question - why turn on the cache at all? There are 2 reasons - firstly
// some of the instances will benefit from per Viewer session caching and will
// use the injected SL cookie and secondly, it's not clear how having no cache
// interacts with the multiple simultaneous paradigm we use.
mRootCachePath += path_separator;
# if LL_WINDOWS
mRootCachePath += std::to_string(_getpid());
# else
mRootCachePath += std::to_string(getpid());
# endif

if (!subfolder.empty())
{
mCachePath = mRootCachePath + path_separator + subfolder;
}
else
{
Expand Down
24 changes: 18 additions & 6 deletions indra/newview/llappviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4411,6 +4411,9 @@ bool LLAppViewer::initCache()
const U32 CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS = 128;
LLVOCache::getInstance()->initCache(LL_PATH_CACHE, CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS, getObjectCacheVersion());

// Remove old, stale CEF cache folders
purgeCefStaleCaches();

return true;
}

Expand All @@ -4435,18 +4438,27 @@ void LLAppViewer::loadKeyBindings()
LLUrlRegistry::instance().setKeybindingHandler(&gViewerInput);
}

// As per GHI #4498, remove old, stale CEF cache folders from previous sessions
void LLAppViewer::purgeCefStaleCaches()
{
// TODO: we really shouldn't use a hard coded name for the cache folder here...
const std::string browser_parent_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
if (LLFile::isdir(browser_parent_cache))
{
// This is a sledgehammer approach - nukes the cef_cache dir entirely
// which is then recreated the first time a CEF instance creates an
// individual cache folder. If we ever decide to retain some folders
// e.g. Search UI cache - then we will need a more granular approach.
gDirUtilp->deleteDirAndContents(browser_parent_cache);
}
}

void LLAppViewer::purgeCache()
{
LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << LL_ENDL;
LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
LLViewerShaderMgr::instance()->clearShaderCache();
std::string browser_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
if (LLFile::isdir(browser_cache))
{
// cef does not support clear_cache and clear_cookies, so clear what we can manually.
gDirUtilp->deleteDirAndContents(browser_cache);
}
gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*");
}

Expand Down
1 change: 1 addition & 0 deletions indra/newview/llappviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class LLAppViewer : public LLApp

void initGeneralThread();
void purgeUserDataOnExit() { mPurgeUserDataOnExit = true; }
void purgeCefStaleCaches(); // Remove old, stale CEF cache folders
void purgeCache(); // Clear the local cache.
void purgeCacheImmediate(); //clear local cache immediately.
S32 updateTextureThreads(F32 max_time);
Expand Down
Loading