Commit bfe6f774 authored by yutak@chromium.org's avatar yutak@chromium.org

[Oilpan] De-oilpanize ScopedPageLoadDeferrer.

ScopedPageLoadDeferrer is an RAII-like class that does some work when it is
constructed and destructed, just like other ScopedXXX classes.

It was oilpanized in the past, and a new method, dispose(), was added to
do clean-ups that had been done in the destructor. However, a few stack-
allocated usages were overlooked in that change.

Garbage-collected objects shouldn't be allocated on the stack. So, stack-
allocated usages should be converted to heap-allocated, with dispose() calls
added in every single place where the object can go out of scope.

However, I find this conversion too cumbersome and less C++-idiomatic.

Therefore, this patch instead de-oilpanizes ScopedPageLoadDeferrer. The only
reference to will-be-heap-managed class in ScopedPageLoadDeferrer is
RefPtr<LocalFrame>, so it is safe to convert it to RefPtrWillBePersistent.

I think this patch makes the code cleaner overall.

BUG=486590
R=haraken@chromium.org, oilpan-reviews@chromium.org, sigbjornf@opera.com

Review URL: https://codereview.chromium.org/1316663004

git-svn-id: svn://svn.chromium.org/blink/trunk@201630 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 486c0df7
......@@ -31,7 +31,7 @@
namespace blink {
ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) : m_detached(false)
ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion)
{
const HashSet<Page*>& pages = Page::ordinaryPages();
for (const Page* page : pages) {
......@@ -57,36 +57,17 @@ ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) : m_detached(fal
void ScopedPageLoadDeferrer::detach()
{
if (m_detached)
return;
for (size_t i = 0; i < m_deferredFrames.size(); ++i) {
if (Page* page = m_deferredFrames[i]->page())
page->setDefersLoading(false);
}
Platform::current()->currentThread()->scheduler()->resumeTimerQueue();
m_detached = true;
}
#if ENABLE(OILPAN)
void ScopedPageLoadDeferrer::dispose()
{
detach();
m_deferredFrames.clear();
}
#endif
ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer()
{
detach();
}
DEFINE_TRACE(ScopedPageLoadDeferrer)
{
#if ENABLE(OILPAN)
visitor->trace(m_deferredFrames);
#endif
}
} // namespace blink
......@@ -30,24 +30,17 @@ namespace blink {
class LocalFrame;
class Page;
class CORE_EXPORT ScopedPageLoadDeferrer final : public NoBaseWillBeGarbageCollectedFinalized<ScopedPageLoadDeferrer> {
class CORE_EXPORT ScopedPageLoadDeferrer final {
WTF_MAKE_NONCOPYABLE(ScopedPageLoadDeferrer);
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(ScopedPageLoadDeferrer);
WTF_MAKE_FAST_ALLOCATED(ScopedPageLoadDeferrer);
public:
ScopedPageLoadDeferrer(Page* exclusion = nullptr);
explicit ScopedPageLoadDeferrer(Page* exclusion = nullptr);
~ScopedPageLoadDeferrer();
#if ENABLE(OILPAN)
void dispose();
#endif
DECLARE_TRACE();
private:
void detach();
WillBeHeapVector<RefPtrWillBeMember<LocalFrame>, 16> m_deferredFrames;
bool m_detached;
Vector<RefPtrWillBePersistent<LocalFrame>, 16> m_deferredFrames;
};
} // namespace blink
......
......@@ -222,10 +222,10 @@ const double WebView::maxTextSizeMultiplier = 3.0;
// Used to defer all page activity in cases where the embedder wishes to run
// a nested event loop. Using a stack enables nesting of message loop invocations.
static WillBeHeapVector<RawPtrWillBeMember<ScopedPageLoadDeferrer>>& pageLoadDeferrerStack()
static Vector<OwnPtr<ScopedPageLoadDeferrer>>& pageLoadDeferrerStack()
{
DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMember<ScopedPageLoadDeferrer>>>, deferrerStack, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMember<ScopedPageLoadDeferrer>>())));
return *deferrerStack;
DEFINE_STATIC_LOCAL(Vector<OwnPtr<ScopedPageLoadDeferrer>>, deferrerStack, ());
return deferrerStack;
}
// Ensure that the WebDragOperation enum values stay in sync with the original
......@@ -356,19 +356,12 @@ void WebView::resetVisitedLinkState()
void WebView::willEnterModalLoop()
{
pageLoadDeferrerStack().append(new ScopedPageLoadDeferrer());
pageLoadDeferrerStack().append(adoptPtr(new ScopedPageLoadDeferrer()));
}
void WebView::didExitModalLoop()
{
ASSERT(pageLoadDeferrerStack().size());
ScopedPageLoadDeferrer* deferrer = pageLoadDeferrerStack().last();
#if ENABLE(OILPAN)
deferrer->dispose();
#else
delete deferrer;
#endif
pageLoadDeferrerStack().removeLast();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment