forked from mirrors/gecko-dev
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:
parent
bbf5b145a3
commit
c25b106076
1 changed files with 3 additions and 63 deletions
66
netwerk/cache/nsCacheService.cpp
vendored
66
netwerk/cache/nsCacheService.cpp
vendored
|
|
@ -39,6 +39,7 @@
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "nsITimer.h"
|
#include "nsITimer.h"
|
||||||
#include "mozIStorageService.h"
|
#include "mozIStorageService.h"
|
||||||
|
#include "mozilla/StaticPrefs_browser.h"
|
||||||
|
|
||||||
#include "mozilla/net/NeckoCommon.h"
|
#include "mozilla/net/NeckoCommon.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
@ -49,8 +50,6 @@ using namespace mozilla::net;
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* nsCacheProfilePrefObserver
|
* 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_DIR_PREF "browser.cache.offline.parent_directory"
|
||||||
#define OFFLINE_CACHE_CAPACITY_PREF "browser.cache.offline.capacity"
|
#define OFFLINE_CACHE_CAPACITY_PREF "browser.cache.offline.capacity"
|
||||||
#define OFFLINE_CACHE_CAPACITY 512000
|
#define OFFLINE_CACHE_CAPACITY 512000
|
||||||
|
|
@ -62,14 +61,6 @@ static const char* observerList[] = {
|
||||||
NS_XPCOM_SHUTDOWN_OBSERVER_ID, "last-pb-context-exited",
|
NS_XPCOM_SHUTDOWN_OBSERVER_ID, "last-pb-context-exited",
|
||||||
"suspend_process_notification", "resume_process_notification"};
|
"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 {
|
class nsCacheProfilePrefObserver : public nsIObserver {
|
||||||
virtual ~nsCacheProfilePrefObserver() = default;
|
virtual ~nsCacheProfilePrefObserver() = default;
|
||||||
|
|
||||||
|
|
@ -104,8 +95,6 @@ class nsCacheProfilePrefObserver : public nsIObserver {
|
||||||
return mSanitizeOnShutdown && mClearCacheOnShutdown;
|
return mSanitizeOnShutdown && mClearCacheOnShutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefChanged(const char* aPref);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mHaveProfile;
|
bool mHaveProfile;
|
||||||
|
|
||||||
|
|
@ -153,10 +142,6 @@ nsresult nsCacheProfilePrefObserver::Install() {
|
||||||
nsCOMPtr<nsIPrefBranch> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
nsCOMPtr<nsIPrefBranch> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||||
if (!branch) return NS_ERROR_FAILURE;
|
if (!branch) return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
Preferences::RegisterCallbacks(
|
|
||||||
PREF_CHANGE_METHOD(nsCacheProfilePrefObserver::PrefChanged), prefList,
|
|
||||||
this);
|
|
||||||
|
|
||||||
// Determine if we have a profile already
|
// Determine if we have a profile already
|
||||||
// Install() is called *after* the profile-after-change notification
|
// Install() is called *after* the profile-after-change notification
|
||||||
// when there is only a single profile, or it is specified on the
|
// when there is only a single profile, or it is specified on the
|
||||||
|
|
@ -183,13 +168,6 @@ void nsCacheProfilePrefObserver::Remove() {
|
||||||
obs->RemoveObserver(this, observer);
|
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
|
NS_IMETHODIMP
|
||||||
|
|
@ -236,40 +214,6 @@ nsCacheProfilePrefObserver::Observe(nsISupports* subject, const char* topic,
|
||||||
return NS_OK;
|
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 nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) {
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
|
@ -303,13 +247,9 @@ nsresult nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read offline cache device prefs
|
// read offline cache device prefs
|
||||||
mOfflineCacheEnabled = true; // presume offline cache is enabled
|
mOfflineCacheEnabled = StaticPrefs::browser_cache_offline_enable();
|
||||||
(void)branch->GetBoolPref(OFFLINE_CACHE_ENABLE_PREF, &mOfflineCacheEnabled);
|
|
||||||
|
|
||||||
mOfflineStorageCacheEnabled =
|
mOfflineStorageCacheEnabled =
|
||||||
true; // presume offline storage cache is enabled
|
StaticPrefs::browser_cache_offline_storage_enable();
|
||||||
(void)branch->GetBoolPref(OFFLINE_CACHE_STORAGE_ENABLE_PREF,
|
|
||||||
&mOfflineStorageCacheEnabled);
|
|
||||||
|
|
||||||
mOfflineCacheCapacity = OFFLINE_CACHE_CAPACITY;
|
mOfflineCacheCapacity = OFFLINE_CACHE_CAPACITY;
|
||||||
(void)branch->GetIntPref(OFFLINE_CACHE_CAPACITY_PREF, &mOfflineCacheCapacity);
|
(void)branch->GetIntPref(OFFLINE_CACHE_CAPACITY_PREF, &mOfflineCacheCapacity);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue