2013-12-13 00:42:14 +00:00
|
|
|
/*
|
2016-05-31 03:35:44 +00:00
|
|
|
* Copyright (C) 2013, 2015, 2016 Apple Inc. All rights reserved.
|
2013-12-13 00:42:14 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-05-31 03:35:44 +00:00
|
|
|
#pragma once
|
2013-12-13 00:42:14 +00:00
|
|
|
|
2016-05-31 03:35:44 +00:00
|
|
|
#include <wtf/CrossThreadCopier.h>
|
2016-06-24 19:40:19 +00:00
|
|
|
#include <wtf/Function.h>
|
2019-03-11 20:06:55 +00:00
|
|
|
#include <wtf/RefPtr.h>
|
2016-05-31 19:33:22 +00:00
|
|
|
#include <wtf/StdLibExtras.h>
|
2019-03-11 20:06:55 +00:00
|
|
|
#include <wtf/ThreadSafeRefCounted.h>
|
2013-12-13 00:42:14 +00:00
|
|
|
|
2016-05-31 03:35:44 +00:00
|
|
|
namespace WTF {
|
2013-12-13 00:42:14 +00:00
|
|
|
|
2015-09-29 23:28:22 +00:00
|
|
|
class CrossThreadTask {
|
2019-08-12 20:57:15 +00:00
|
|
|
WTF_MAKE_FAST_ALLOCATED;
|
2013-12-13 00:42:14 +00:00
|
|
|
public:
|
2016-05-31 19:33:22 +00:00
|
|
|
CrossThreadTask() = default;
|
|
|
|
|
2016-06-24 19:40:19 +00:00
|
|
|
CrossThreadTask(Function<void ()>&& taskFunction)
|
2016-05-31 03:35:44 +00:00
|
|
|
: m_taskFunction(WTFMove(taskFunction))
|
Abstractify WebOriginDataManager to support arbitrary ChildProcess supplements.
https://bugs.webkit.org/show_bug.cgi?id=137993
Reviewed by Brady Eidson.
To allow different ChildProcess subclasses to handle listing and deletion of origin
data, make WebOriginDataManager more generic by having a supplement implement the
details, leaving WebOriginDataManager to deal with cross-process messaging.
De-virtualize AsyncTask, allowing a task to be created by passing in a
function<void()>, rather than an object, method, and arguments.
* Shared/AsyncTask.h:
(WebKit::AsyncTask::AsyncTask):
(WebKit::AsyncTask::performTask):
(WebKit::AsyncTask::~AsyncTask): Deleted.
Add a new virtual base class, to be implemented by various ChildProcesses, which
WebOriginDataManager will use to implement listing and deletion requests.
* WebProcess/OriginData/WebOriginDataManager.h:
* WebProcess/OriginData/WebOriginDataManagerSupplement.h: Added.
(WebKit::WebOriginDataManagerSupplement::WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::~WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::getOrigins):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesForOrigin):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManagerSupplement::deleteAllEntries):
* WebKit2.xcodeproj/project.pbxproj:
WebOriginDataManager doesn't need to be a ChildSupplement. Remove the DatabaseProcess-
specific implementations for its message handlers and replace with clean, generic calls
to its supplement. Because these supplements may want to respond to the request
asynchronously, pass a completion function in to be called by the supplement once its
work is complete.
* WebProcess/OriginData/WebOriginDataManager.cpp:
(WebKit::WebOriginDataManager::WebOriginDataManager):
(WebKit::WebOriginDataManager::getOrigins):
(WebKit::WebOriginDataManager::deleteEntriesForOrigin):
(WebKit::WebOriginDataManager::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManager::deleteAllEntries):
(WebKit::WebOriginDataManager::supplementName): Deleted.
DatabaseProcess already uses WebOriginDataManager, so it will be the first process
to fall under the heel of the new regime. DatabaseProcess will subclass
WebOriginDataManagerSupplement, and pass itself in twice to the WebOriginDataManager
constructor. Create a lambda-based AsyncTask for each request, and call the completion
function when each request is complete.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::DatabaseProcess):
(WebKit::DatabaseProcess::getIndexedDatabaseOrigins):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesForOrigin):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllIndexedDatabaseEntries):
(WebKit::DatabaseProcess::getOrigins):
(WebKit::DatabaseProcess::deleteEntriesForOrigin):
(WebKit::DatabaseProcess::deleteEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllEntries):
(WebKit::DatabaseProcess::doGetIndexedDatabaseOrigins): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesForOrigin): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesModifiedBetweenDates): Deleted.
(WebKit::DatabaseProcess::doDeleteAllIndexedDatabaseEntries): Deleted.
* DatabaseProcess/DatabaseProcess.h:
Canonical link: https://commits.webkit.org/155925@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175188 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-10-24 23:01:54 +00:00
|
|
|
{
|
2016-06-08 17:31:47 +00:00
|
|
|
ASSERT(m_taskFunction);
|
Abstractify WebOriginDataManager to support arbitrary ChildProcess supplements.
https://bugs.webkit.org/show_bug.cgi?id=137993
Reviewed by Brady Eidson.
To allow different ChildProcess subclasses to handle listing and deletion of origin
data, make WebOriginDataManager more generic by having a supplement implement the
details, leaving WebOriginDataManager to deal with cross-process messaging.
De-virtualize AsyncTask, allowing a task to be created by passing in a
function<void()>, rather than an object, method, and arguments.
* Shared/AsyncTask.h:
(WebKit::AsyncTask::AsyncTask):
(WebKit::AsyncTask::performTask):
(WebKit::AsyncTask::~AsyncTask): Deleted.
Add a new virtual base class, to be implemented by various ChildProcesses, which
WebOriginDataManager will use to implement listing and deletion requests.
* WebProcess/OriginData/WebOriginDataManager.h:
* WebProcess/OriginData/WebOriginDataManagerSupplement.h: Added.
(WebKit::WebOriginDataManagerSupplement::WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::~WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::getOrigins):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesForOrigin):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManagerSupplement::deleteAllEntries):
* WebKit2.xcodeproj/project.pbxproj:
WebOriginDataManager doesn't need to be a ChildSupplement. Remove the DatabaseProcess-
specific implementations for its message handlers and replace with clean, generic calls
to its supplement. Because these supplements may want to respond to the request
asynchronously, pass a completion function in to be called by the supplement once its
work is complete.
* WebProcess/OriginData/WebOriginDataManager.cpp:
(WebKit::WebOriginDataManager::WebOriginDataManager):
(WebKit::WebOriginDataManager::getOrigins):
(WebKit::WebOriginDataManager::deleteEntriesForOrigin):
(WebKit::WebOriginDataManager::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManager::deleteAllEntries):
(WebKit::WebOriginDataManager::supplementName): Deleted.
DatabaseProcess already uses WebOriginDataManager, so it will be the first process
to fall under the heel of the new regime. DatabaseProcess will subclass
WebOriginDataManagerSupplement, and pass itself in twice to the WebOriginDataManager
constructor. Create a lambda-based AsyncTask for each request, and call the completion
function when each request is complete.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::DatabaseProcess):
(WebKit::DatabaseProcess::getIndexedDatabaseOrigins):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesForOrigin):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllIndexedDatabaseEntries):
(WebKit::DatabaseProcess::getOrigins):
(WebKit::DatabaseProcess::deleteEntriesForOrigin):
(WebKit::DatabaseProcess::deleteEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllEntries):
(WebKit::DatabaseProcess::doGetIndexedDatabaseOrigins): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesForOrigin): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesModifiedBetweenDates): Deleted.
(WebKit::DatabaseProcess::doDeleteAllIndexedDatabaseEntries): Deleted.
* DatabaseProcess/DatabaseProcess.h:
Canonical link: https://commits.webkit.org/155925@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175188 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-10-24 23:01:54 +00:00
|
|
|
}
|
2013-12-13 00:42:14 +00:00
|
|
|
|
Abstractify WebOriginDataManager to support arbitrary ChildProcess supplements.
https://bugs.webkit.org/show_bug.cgi?id=137993
Reviewed by Brady Eidson.
To allow different ChildProcess subclasses to handle listing and deletion of origin
data, make WebOriginDataManager more generic by having a supplement implement the
details, leaving WebOriginDataManager to deal with cross-process messaging.
De-virtualize AsyncTask, allowing a task to be created by passing in a
function<void()>, rather than an object, method, and arguments.
* Shared/AsyncTask.h:
(WebKit::AsyncTask::AsyncTask):
(WebKit::AsyncTask::performTask):
(WebKit::AsyncTask::~AsyncTask): Deleted.
Add a new virtual base class, to be implemented by various ChildProcesses, which
WebOriginDataManager will use to implement listing and deletion requests.
* WebProcess/OriginData/WebOriginDataManager.h:
* WebProcess/OriginData/WebOriginDataManagerSupplement.h: Added.
(WebKit::WebOriginDataManagerSupplement::WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::~WebOriginDataManagerSupplement):
(WebKit::WebOriginDataManagerSupplement::getOrigins):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesForOrigin):
(WebKit::WebOriginDataManagerSupplement::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManagerSupplement::deleteAllEntries):
* WebKit2.xcodeproj/project.pbxproj:
WebOriginDataManager doesn't need to be a ChildSupplement. Remove the DatabaseProcess-
specific implementations for its message handlers and replace with clean, generic calls
to its supplement. Because these supplements may want to respond to the request
asynchronously, pass a completion function in to be called by the supplement once its
work is complete.
* WebProcess/OriginData/WebOriginDataManager.cpp:
(WebKit::WebOriginDataManager::WebOriginDataManager):
(WebKit::WebOriginDataManager::getOrigins):
(WebKit::WebOriginDataManager::deleteEntriesForOrigin):
(WebKit::WebOriginDataManager::deleteEntriesModifiedBetweenDates):
(WebKit::WebOriginDataManager::deleteAllEntries):
(WebKit::WebOriginDataManager::supplementName): Deleted.
DatabaseProcess already uses WebOriginDataManager, so it will be the first process
to fall under the heel of the new regime. DatabaseProcess will subclass
WebOriginDataManagerSupplement, and pass itself in twice to the WebOriginDataManager
constructor. Create a lambda-based AsyncTask for each request, and call the completion
function when each request is complete.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::DatabaseProcess):
(WebKit::DatabaseProcess::getIndexedDatabaseOrigins):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesForOrigin):
(WebKit::DatabaseProcess::deleteIndexedDatabaseEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllIndexedDatabaseEntries):
(WebKit::DatabaseProcess::getOrigins):
(WebKit::DatabaseProcess::deleteEntriesForOrigin):
(WebKit::DatabaseProcess::deleteEntriesModifiedBetweenDates):
(WebKit::DatabaseProcess::deleteAllEntries):
(WebKit::DatabaseProcess::doGetIndexedDatabaseOrigins): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesForOrigin): Deleted.
(WebKit::DatabaseProcess::doDeleteIndexedDatabaseEntriesModifiedBetweenDates): Deleted.
(WebKit::DatabaseProcess::doDeleteAllIndexedDatabaseEntries): Deleted.
* DatabaseProcess/DatabaseProcess.h:
Canonical link: https://commits.webkit.org/155925@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175188 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-10-24 23:01:54 +00:00
|
|
|
void performTask()
|
|
|
|
{
|
|
|
|
m_taskFunction();
|
|
|
|
}
|
2013-12-13 00:42:14 +00:00
|
|
|
|
2021-05-27 21:55:40 +00:00
|
|
|
explicit operator bool() const { return !!m_taskFunction; }
|
|
|
|
|
2013-12-13 00:42:14 +00:00
|
|
|
protected:
|
2016-06-24 19:40:19 +00:00
|
|
|
Function<void ()> m_taskFunction;
|
2013-12-13 00:42:14 +00:00
|
|
|
};
|
|
|
|
|
2016-06-09 17:34:55 +00:00
|
|
|
template <typename F, typename ArgsTuple, size_t... ArgsIndex>
|
|
|
|
void callFunctionForCrossThreadTaskImpl(F function, ArgsTuple&& args, std::index_sequence<ArgsIndex...>)
|
2013-12-13 00:42:14 +00:00
|
|
|
{
|
2016-06-09 17:34:55 +00:00
|
|
|
function(std::get<ArgsIndex>(std::forward<ArgsTuple>(args))...);
|
2013-12-13 00:42:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 17:42:41 +00:00
|
|
|
template <typename F, typename ArgsTuple, typename ArgsIndices = std::make_index_sequence<std::tuple_size<ArgsTuple>::value>>
|
2016-06-09 17:34:55 +00:00
|
|
|
void callFunctionForCrossThreadTask(F function, ArgsTuple&& args)
|
2013-12-13 00:42:14 +00:00
|
|
|
{
|
2016-06-09 17:42:41 +00:00
|
|
|
callFunctionForCrossThreadTaskImpl(function, std::forward<ArgsTuple>(args), ArgsIndices());
|
2013-12-13 00:42:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 17:34:55 +00:00
|
|
|
template<typename... Parameters, typename... Arguments>
|
|
|
|
CrossThreadTask createCrossThreadTask(void (*method)(Parameters...), const Arguments&... arguments)
|
2013-12-18 00:12:50 +00:00
|
|
|
{
|
2019-06-20 00:51:30 +00:00
|
|
|
return CrossThreadTask([method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
|
2016-06-09 17:34:55 +00:00
|
|
|
callFunctionForCrossThreadTask(method, WTFMove(arguments));
|
2016-06-08 17:31:47 +00:00
|
|
|
});
|
2013-12-18 00:12:50 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 17:34:55 +00:00
|
|
|
template <typename C, typename MF, typename ArgsTuple, size_t... ArgsIndex>
|
|
|
|
void callMemberFunctionForCrossThreadTaskImpl(C* object, MF function, ArgsTuple&& args, std::index_sequence<ArgsIndex...>)
|
2016-04-14 00:54:10 +00:00
|
|
|
{
|
2016-06-09 17:34:55 +00:00
|
|
|
(object->*function)(std::get<ArgsIndex>(std::forward<ArgsTuple>(args))...);
|
2016-04-14 00:54:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 17:34:55 +00:00
|
|
|
template <typename C, typename MF, typename ArgsTuple, typename ArgsIndicies = std::make_index_sequence<std::tuple_size<ArgsTuple>::value>>
|
|
|
|
void callMemberFunctionForCrossThreadTask(C* object, MF function, ArgsTuple&& args)
|
2014-01-22 23:48:27 +00:00
|
|
|
{
|
2016-06-09 17:34:55 +00:00
|
|
|
callMemberFunctionForCrossThreadTaskImpl(object, function, std::forward<ArgsTuple>(args), ArgsIndicies());
|
2014-01-31 20:50:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 01:33:10 +00:00
|
|
|
template<typename T, typename std::enable_if<std::is_base_of<ThreadSafeRefCountedBase, T>::value, int>::type = 0, typename... Parameters, typename... Arguments>
|
2019-03-11 20:06:55 +00:00
|
|
|
CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments)
|
|
|
|
{
|
2019-06-20 00:51:30 +00:00
|
|
|
return CrossThreadTask([callee = makeRefPtr(&callee), method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
|
2019-03-11 20:06:55 +00:00
|
|
|
callMemberFunctionForCrossThreadTask(callee.get(), method, WTFMove(arguments));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-22 01:33:10 +00:00
|
|
|
template<typename T, typename std::enable_if<!std::is_base_of<ThreadSafeRefCountedBase, T>::value, int>::type = 0, typename... Parameters, typename... Arguments>
|
2016-06-09 17:34:55 +00:00
|
|
|
CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments)
|
2014-01-22 23:48:27 +00:00
|
|
|
{
|
2019-06-20 00:51:30 +00:00
|
|
|
return CrossThreadTask([callee = &callee, method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
|
2016-06-09 17:34:55 +00:00
|
|
|
callMemberFunctionForCrossThreadTask(callee, method, WTFMove(arguments));
|
2016-06-08 17:31:47 +00:00
|
|
|
});
|
2014-01-22 23:48:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 03:35:44 +00:00
|
|
|
} // namespace WTF
|
2013-12-13 00:42:14 +00:00
|
|
|
|
2016-05-31 03:35:44 +00:00
|
|
|
using WTF::CrossThreadTask;
|
|
|
|
using WTF::createCrossThreadTask;
|