зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1473631: Part 13 - Replace pref observers with callbacks in DataStorage. r=njn
MozReview-Commit-ID: 4UFghn8JDTu --HG-- extra : rebase_source : eaf2096d9c6abc2e192c3f6bb637b3473bfd62d8
This commit is contained in:
Родитель
5764d2a51d
Коммит
adc29b7d10
|
@ -190,6 +190,9 @@ DataStorage::DataStorage(const nsString& aFilename)
|
|||
|
||||
DataStorage::~DataStorage()
|
||||
{
|
||||
Preferences::UnregisterCallback(PREF_CHANGE_METHOD(DataStorage::PrefChanged),
|
||||
"test.datastorage.write_timer_ms",
|
||||
this);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -430,10 +433,9 @@ DataStorage::Init(bool& aDataWillPersist,
|
|||
// For test purposes, we can set the write timer to be very fast.
|
||||
mTimerDelay = Preferences::GetInt("test.datastorage.write_timer_ms",
|
||||
sDataStorageDefaultTimerDelay);
|
||||
rv = Preferences::AddStrongObserver(this, "test.datastorage.write_timer_ms");
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
Preferences::RegisterCallback(PREF_CHANGE_METHOD(DataStorage::PrefChanged),
|
||||
"test.datastorage.write_timer_ms",
|
||||
this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1156,10 +1158,6 @@ DataStorage::Observe(nsISupports* /*aSubject*/, const char* aTopic,
|
|||
if (strcmp(aTopic, "last-pb-context-exited") == 0) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
mPrivateDataTable.Clear();
|
||||
} else if (strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
mTimerDelay = Preferences::GetInt("test.datastorage.write_timer_ms",
|
||||
sDataStorageDefaultTimerDelay);
|
||||
}
|
||||
|
||||
if (!XRE_IsParentProcess()) {
|
||||
|
@ -1193,6 +1191,14 @@ DataStorage::Observe(nsISupports* /*aSubject*/, const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
DataStorage::PrefChanged(const char* aPref)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
mTimerDelay = Preferences::GetInt("test.datastorage.write_timer_ms",
|
||||
sDataStorageDefaultTimerDelay);
|
||||
}
|
||||
|
||||
DataStorage::Entry::Entry()
|
||||
: mScore(0)
|
||||
, mLastAccessed((int32_t)(PR_Now() / sOneDayInMicroseconds))
|
||||
|
|
|
@ -197,6 +197,8 @@ private:
|
|||
void ShutdownTimer();
|
||||
void NotifyObservers(const char* aTopic);
|
||||
|
||||
void PrefChanged(const char* aPref);
|
||||
|
||||
bool GetInternal(const nsCString& aKey, Entry* aEntry, DataStorageType aType,
|
||||
const MutexAutoLock& aProofOfLock);
|
||||
nsresult PutInternal(const nsCString& aKey, Entry& aEntry,
|
||||
|
|
Загрузка…
Ссылка в новой задаче