mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1274516 - Add a helper to iterate over all ContentParents and use it to clear the image cache in both the parent and child processes. r=billm r=seth
This commit is contained in:
parent
70f1406c83
commit
e6e116bff5
@ -60,6 +60,7 @@
|
||||
#include "mozilla/media/MediaChild.h"
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/WebBrowserPersistDocumentChild.h"
|
||||
#include "imgLoader.h"
|
||||
|
||||
#if defined(MOZ_CONTENT_SANDBOX)
|
||||
#if defined(XP_WIN)
|
||||
@ -2243,6 +2244,16 @@ ContentChild::RecvRegisterChromeItem(const ChromeRegistryItem& item)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvClearImageCache(const bool& privateLoader, const bool& chrome)
|
||||
{
|
||||
imgLoader* loader = privateLoader ? imgLoader::PrivateBrowsingLoader() :
|
||||
imgLoader::NormalLoader();
|
||||
|
||||
loader->ClearCache(chrome);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvSetOffline(const bool& offline)
|
||||
{
|
||||
|
@ -388,6 +388,9 @@ public:
|
||||
const bool& reset) override;
|
||||
virtual bool RecvRegisterChromeItem(const ChromeRegistryItem& item) override;
|
||||
|
||||
virtual bool RecvClearImageCache(const bool& privateLoader,
|
||||
const bool& chrome) override;
|
||||
|
||||
virtual mozilla::jsipc::PJavaScriptChild* AllocPJavaScriptChild() override;
|
||||
|
||||
virtual bool DeallocPJavaScriptChild(mozilla::jsipc::PJavaScriptChild*) override;
|
||||
|
@ -1400,15 +1400,8 @@ ContentParent::GetAll(nsTArray<ContentParent*>& aArray)
|
||||
{
|
||||
aArray.Clear();
|
||||
|
||||
if (!sContentParents) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ContentParent* cp = sContentParents->getFirst(); cp;
|
||||
cp = cp->LinkedListElement<ContentParent>::getNext()) {
|
||||
if (cp->mIsAlive) {
|
||||
aArray.AppendElement(cp);
|
||||
}
|
||||
for (auto* cp : AllProcesses(eLive)) {
|
||||
aArray.AppendElement(cp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1417,12 +1410,7 @@ ContentParent::GetAllEvenIfDead(nsTArray<ContentParent*>& aArray)
|
||||
{
|
||||
aArray.Clear();
|
||||
|
||||
if (!sContentParents) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ContentParent* cp = sContentParents->getFirst(); cp;
|
||||
cp = cp->LinkedListElement<ContentParent>::getNext()) {
|
||||
for (auto* cp : AllProcesses(eAll)) {
|
||||
aArray.AppendElement(cp);
|
||||
}
|
||||
}
|
||||
@ -5109,17 +5097,14 @@ ContentParent::IgnoreIPCPrincipal()
|
||||
void
|
||||
ContentParent::NotifyUpdatedDictionaries()
|
||||
{
|
||||
AutoTArray<ContentParent*, 8> processes;
|
||||
GetAll(processes);
|
||||
|
||||
nsCOMPtr<nsISpellChecker> spellChecker(do_GetService(NS_SPELLCHECKER_CONTRACTID));
|
||||
MOZ_ASSERT(spellChecker, "No spell checker?");
|
||||
|
||||
InfallibleTArray<nsString> dictionaries;
|
||||
spellChecker->GetDictionaryList(&dictionaries);
|
||||
|
||||
for (size_t i = 0; i < processes.Length(); ++i) {
|
||||
Unused << processes[i]->SendUpdateDictionaryList(dictionaries);
|
||||
for (auto* cp : AllProcesses(eLive)) {
|
||||
Unused << cp->SendUpdateDictionaryList(dictionaries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,61 @@ public:
|
||||
|
||||
static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
|
||||
|
||||
enum CPIteratorPolicy {
|
||||
eLive,
|
||||
eAll
|
||||
};
|
||||
|
||||
class ContentParentIterator {
|
||||
private:
|
||||
ContentParent* mCurrent;
|
||||
CPIteratorPolicy mPolicy;
|
||||
|
||||
public:
|
||||
ContentParentIterator(CPIteratorPolicy aPolicy, ContentParent* aCurrent)
|
||||
: mCurrent(aCurrent),
|
||||
mPolicy(aPolicy)
|
||||
{
|
||||
}
|
||||
|
||||
ContentParentIterator begin()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
ContentParentIterator end()
|
||||
{
|
||||
return ContentParentIterator(mPolicy, nullptr);
|
||||
}
|
||||
|
||||
const ContentParentIterator& operator++()
|
||||
{
|
||||
MOZ_ASSERT(mCurrent);
|
||||
do {
|
||||
mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
|
||||
} while (mPolicy != eAll && mCurrent && !mCurrent->mIsAlive);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator!=(const ContentParentIterator& aOther)
|
||||
{
|
||||
MOZ_ASSERT(mPolicy == aOther.mPolicy);
|
||||
return mCurrent != aOther.mCurrent;
|
||||
}
|
||||
|
||||
ContentParent* operator*()
|
||||
{
|
||||
return mCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
static ContentParentIterator AllProcesses(CPIteratorPolicy aPolicy)
|
||||
{
|
||||
ContentParent* first =
|
||||
sContentParents ? sContentParents->getFirst() : nullptr;
|
||||
return ContentParentIterator(aPolicy, first);
|
||||
}
|
||||
|
||||
static bool IgnoreIPCPrincipal();
|
||||
|
||||
static void NotifyUpdatedDictionaries();
|
||||
|
@ -514,6 +514,8 @@ child:
|
||||
OverrideMapping[] overrides, nsCString locale, bool reset);
|
||||
async RegisterChromeItem(ChromeRegistryItem item);
|
||||
|
||||
async ClearImageCache(bool privateLoader, bool chrome);
|
||||
|
||||
async SetOffline(bool offline);
|
||||
async SetConnectivity(bool connectivity);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ChaosMode.h"
|
||||
#include "mozilla/ChaosMode.h"
|
||||
|
||||
#include "ImageLogging.h"
|
||||
#include "nsImageModule.h"
|
||||
@ -37,6 +37,7 @@
|
||||
#include "nsIFile.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsINetworkPredictor.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/nsMixedContentBlocker.h"
|
||||
|
||||
#include "nsIApplicationCache.h"
|
||||
@ -57,6 +58,7 @@
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::image;
|
||||
using namespace mozilla::net;
|
||||
|
||||
@ -1344,6 +1346,13 @@ void imgLoader::ReadAcceptHeaderPref()
|
||||
NS_IMETHODIMP
|
||||
imgLoader::ClearCache(bool chrome)
|
||||
{
|
||||
if (XRE_IsParentProcess()) {
|
||||
bool privateLoader = this == gPrivateBrowsingLoader;
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendClearImageCache(privateLoader, chrome);
|
||||
}
|
||||
}
|
||||
|
||||
if (chrome) {
|
||||
return ClearChromeImageCache();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user