Commit f2ead0f7 authored by weinig@apple.com's avatar weinig@apple.com

Cleanup PageThrottler and PageConsole a bit

https://bugs.webkit.org/show_bug.cgi?id=122085

Reviewed by Anders Carlsson.

* html/HTMLMediaElement.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::completed):
* loader/FrameLoader.h:
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::checkForHTTPStatusCodeError):
(WebCore::SubresourceLoader::didFinishLoading):
(WebCore::SubresourceLoader::didFail):
(WebCore::SubresourceLoader::willCancel):
* loader/SubresourceLoader.h:
Store the PageActivityAssertionToken as a std::unique_ptr.

* page/Page.cpp:
(WebCore::Page::Page):
Use createOwned and pass this by reference for the PageThrottler and PageConsole.
(WebCore::Page::~Page):
Remove unnecessary clearing of an OwnPtr that is about to be destroyed.
* page/Page.h:
Make m_pageThrottler const and return it as a reference.

* page/PageActivityAssertionToken.cpp:
(WebCore::PageActivityAssertionToken::PageActivityAssertionToken):
(WebCore::PageActivityAssertionToken::~PageActivityAssertionToken):
* page/PageActivityAssertionToken.h:
Take the PageThrottler by reference in the constructor. It is never null.

* page/PageConsole.cpp:
(WebCore::PageConsole::PageConsole):
(WebCore::PageConsole::~PageConsole):
(WebCore::PageConsole::addMessage):
* page/PageConsole.h:
Pass and store the Page as a reference and remove an extraneous null check. Remove
the create function.

* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
(WebCore::PageThrottler::~PageThrottler):
(WebCore::PageThrottler::createActivityToken):
(WebCore::PageThrottler::throttlePage):
(WebCore::PageThrottler::unthrottlePage):
(WebCore::PageThrottler::addActivityToken):
(WebCore::PageThrottler::removeActivityToken):
* page/PageThrottler.h:
Pass and store the Page as a reference. Move the creation of PageActivityAssertionToken here
to aid encapsulation.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156625 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 59875529
2013-09-29 Sam Weinig <sam@webkit.org>
Cleanup PageThrottler and PageConsole a bit
https://bugs.webkit.org/show_bug.cgi?id=122085
Reviewed by Anders Carlsson.
* html/HTMLMediaElement.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::completed):
* loader/FrameLoader.h:
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::checkForHTTPStatusCodeError):
(WebCore::SubresourceLoader::didFinishLoading):
(WebCore::SubresourceLoader::didFail):
(WebCore::SubresourceLoader::willCancel):
* loader/SubresourceLoader.h:
Store the PageActivityAssertionToken as a std::unique_ptr.
* page/Page.cpp:
(WebCore::Page::Page):
Use createOwned and pass this by reference for the PageThrottler and PageConsole.
(WebCore::Page::~Page):
Remove unnecessary clearing of an OwnPtr that is about to be destroyed.
* page/Page.h:
Make m_pageThrottler const and return it as a reference.
* page/PageActivityAssertionToken.cpp:
(WebCore::PageActivityAssertionToken::PageActivityAssertionToken):
(WebCore::PageActivityAssertionToken::~PageActivityAssertionToken):
* page/PageActivityAssertionToken.h:
Take the PageThrottler by reference in the constructor. It is never null.
* page/PageConsole.cpp:
(WebCore::PageConsole::PageConsole):
(WebCore::PageConsole::~PageConsole):
(WebCore::PageConsole::addMessage):
* page/PageConsole.h:
Pass and store the Page as a reference and remove an extraneous null check. Remove
the create function.
* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
(WebCore::PageThrottler::~PageThrottler):
(WebCore::PageThrottler::createActivityToken):
(WebCore::PageThrottler::throttlePage):
(WebCore::PageThrottler::unthrottlePage):
(WebCore::PageThrottler::addActivityToken):
(WebCore::PageThrottler::removeActivityToken):
* page/PageThrottler.h:
Pass and store the Page as a reference. Move the creation of PageActivityAssertionToken here
to aid encapsulation.
2013-09-29 Darin Adler <darin@apple.com>
Try to fix Windows build.
......@@ -781,7 +781,7 @@ private:
OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
#endif
OwnPtr<PageActivityAssertionToken> m_activityToken;
std::unique_ptr<PageActivityAssertionToken> m_activityToken;
size_t m_reportedExtraMemoryCost;
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
......
......@@ -1101,7 +1101,7 @@ void FrameLoader::completed()
if (m_frame.view())
m_frame.view()->maintainScrollPositionAtAnchor(0);
m_activityAssertion.clear();
m_activityAssertion = nullptr;
}
void FrameLoader::started()
......
......@@ -447,7 +447,7 @@ private:
URL m_previousURL;
RefPtr<HistoryItem> m_requestedHistoryItem;
OwnPtr<PageActivityAssertionToken> m_activityAssertion;
std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
};
// This function is called by createWindow() in JSDOMWindowBase.cpp, for example, for
......
......@@ -260,7 +260,7 @@ bool SubresourceLoader::checkForHTTPStatusCodeError()
return false;
m_state = Finishing;
m_activityAssertion.clear();
m_activityAssertion = nullptr;
m_resource->error(CachedResource::LoadError);
cancel();
return true;
......@@ -278,7 +278,7 @@ void SubresourceLoader::didFinishLoading(double finishTime)
Ref<SubresourceLoader> protect(*this);
CachedResourceHandle<CachedResource> protectResource(m_resource);
m_state = Finishing;
m_activityAssertion.clear();
m_activityAssertion = nullptr;
m_resource->setLoadFinishTime(finishTime);
m_resource->finishLoading(resourceData());
......@@ -303,7 +303,7 @@ void SubresourceLoader::didFail(const ResourceError& error)
Ref<SubresourceLoader> protect(*this);
CachedResourceHandle<CachedResource> protectResource(m_resource);
m_state = Finishing;
m_activityAssertion.clear();
m_activityAssertion = nullptr;
if (m_resource->resourceToRevalidate())
memoryCache()->revalidationFailed(m_resource);
m_resource->setResourceError(error);
......@@ -326,7 +326,7 @@ void SubresourceLoader::willCancel(const ResourceError& error)
Ref<SubresourceLoader> protect(*this);
m_state = Finishing;
m_activityAssertion.clear();
m_activityAssertion = nullptr;
if (m_resource->resourceToRevalidate())
memoryCache()->revalidationFailed(m_resource);
m_resource->setResourceError(error);
......
......@@ -102,7 +102,7 @@ private:
bool m_loadingMultipartContent;
SubresourceLoaderState m_state;
OwnPtr<RequestCountTracker> m_requestCountTracker;
OwnPtr<PageActivityAssertionToken> m_activityAssertion;
std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
};
}
......
......@@ -185,8 +185,8 @@ Page::Page(PageClients& pageClients)
#endif
, m_alternativeTextClient(pageClients.alternativeTextClient)
, m_scriptedAnimationsSuspended(false)
, m_pageThrottler(PageThrottler::create(this))
, m_console(PageConsole::create(this))
, m_pageThrottler(createOwned<PageThrottler>(*this))
, m_console(createOwned<PageConsole>(*this))
, m_lastSpatialNavigationCandidatesCount(0) // NOTE: Only called from Internals for Spatial Navigation testing.
, m_framesHandlingBeforeUnloadEvent(0)
{
......@@ -235,8 +235,6 @@ Page::~Page()
#ifndef NDEBUG
pageCounter.decrement();
#endif
m_pageThrottler.clear();
}
ArenaSize Page::renderTreeSize() const
......@@ -1505,9 +1503,9 @@ void Page::resetSeenMediaEngines()
m_seenMediaEngines.clear();
}
PassOwnPtr<PageActivityAssertionToken> Page::createActivityToken()
std::unique_ptr<PageActivityAssertionToken> Page::createActivityToken()
{
return adoptPtr(new PageActivityAssertionToken(m_pageThrottler.get()));
return m_pageThrottler->createActivityToken();
}
#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
......
......@@ -395,8 +395,8 @@ public:
void sawMediaEngine(const String& engineName);
void resetSeenMediaEngines();
PageThrottler* pageThrottler() { return m_pageThrottler.get(); }
PassOwnPtr<PageActivityAssertionToken> createActivityToken();
PageThrottler& pageThrottler() { return *m_pageThrottler; }
std::unique_ptr<PageActivityAssertionToken> createActivityToken();
PageConsole& console() { return *m_console; }
......@@ -546,8 +546,7 @@ private:
AlternativeTextClient* m_alternativeTextClient;
bool m_scriptedAnimationsSuspended;
OwnPtr<PageThrottler> m_pageThrottler;
const OwnPtr<PageThrottler> m_pageThrottler;
const OwnPtr<PageConsole> m_console;
HashSet<String> m_seenPlugins;
......
......@@ -30,17 +30,16 @@
namespace WebCore {
PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler* throttler)
:m_throttler(throttler)
PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler& throttler)
: m_throttler(&throttler)
{
if (m_throttler)
m_throttler->addActivityToken(this);
m_throttler->addActivityToken(*this);
}
PageActivityAssertionToken::~PageActivityAssertionToken()
{
if (m_throttler)
m_throttler->removeActivityToken(this);
m_throttler->removeActivityToken(*this);
}
void PageActivityAssertionToken::invalidate()
......@@ -48,6 +47,6 @@ void PageActivityAssertionToken::invalidate()
m_throttler = 0;
}
}
} // namespace WebCore
......@@ -35,17 +35,15 @@ class PageThrottler;
class PageActivityAssertionToken {
WTF_MAKE_NONCOPYABLE(PageActivityAssertionToken);
public:
PageActivityAssertionToken(PageThrottler&);
~PageActivityAssertionToken();
void invalidate();
private:
friend class Page;
PageActivityAssertionToken(PageThrottler*);
PageThrottler* m_throttler;
};
}
} // namespace WebCore
#endif // PageActivityAssertionToken_h
......@@ -55,9 +55,14 @@ namespace {
int muteCount = 0;
}
PageConsole::PageConsole(Page* page) : m_page(page) { }
PageConsole::PageConsole(Page& page)
: m_page(page)
{
}
PageConsole::~PageConsole() { }
PageConsole::~PageConsole()
{
}
void PageConsole::printSourceURLAndLine(const String& sourceURL, unsigned lineNumber)
{
......@@ -161,24 +166,20 @@ void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str
if (muteCount && source != ConsoleAPIMessageSource)
return;
Page* page = this->page();
if (!page)
return;
if (callStack)
InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, callStack, requestIdentifier);
InspectorInstrumentation::addMessageToConsole(&m_page, source, LogMessageType, level, message, callStack, requestIdentifier);
else
InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, url, lineNumber, columnNumber, state, requestIdentifier);
InspectorInstrumentation::addMessageToConsole(&m_page, source, LogMessageType, level, message, url, lineNumber, columnNumber, state, requestIdentifier);
if (source == CSSMessageSource)
return;
if (page->settings().privateBrowsingEnabled())
if (m_page.settings().privateBrowsingEnabled())
return;
page->chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url);
m_page.chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url);
if (!page->settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
if (!m_page.settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
return;
printSourceURLAndLine(url, lineNumber);
......
......@@ -31,10 +31,13 @@
#include "ConsoleTypes.h"
#include "ScriptCallStack.h"
#include "ScriptState.h"
#include <wtf/Forward.h>
#include <wtf/PassOwnPtr.h>
namespace JSC {
class ExecState;
}
namespace WebCore {
class Document;
......@@ -42,8 +45,8 @@ class Page;
class PageConsole {
public:
static PassOwnPtr<PageConsole> create(Page* page) { return adoptPtr(new PageConsole(page)); }
virtual ~PageConsole();
PageConsole(Page&);
~PageConsole();
static void printSourceURLAndLine(const String& sourceURL, unsigned lineNumber);
static void printMessageSourceAndLevelPrefix(MessageSource, MessageLevel);
......@@ -59,11 +62,7 @@ public:
static void setShouldPrintExceptions(bool);
private:
PageConsole(Page*);
Page* page() { return m_page; };
Page* m_page;
Page& m_page;
};
} // namespace WebCore
......
......@@ -31,42 +31,48 @@
#include "MainFrame.h"
#include "Page.h"
#include "PageActivityAssertionToken.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
static const double kThrottleHysteresisSeconds = 2.0;
PageThrottler::PageThrottler(Page* page)
PageThrottler::PageThrottler(Page& page)
: m_page(page)
, m_throttleState(PageNotThrottledState)
, m_throttleHysteresisTimer(this, &PageThrottler::throttleHysteresisTimerFired)
{
m_page->chrome().client().incrementActivePageCount();
m_page.chrome().client().incrementActivePageCount();
}
PageThrottler::~PageThrottler()
{
setThrottled(false);
for (HashSet<PageActivityAssertionToken*>::iterator i = m_activityTokens.begin(); i != m_activityTokens.end(); ++i)
(*i)->invalidate();
for (auto it = m_activityTokens.begin(), end = m_activityTokens.end(); it != end; ++it)
(*it)->invalidate();
if (m_throttleState != PageThrottledState)
m_page->chrome().client().decrementActivePageCount();
m_page.chrome().client().decrementActivePageCount();
}
std::unique_ptr<PageActivityAssertionToken> PageThrottler::createActivityToken()
{
return std::make_unique<PageActivityAssertionToken>(*this);
}
void PageThrottler::throttlePage()
{
m_throttleState = PageThrottledState;
m_page->chrome().client().decrementActivePageCount();
m_page.chrome().client().decrementActivePageCount();
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->scriptedAnimationControllerSetThrottled(true);
}
m_page->throttleTimers();
m_page.throttleTimers();
}
void PageThrottler::unthrottlePage()
......@@ -78,14 +84,14 @@ void PageThrottler::unthrottlePage()
return;
if (oldState == PageThrottledState)
m_page->chrome().client().incrementActivePageCount();
m_page.chrome().client().incrementActivePageCount();
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->scriptedAnimationControllerSetThrottled(false);
}
m_page->unthrottleTimers();
m_page.unthrottleTimers();
}
void PageThrottler::setThrottled(bool isThrottled)
......@@ -128,11 +134,11 @@ void PageThrottler::throttleHysteresisTimerFired(Timer<PageThrottler>*)
throttlePage();
}
void PageThrottler::addActivityToken(PageActivityAssertionToken* token)
void PageThrottler::addActivityToken(PageActivityAssertionToken& token)
{
ASSERT(token && !m_activityTokens.contains(token));
ASSERT(!m_activityTokens.contains(&token));
m_activityTokens.add(token);
m_activityTokens.add(&token);
// If we've already got events that block throttling we can return early
if (m_activityTokens.size() > 1)
......@@ -148,11 +154,11 @@ void PageThrottler::addActivityToken(PageActivityAssertionToken* token)
stopThrottleHysteresisTimer();
}
void PageThrottler::removeActivityToken(PageActivityAssertionToken* token)
void PageThrottler::removeActivityToken(PageActivityAssertionToken& token)
{
ASSERT(token && m_activityTokens.contains(token));
ASSERT(m_activityTokens.contains(&token));
m_activityTokens.remove(token);
m_activityTokens.remove(&token);
if (m_activityTokens.size())
return;
......
......@@ -39,10 +39,10 @@ class PageActivityAssertionToken;
class PageThrottler {
public:
static PassOwnPtr<PageThrottler> create(Page* page)
{
return adoptPtr(new PageThrottler(page));
}
PageThrottler(Page&);
~PageThrottler();
std::unique_ptr<PageActivityAssertionToken> createActivityToken();
bool shouldThrottleAnimations() const { return m_throttleState != PageNotThrottledState; }
bool shouldThrottleTimers() const { return m_throttleState != PageNotThrottledState; }
......@@ -51,8 +51,6 @@ public:
void reportInterestingEvent();
~PageThrottler();
private:
enum PageThrottleState {
PageNotThrottledState,
......@@ -61,19 +59,17 @@ private:
};
friend class PageActivityAssertionToken;
void addActivityToken(PageActivityAssertionToken*);
void removeActivityToken(PageActivityAssertionToken*);
void addActivityToken(PageActivityAssertionToken&);
void removeActivityToken(PageActivityAssertionToken&);
PageThrottler(Page*);
void startThrottleHysteresisTimer();
void stopThrottleHysteresisTimer();
void throttleHysteresisTimerFired(Timer<PageThrottler>*);
Page* m_page;
void throttlePage();
void unthrottlePage();
Page& m_page;
PageThrottleState m_throttleState;
Timer<PageThrottler> m_throttleHysteresisTimer;
HashSet<PageActivityAssertionToken*> m_activityTokens;
......
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