Skip to content

Commit 356b682

Browse files
committed
First part of work for #4498. This change forces each CEF instance to have it's own cache/cookie folder underneath the parent cef_cache folder. The whole cef_cache folder structure is purged at startup (before the parent being created at the first media instance creation)
1 parent 819817f commit 356b682

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

indra/media_plugins/cef/media_plugin_cef.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
#include "volume_catcher.h"
3939
#include "media_plugin_base.h"
4040

41+
// _getpid()/getpid()
42+
#if LL_WINDOWS
43+
#include <process.h>
44+
#else
45+
#include <unistd.h>
46+
#endif
47+
4148
#include "dullahan.h"
4249

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

732-
mRootCachePath = user_data_path_cache + "cef_cache";
733-
if (!subfolder.empty())
734-
{
735-
std::string delim;
739+
// media plugin doesn't have access to gDirUtilp
740+
std::string path_separator;
736741
#if LL_WINDOWS
737-
// media plugin doesn't have access to gDirUtilp
738-
delim = "\\";
742+
path_separator = "\\";
739743
#else
740-
delim = "/";
744+
path_separator = "/";
741745
#endif
742-
mCachePath = mRootCachePath + delim + subfolder;
746+
747+
mRootCachePath = user_data_path_cache + "cef_cache";
748+
749+
// Issue #4498 Introduce an additional sub-folder underneath the main cache
750+
// folder so that each CEF media instance gets its own (as per the CEF API
751+
// official position). These folders will be removed at startup by Viewer code
752+
// so that their non-trivial size does not exhaust available disk space. This
753+
// begs the question - why turn on the cache at all? There are 2 reasons - firstly
754+
// some of the instances will benefit from per Viewer session caching and will
755+
// use the injected SL cookie and secondly, it's not clear how having no cache
756+
// interacts with the multiple simultaneous paradigm we use.
757+
mRootCachePath += path_separator;
758+
# if LL_WINDOWS
759+
mRootCachePath += std::to_string(_getpid());
760+
# else
761+
mRootCachePath += std::to_string(getpid());
762+
# endif
763+
764+
if (!subfolder.empty())
765+
{
766+
mCachePath = mRootCachePath + path_separator + subfolder;
743767
}
744768
else
745769
{

indra/newview/llappviewer.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,6 +4411,9 @@ bool LLAppViewer::initCache()
44114411
const U32 CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS = 128;
44124412
LLVOCache::getInstance()->initCache(LL_PATH_CACHE, CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS, getObjectCacheVersion());
44134413

4414+
// Remove old, stale CEF cache folders
4415+
purgeCefStaleCaches();
4416+
44144417
return true;
44154418
}
44164419

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

4441+
// As per GHI #4498, remove old, stale CEF cache folders from previous sessions
4442+
void LLAppViewer::purgeCefStaleCaches()
4443+
{
4444+
// TODO: we really shouldn't use a hard coded name for the cache folder here...
4445+
const std::string browser_parent_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
4446+
if (LLFile::isdir(browser_parent_cache))
4447+
{
4448+
// This is a sledgehammer approach - nukes the cef_cache dir entirely
4449+
// which is then recreated the first time a CEF instance creates an
4450+
// individual cache folder. If we ever decide to retain some folders
4451+
// e.g. Search UI cache - then we will need a more granular approach.
4452+
gDirUtilp->deleteDirAndContents(browser_parent_cache);
4453+
}
4454+
}
4455+
44384456
void LLAppViewer::purgeCache()
44394457
{
44404458
LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << LL_ENDL;
44414459
LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
44424460
LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
44434461
LLViewerShaderMgr::instance()->clearShaderCache();
4444-
std::string browser_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
4445-
if (LLFile::isdir(browser_cache))
4446-
{
4447-
// cef does not support clear_cache and clear_cookies, so clear what we can manually.
4448-
gDirUtilp->deleteDirAndContents(browser_cache);
4449-
}
44504462
gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*");
44514463
}
44524464

indra/newview/llappviewer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class LLAppViewer : public LLApp
220220

221221
void initGeneralThread();
222222
void purgeUserDataOnExit() { mPurgeUserDataOnExit = true; }
223+
void purgeCefStaleCaches(); // Remove old, stale CEF cache folders
223224
void purgeCache(); // Clear the local cache.
224225
void purgeCacheImmediate(); //clear local cache immediately.
225226
S32 updateTextureThreads(F32 max_time);

0 commit comments

Comments
 (0)