Skip to content

Commit

Permalink
Bug 1649728 - Use WeakPtr in SharedStyleSheetCache::mLoadingDatas. r=…
Browse files Browse the repository at this point in the history
…firefox-style-system-reviewers,jwatt

This is safer in case Necko fails to notify us. The only repro we have
is fixed by bug 1651661, but this should hopefully be uncontroversial as
well and prevents crashing in release builds.

Differential Revision: https://phabricator.services.mozilla.com/D83642
  • Loading branch information
emilio committed Jul 16, 2020
1 parent 38b4de3 commit 01a5c05
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions layout/style/SharedStyleSheetCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,14 @@ void SharedStyleSheetCache::CancelLoadsForLoader(css::Loader& aLoader) {
// We can't stop in-progress loads because some other loader may care about
// them.
for (auto iter = mLoadingDatas.Iter(); !iter.Done(); iter.Next()) {
SheetLoadData* data = iter.Data();
do {
MOZ_DIAGNOSTIC_ASSERT(iter.Data(),
"We weren't properly notified and the load was "
"incorrectly dropped on the floor");
for (SheetLoadData* data = iter.Data(); data; data = data->mNext) {
if (data->mLoader == &aLoader) {
data->mIsCancelled = true;
}
} while ((data = data->mNext));
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions layout/style/SharedStyleSheetCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ class SharedStyleSheetCache final : public nsIMemoryReporter {

nsDataHashtable<SheetLoadDataHashKey, CompleteSheet> mCompleteSheets;
nsRefPtrHashtable<SheetLoadDataHashKey, css::SheetLoadData> mPendingDatas;
// The SheetLoadData pointers in mLoadingDatas below are weak references.
// The SheetLoadData pointers in mLoadingDatas below are weak references that
// get cleaned up when StreamLoader::OnStopRequest gets called.
//
// Note that we hold on to all sheet loads, even if in the end they happen not
// to be cacheable.
nsDataHashtable<SheetLoadDataHashKey, css::SheetLoadData*> mLoadingDatas;
nsDataHashtable<SheetLoadDataHashKey, WeakPtr<css::SheetLoadData>> mLoadingDatas;

// An origin-to-number-of-registered-documents count, in order to manage cache
// eviction as described in RegisterLoader / UnregisterLoader.
Expand Down
2 changes: 2 additions & 0 deletions layout/style/SheetLoadData.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static_assert(eAuthorSheetFeatures == 0 && eUserSheetFeatures == 1 &&
"in SheetLoadData::mParsingMode");

class SheetLoadData final : public PreloaderBase,
// FIXME(bug 1653011): This is a bit unfortunate.
public SupportsWeakPtr<SheetLoadData>,
public nsIRunnable,
public nsIThreadObserver {
using MediaMatched = dom::LinkStyle::MediaMatched;
Expand Down

0 comments on commit 01a5c05

Please sign in to comment.