Add strong typing to RefCounter interface, return value as a bool.
https://bugs.webkit.org/show_bug.cgi?id=139776
Reviewed by Geoff Garen.
Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
This means there is no compile time type checking to prevent mistakes. Update the count()
method to token<>(), templated on type used to identify the token being returned.
Calls to token<T>() will return a result of type RefCounter::Token<T>.
There are a few problems with the fact the counter will return you an exact count of the
number of outstanding tokens:
- It is desirable to only fire the callback on zero-edge changes; it is more consistent
to do so if the value is only readable as a boolean.
- It is desirable to provide the value as an argument to the callback, however to make
this useful for integer values it is also necessary to indicate the direction of change
(0->1 is often interesting where 2->1 is not).
- There is a mismatch between the precision of returning a count, and the inherent
imprecision of a token based mechanism, where it may be difficult to guarantee
absolutely no unnecessary refcount churn, and thus unintentional counter values.
Source/WebCore:
* page/PageThrottler.cpp:
(WebCore::m_mediaActivityCounter):
(WebCore::m_pageLoadActivityCounter):
- lambdas now passed the value.
(WebCore::PageThrottler::mediaActivityToken):
(WebCore::PageThrottler::pageLoadActivityToken):
- count() -> token<>().
* page/PageThrottler.h:
- specify tpoken type for PageActivityAssertionToken.
Source/WebKit2:
Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on
zero-edge transitions we no longer need this to filter changes.
* UIProcess/Plugins/PluginProcessManager.cpp:
(WebKit::PluginProcessManager::PluginProcessManager):
- updateProcessSuppressionState -> updateProcessSuppressionDisabled.
* UIProcess/Plugins/PluginProcessManager.h:
(WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabledToken):
- processSuppressionDisabledForPageCount -> processSuppressionDisabledToken.
(WebKit::PluginProcessManager::processSuppressionEnabled): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabled):
- processSuppressionEnabled -> processSuppressionDisabled.
* UIProcess/Plugins/PluginProcessProxy.cpp:
(WebKit::PluginProcessProxy::didFinishLaunching):
- processSuppressionEnabled -> processSuppressionDisabled.
* UIProcess/Plugins/mac/PluginProcessManagerMac.mm:
(WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted.
(WebKit::PluginProcessManager::updateProcessSuppressionDisabled):
- updateProcessSuppressionState -> updateProcessSuppressionDisabled
* UIProcess/ProcessThrottler.h:
- added UserObservablePageToken, ProcessSuppressionDisabledToken types.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::WebContext):
(WebKit::m_processSuppressionDisabledForPageCounter):
- lambda now has bool argument.
* UIProcess/WebContext.h:
(WebKit::WebContext::userObservablePageCount):
(WebKit::WebContext::processSuppressionDisabledForPageCount):
- count() -> token<>(), changed return type.
* UIProcess/WebPageProxy.h:
- changed types of token members.
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::updateProcessSuppressionState):
renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken.
Source/WTF:
* wtf/RefCounter.cpp:
(WTF::RefCounter::Count::ref):
(WTF::RefCounter::Count::deref):
- only call the callback on zero-edge changes; provide the value.
(WTF::RefCounter::RefCounter):
- callback now takes a bool argument.
* wtf/RefCounter.h:
(WTF::RefCounter::Token::Token):
- New opaque type to reference the RefCounter::Count.
(WTF::RefCounter::Token::operator!):
- ! operator checks for null / anasigned Tokens.
(WTF::RefCounter::RefCounter):
- callback now takes a bool argument.
(WTF::RefCounter::token):
- renamed from count(), templated on type of token returned.
(WTF::RefCounter::value):
- now returns a bool.
(WTF::RefCounter::Token<T>::Token):
(WTF::=):
- Tokens can be copied & assigned.
(WTF::RefCounter::count): Deleted.
- renamed to token<>().
Tools:
* TestWebKitAPI/Tests/WTF/RefCounter.cpp:
(TestWebKitAPI::TEST):
- update API test.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@177541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed