зеркало из https://github.com/mozilla/gecko-dev.git
Bug 897954: Implement and apply purge-caches mechanism. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D105440
This commit is contained in:
Родитель
3bb28a3f45
Коммит
c0e2db0631
|
@ -50,6 +50,9 @@ class PlacesEvent : public nsWrapperCache {
|
|||
virtual const PlacesVisitRemoved* AsPlacesVisitRemoved() const {
|
||||
return nullptr;
|
||||
}
|
||||
virtual const PlacesPurgeCaches* AsPlacesPurgeCaches() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~PlacesEvent() = default;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_PlacesPurgeCaches_h
|
||||
#define mozilla_dom_PlacesPurgeCaches_h
|
||||
|
||||
#include "mozilla/dom/PlacesEvent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class PlacesPurgeCaches final : public PlacesEvent {
|
||||
public:
|
||||
explicit PlacesPurgeCaches() : PlacesEvent(PlacesEventType::Purge_caches) {}
|
||||
|
||||
static already_AddRefed<PlacesPurgeCaches> Constructor(
|
||||
const GlobalObject& aGlobal) {
|
||||
RefPtr<PlacesPurgeCaches> event = new PlacesPurgeCaches();
|
||||
return event.forget();
|
||||
}
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override {
|
||||
return PlacesPurgeCaches_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
const PlacesPurgeCaches* AsPlacesPurgeCaches() const override { return this; }
|
||||
|
||||
private:
|
||||
~PlacesPurgeCaches() = default;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_PlacesPurgeCaches_h
|
|
@ -223,6 +223,7 @@ EXPORTS.mozilla.dom += [
|
|||
"PlacesFavicon.h",
|
||||
"PlacesHistoryCleared.h",
|
||||
"PlacesObservers.h",
|
||||
"PlacesPurgeCaches.h",
|
||||
"PlacesRanking.h",
|
||||
"PlacesVisit.h",
|
||||
"PlacesVisitRemoved.h",
|
||||
|
|
|
@ -39,6 +39,12 @@ enum PlacesEventType {
|
|||
* bookmarked.
|
||||
*/
|
||||
"page-removed",
|
||||
/**
|
||||
* data: PlacesPurgeCaches. Fired whenever changes happened that could not be observed
|
||||
* through other notifications, for example a database fixup. When received, observers,
|
||||
* especially data views, should drop any caches and reload from scratch.
|
||||
*/
|
||||
"purge-caches",
|
||||
};
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
|
@ -328,4 +334,9 @@ interface PlacesVisitRemoved : PlacesEvent {
|
|||
* This will be true if remains at least one visit to the page.
|
||||
*/
|
||||
readonly attribute boolean isPartialVisistsRemoval;
|
||||
};
|
||||
};
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface PlacesPurgeCaches : PlacesEvent {
|
||||
constructor();
|
||||
};
|
||||
|
|
|
@ -891,6 +891,10 @@ BookmarksTracker.prototype = {
|
|||
this._log.trace("'bookmark-removed': " + event.id);
|
||||
this._upScore();
|
||||
break;
|
||||
case "purge-caches":
|
||||
this._log.trace("purge-caches");
|
||||
this._upScore();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -103,15 +103,7 @@ var PlacesDBUtils = {
|
|||
* @returns {Array} An empty array.
|
||||
*/
|
||||
async _refreshUI() {
|
||||
// Send batch update notifications to update the UI.
|
||||
let observers = [
|
||||
...PlacesUtils.history.getObservers(),
|
||||
...PlacesUtils.bookmarks.getObservers(),
|
||||
];
|
||||
for (let observer of observers) {
|
||||
observer.onBeginUpdateBatch();
|
||||
observer.onEndUpdateBatch();
|
||||
}
|
||||
PlacesObservers.notifyListeners([new PlacesPurgeCaches()]);
|
||||
return [];
|
||||
},
|
||||
|
||||
|
|
|
@ -3477,9 +3477,17 @@ nsNavHistoryResult::nsNavHistoryResult(
|
|||
MOZ_ASSERT(mRootNode->mIndentLevel == -1,
|
||||
"Root node's indent level initialized wrong");
|
||||
mRootNode->FillStats();
|
||||
|
||||
AutoTArray<PlacesEventType, 1> events;
|
||||
events.AppendElement(PlacesEventType::Purge_caches);
|
||||
PlacesObservers::AddListener(events, this);
|
||||
}
|
||||
|
||||
nsNavHistoryResult::~nsNavHistoryResult() {
|
||||
AutoTArray<PlacesEventType, 1> events;
|
||||
events.AppendElement(PlacesEventType::Purge_caches);
|
||||
PlacesObservers::RemoveListener(events, this);
|
||||
|
||||
// Delete all heap-allocated bookmark folder observer arrays.
|
||||
for (auto it = mBookmarkFolderObservers.Iter(); !it.Done(); it.Next()) {
|
||||
delete it.Data();
|
||||
|
@ -4227,6 +4235,10 @@ void nsNavHistoryResult::HandlePlacesEvent(const PlacesEventSequence& aEvents) {
|
|||
|
||||
break;
|
||||
}
|
||||
case PlacesEventType::Purge_caches: {
|
||||
mRootNode->Refresh();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"Receive notification of a type not subscribed to.");
|
||||
|
|
|
@ -432,6 +432,7 @@ module.exports = {
|
|||
PlacesEvent: false,
|
||||
PlacesHistoryCleared: false,
|
||||
PlacesObservers: false,
|
||||
PlacesPurgeCaches: false,
|
||||
PlacesRanking: false,
|
||||
PlacesVisit: false,
|
||||
PlacesVisitRemoved: false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче