Bug 1585582 - Remove all pref observers in CacheService r=mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D47960

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jonathan Kingston 2019-10-21 09:35:19 +00:00
parent bbf5b145a3
commit c25b106076

View File

@ -39,6 +39,7 @@
#include "mozilla/Services.h"
#include "nsITimer.h"
#include "mozIStorageService.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/net/NeckoCommon.h"
#include <algorithm>
@ -49,8 +50,6 @@ using namespace mozilla::net;
/******************************************************************************
* nsCacheProfilePrefObserver
*****************************************************************************/
#define OFFLINE_CACHE_ENABLE_PREF "browser.cache.offline.enable"
#define OFFLINE_CACHE_STORAGE_ENABLE_PREF "browser.cache.offline.storage.enable"
#define OFFLINE_CACHE_DIR_PREF "browser.cache.offline.parent_directory"
#define OFFLINE_CACHE_CAPACITY_PREF "browser.cache.offline.capacity"
#define OFFLINE_CACHE_CAPACITY 512000
@ -62,14 +61,6 @@ static const char* observerList[] = {
NS_XPCOM_SHUTDOWN_OBSERVER_ID, "last-pb-context-exited",
"suspend_process_notification", "resume_process_notification"};
static const char* prefList[] = {
OFFLINE_CACHE_ENABLE_PREF,
OFFLINE_CACHE_STORAGE_ENABLE_PREF,
OFFLINE_CACHE_CAPACITY_PREF,
OFFLINE_CACHE_DIR_PREF,
nullptr,
};
class nsCacheProfilePrefObserver : public nsIObserver {
virtual ~nsCacheProfilePrefObserver() = default;
@ -104,8 +95,6 @@ class nsCacheProfilePrefObserver : public nsIObserver {
return mSanitizeOnShutdown && mClearCacheOnShutdown;
}
void PrefChanged(const char* aPref);
private:
bool mHaveProfile;
@ -153,10 +142,6 @@ nsresult nsCacheProfilePrefObserver::Install() {
nsCOMPtr<nsIPrefBranch> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!branch) return NS_ERROR_FAILURE;
Preferences::RegisterCallbacks(
PREF_CHANGE_METHOD(nsCacheProfilePrefObserver::PrefChanged), prefList,
this);
// Determine if we have a profile already
// Install() is called *after* the profile-after-change notification
// when there is only a single profile, or it is specified on the
@ -183,13 +168,6 @@ void nsCacheProfilePrefObserver::Remove() {
obs->RemoveObserver(this, observer);
}
}
// remove Pref Service observers
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs) return;
Preferences::UnregisterCallbacks(
PREF_CHANGE_METHOD(nsCacheProfilePrefObserver::PrefChanged), prefList,
this);
}
NS_IMETHODIMP
@ -236,40 +214,6 @@ nsCacheProfilePrefObserver::Observe(nsISupports* subject, const char* topic,
return NS_OK;
}
void nsCacheProfilePrefObserver::PrefChanged(const char* aPref) {
// ignore pref changes until we're done switch profiles
if (!mHaveProfile) return;
// which preference changed?
nsresult rv;
if (!strcmp(OFFLINE_CACHE_ENABLE_PREF, aPref) ||
!strcmp(OFFLINE_CACHE_STORAGE_ENABLE_PREF, aPref)) {
rv = Preferences::GetBool(OFFLINE_CACHE_ENABLE_PREF, &mOfflineCacheEnabled);
if (NS_FAILED(rv)) {
return;
}
rv = Preferences::GetBool(OFFLINE_CACHE_STORAGE_ENABLE_PREF,
&mOfflineStorageCacheEnabled);
if (NS_FAILED(rv)) {
return;
}
nsCacheService::SetOfflineCacheEnabled(OfflineCacheEnabled());
} else if (!strcmp(OFFLINE_CACHE_CAPACITY_PREF, aPref)) {
int32_t capacity = 0;
rv = Preferences::GetInt(OFFLINE_CACHE_CAPACITY_PREF, &capacity);
if (NS_FAILED(rv)) return;
mOfflineCacheCapacity = std::max(0, capacity);
nsCacheService::SetOfflineCacheCapacity(mOfflineCacheCapacity);
#if 0
} else if (!strcmp(OFFLINE_CACHE_DIR_PREF, aPref)) {
// XXX We probaby don't want to respond to this pref except after
// XXX profile changes. Ideally, there should be some kind of user
// XXX notification that the pref change won't take effect until
// XXX the next time the profile changes (browser launch)
#endif
}
}
nsresult nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) {
nsresult rv = NS_OK;
@ -303,13 +247,9 @@ nsresult nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) {
}
// read offline cache device prefs
mOfflineCacheEnabled = true; // presume offline cache is enabled
(void)branch->GetBoolPref(OFFLINE_CACHE_ENABLE_PREF, &mOfflineCacheEnabled);
mOfflineCacheEnabled = StaticPrefs::browser_cache_offline_enable();
mOfflineStorageCacheEnabled =
true; // presume offline storage cache is enabled
(void)branch->GetBoolPref(OFFLINE_CACHE_STORAGE_ENABLE_PREF,
&mOfflineStorageCacheEnabled);
StaticPrefs::browser_cache_offline_storage_enable();
mOfflineCacheCapacity = OFFLINE_CACHE_CAPACITY;
(void)branch->GetIntPref(OFFLINE_CACHE_CAPACITY_PREF, &mOfflineCacheCapacity);