Skip to content

Commit

Permalink
Merge r220931 - REGRESSION (r220601): Crash when closing google doc a…
Browse files Browse the repository at this point in the history
…fter switching the order of tabs in safari

https://bugs.webkit.org/show_bug.cgi?id=175721
<rdar://problem/33928369>

Reviewed by Geoffrey Garen.

Make sure WebProcess::markAllLayersVolatile() does not call WTFMove() multiple times
on the same completion handler. Use a RefCounter to hold on to the completion handler
and make sure the handler gets called when the RefCounter's value becomes 0.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::cancelPrepareToSuspend):
(WebKit::WebProcess::markAllLayersVolatile):
(WebKit::WebProcess::cancelMarkAllLayersVolatile):
* WebProcess/WebProcess.h:
  • Loading branch information
cdumez authored and carlosgcampos committed Aug 28, 2017
1 parent 43a3335 commit f7891c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
18 changes: 18 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,21 @@
2017-08-18 Chris Dumez <cdumez@apple.com>

REGRESSION (r220601): Crash when closing google doc after switching the order of tabs in safari
https://bugs.webkit.org/show_bug.cgi?id=175721
<rdar://problem/33928369>

Reviewed by Geoffrey Garen.

Make sure WebProcess::markAllLayersVolatile() does not call WTFMove() multiple times
on the same completion handler. Use a RefCounter to hold on to the completion handler
and make sure the handler gets called when the RefCounter's value becomes 0.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::cancelPrepareToSuspend):
(WebKit::WebProcess::markAllLayersVolatile):
(WebKit::WebProcess::cancelMarkAllLayersVolatile):
* WebProcess/WebProcess.h:

2017-08-18 Carlos Garcia Campos <cgarcia@igalia.com>

Unreviewed. Update OptionsGTK.cmake and NEWS for 2.17.91 release.
Expand Down
27 changes: 13 additions & 14 deletions Source/WebKit/WebProcess/WebProcess.cpp
Expand Up @@ -1365,7 +1365,7 @@ void WebProcess::cancelPrepareToSuspend()

// If we've already finished cleaning up and sent ProcessReadyToSuspend, we
// shouldn't send DidCancelProcessSuspension; the UI process strictly expects one or the other.
if (!m_pagesMarkingLayersAsVolatile)
if (!m_pageMarkingLayersAsVolatileCounter)
return;

cancelMarkAllLayersVolatile();
Expand All @@ -1377,28 +1377,27 @@ void WebProcess::cancelPrepareToSuspend()
void WebProcess::markAllLayersVolatile(WTF::Function<void()>&& completionHandler)
{
RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile()", this);
m_pagesMarkingLayersAsVolatile = m_pageMap.size();
if (!m_pagesMarkingLayersAsVolatile) {
ASSERT(!m_pageMarkingLayersAsVolatileCounter);
m_pageMarkingLayersAsVolatileCounter = std::make_unique<PageMarkingLayersAsVolatileCounter>([this, completionHandler = WTFMove(completionHandler)] (RefCounterEvent) {
if (m_pageMarkingLayersAsVolatileCounter->value())
return;

completionHandler();
return;
}
for (auto& page : m_pageMap.values()) {
page->markLayersVolatile([this, completionHandler = WTFMove(completionHandler)] {
ASSERT(m_pagesMarkingLayersAsVolatile);
if (!--m_pagesMarkingLayersAsVolatile)
completionHandler();
});
}
m_pageMarkingLayersAsVolatileCounter = nullptr;
});
auto token = m_pageMarkingLayersAsVolatileCounter->count();
for (auto& page : m_pageMap.values())
page->markLayersVolatile([token] { });
}

void WebProcess::cancelMarkAllLayersVolatile()
{
if (!m_pagesMarkingLayersAsVolatile)
if (!m_pageMarkingLayersAsVolatileCounter)
return;

m_pageMarkingLayersAsVolatileCounter = nullptr;
for (auto& page : m_pageMap.values())
page->cancelMarkLayersVolatile();
m_pagesMarkingLayersAsVolatile = 0;
}

void WebProcess::setAllLayerTreeStatesFrozen(bool frozen)
Expand Down
6 changes: 5 additions & 1 deletion Source/WebKit/WebProcess/WebProcess.h
Expand Up @@ -40,6 +40,7 @@
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/RefCounter.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/AtomicStringHash.h>

Expand Down Expand Up @@ -406,7 +407,10 @@ class WebProcess : public ChildProcess {
WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
#endif

unsigned m_pagesMarkingLayersAsVolatile { 0 };
enum PageMarkingLayersAsVolatileCounterType { };
using PageMarkingLayersAsVolatileCounter = RefCounter<PageMarkingLayersAsVolatileCounterType>;
std::unique_ptr<PageMarkingLayersAsVolatileCounter> m_pageMarkingLayersAsVolatileCounter;

bool m_suppressMemoryPressureHandler { false };
#if PLATFORM(MAC)
std::unique_ptr<WebCore::CPUMonitor> m_cpuMonitor;
Expand Down

0 comments on commit f7891c2

Please sign in to comment.