Commit ae86fc7d authored by tkent@chromium.org's avatar tkent@chromium.org

Oilpan: Prepare to move AbstractSQLStatement, SQLStatement, and...

Oilpan: Prepare to move AbstractSQLStatement, SQLStatement, and SQLCallbackWrapper<T> to Oilpan heap.

SQLCallbackWrapper has code to call ExecutionContext::deref() in the origin
thread. This is unnecessary in Oilpan because implementation classes of
ExecutionContext are already on-heap and they are always destructed in their
origin threads.

This is a prepration to make ExecutionContext GarbageCollected.

BUG=357163

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

git-svn-id: svn://svn.chromium.org/blink/trunk@175610 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 42b829e5
......@@ -26,15 +26,16 @@
#ifndef AbstractSQLStatement_h
#define AbstractSQLStatement_h
#include "wtf/ThreadSafeRefCounted.h"
#include "platform/heap/Handle.h"
namespace WebCore {
class AbstractSQLStatementBackend;
class AbstractSQLStatement {
class AbstractSQLStatement : public NoBaseWillBeGarbageCollectedFinalized<AbstractSQLStatement> {
public:
virtual ~AbstractSQLStatement() { }
virtual void trace(Visitor*) { }
virtual void setBackend(AbstractSQLStatementBackend*) = 0;
......
......@@ -49,7 +49,7 @@ public:
virtual AbstractSQLStatement* currentStatement() = 0;
virtual void setShouldRetryCurrentStatement(bool) = 0;
virtual void executeSQL(PassOwnPtr<AbstractSQLStatement>, const String& statement,
virtual void executeSQL(PassOwnPtrWillBeRawPtr<AbstractSQLStatement>, const String& statement,
const Vector<SQLValue>& arguments, int permissions) = 0;
};
......
......@@ -40,7 +40,9 @@ namespace WebCore {
// - by destructing the enclosing wrapper - on any thread
// - by calling clear() - on any thread
// - by unwrapping and then dereferencing normally - on context thread only
// Oilpan: ~T must be thread-independent.
template<typename T> class SQLCallbackWrapper {
DISALLOW_ALLOCATION();
public:
SQLCallbackWrapper(PassOwnPtr<T> callback, ExecutionContext* executionContext)
: m_callback(callback)
......@@ -54,8 +56,19 @@ public:
clear();
}
// FIXME: Oilpan: Trace m_executionContext.
void trace(Visitor* visitor) { }
void clear()
{
#if ENABLE(OILPAN)
// It's safe to call ~T in non-context-thread.
// Implementation classes of ExecutionContext are on-heap. Their
// destructors are called in their owner threads.
MutexLocker locker(m_mutex);
m_callback.clear();
m_executionContext.clear();
#else
ExecutionContext* context;
OwnPtr<T> callback;
{
......@@ -73,6 +86,7 @@ public:
callback = m_callback.release();
}
context->postTask(SafeReleaseTask::create(callback.release()));
#endif
}
PassOwnPtr<T> unwrap()
......@@ -87,6 +101,7 @@ public:
bool hasCallback() const { return m_callback; }
private:
#if !ENABLE(OILPAN)
class SafeReleaseTask : public ExecutionContextTask {
public:
static PassOwnPtr<SafeReleaseTask> create(PassOwnPtr<T> callbackToRelease)
......@@ -111,6 +126,7 @@ private:
OwnPtr<T> m_callbackToRelease;
};
#endif
Mutex m_mutex;
OwnPtr<T> m_callback;
......
......@@ -42,10 +42,10 @@
namespace WebCore {
PassOwnPtr<SQLStatement> SQLStatement::create(Database* database,
PassOwnPtrWillBeRawPtr<SQLStatement> SQLStatement::create(Database* database,
PassOwnPtr<SQLStatementCallback> callback, PassOwnPtr<SQLStatementErrorCallback> errorCallback)
{
return adoptPtr(new SQLStatement(database, callback, errorCallback));
return adoptPtrWillBeNoop(new SQLStatement(database, callback, errorCallback));
}
SQLStatement::SQLStatement(Database* database, PassOwnPtr<SQLStatementCallback> callback,
......@@ -55,6 +55,14 @@ SQLStatement::SQLStatement(Database* database, PassOwnPtr<SQLStatementCallback>
{
}
void SQLStatement::trace(Visitor* visitor)
{
visitor->trace(m_backend);
visitor->trace(m_statementCallbackWrapper);
visitor->trace(m_statementErrorCallbackWrapper);
AbstractSQLStatement::trace(visitor);
}
void SQLStatement::setBackend(AbstractSQLStatementBackend* backend)
{
m_backend = backend;
......
......@@ -47,8 +47,9 @@ class SQLTransaction;
class SQLStatement FINAL : public AbstractSQLStatement {
public:
static PassOwnPtr<SQLStatement> create(Database*,
static PassOwnPtrWillBeRawPtr<SQLStatement> create(Database*,
PassOwnPtr<SQLStatementCallback>, PassOwnPtr<SQLStatementErrorCallback>);
virtual void trace(Visitor*) OVERRIDE;
bool performCallback(SQLTransaction*);
......@@ -63,7 +64,7 @@ private:
// The AbstractSQLStatementBackend owns the SQLStatement. Hence, the backend is
// guaranteed to be outlive the SQLStatement, and it is safe for us to refer
// to the backend using a raw pointer here.
AbstractSQLStatementBackend* m_backend;
RawPtrWillBeMember<AbstractSQLStatementBackend> m_backend;
SQLCallbackWrapper<SQLStatementCallback> m_statementCallbackWrapper;
SQLCallbackWrapper<SQLStatementErrorCallback> m_statementErrorCallbackWrapper;
......
......@@ -71,13 +71,13 @@
namespace WebCore {
PassRefPtrWillBeRawPtr<SQLStatementBackend> SQLStatementBackend::create(PassOwnPtr<AbstractSQLStatement> frontend,
PassRefPtrWillBeRawPtr<SQLStatementBackend> SQLStatementBackend::create(PassOwnPtrWillBeRawPtr<AbstractSQLStatement> frontend,
const String& statement, const Vector<SQLValue>& arguments, int permissions)
{
return adoptRefWillBeNoop(new SQLStatementBackend(frontend, statement, arguments, permissions));
}
SQLStatementBackend::SQLStatementBackend(PassOwnPtr<AbstractSQLStatement> frontend,
SQLStatementBackend::SQLStatementBackend(PassOwnPtrWillBeRawPtr<AbstractSQLStatement> frontend,
const String& statement, const Vector<SQLValue>& arguments, int permissions)
: m_frontend(frontend)
, m_statement(statement.isolatedCopy())
......@@ -92,6 +92,7 @@ SQLStatementBackend::SQLStatementBackend(PassOwnPtr<AbstractSQLStatement> fronte
void SQLStatementBackend::trace(Visitor* visitor)
{
visitor->trace(m_frontend);
visitor->trace(m_resultSet);
AbstractSQLStatementBackend::trace(visitor);
}
......
......@@ -44,7 +44,7 @@ class SQLTransactionBackend;
class SQLStatementBackend FINAL : public AbstractSQLStatementBackend {
public:
static PassRefPtrWillBeRawPtr<SQLStatementBackend> create(PassOwnPtr<AbstractSQLStatement>,
static PassRefPtrWillBeRawPtr<SQLStatementBackend> create(PassOwnPtrWillBeRawPtr<AbstractSQLStatement>,
const String& sqlStatement, const Vector<SQLValue>& arguments, int permissions);
virtual void trace(Visitor*) OVERRIDE;
......@@ -61,13 +61,13 @@ public:
virtual SQLResultSet* sqlResultSet() const OVERRIDE;
private:
SQLStatementBackend(PassOwnPtr<AbstractSQLStatement>, const String& statement,
SQLStatementBackend(PassOwnPtrWillBeRawPtr<AbstractSQLStatement>, const String& statement,
const Vector<SQLValue>& arguments, int permissions);
void setFailureDueToQuota(DatabaseBackend*);
void clearFailureDueToQuota();
OwnPtr<AbstractSQLStatement> m_frontend;
OwnPtrWillBeMember<AbstractSQLStatement> m_frontend;
String m_statement;
Vector<SQLValue> m_arguments;
bool m_hasCallback;
......
......@@ -73,6 +73,9 @@ void SQLTransaction::trace(Visitor* visitor)
{
visitor->trace(m_database);
visitor->trace(m_backend);
visitor->trace(m_callbackWrapper);
visitor->trace(m_successCallbackWrapper);
visitor->trace(m_errorCallbackWrapper);
AbstractSQLTransaction::trace(visitor);
}
......@@ -278,7 +281,7 @@ void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValu
else if (m_readOnly)
permissions |= DatabaseAuthorizer::ReadOnlyMask;
OwnPtr<SQLStatement> statement = SQLStatement::create(m_database.get(), callback, callbackError);
OwnPtrWillBeRawPtr<SQLStatement> statement = SQLStatement::create(m_database.get(), callback, callbackError);
m_backend->executeSQL(statement.release(), sqlStatement, arguments, permissions);
}
......
......@@ -526,7 +526,7 @@ void SQLTransactionBackend::performNextStep()
runStateMachine();
}
void SQLTransactionBackend::executeSQL(PassOwnPtr<AbstractSQLStatement> statement,
void SQLTransactionBackend::executeSQL(PassOwnPtrWillBeRawPtr<AbstractSQLStatement> statement,
const String& sqlStatement, const Vector<SQLValue>& arguments, int permissions)
{
enqueueStatementBackend(SQLStatementBackend::create(statement, sqlStatement, arguments, permissions));
......
......@@ -82,7 +82,7 @@ private:
virtual SQLErrorData* transactionError() OVERRIDE;
virtual AbstractSQLStatement* currentStatement() OVERRIDE;
virtual void setShouldRetryCurrentStatement(bool) OVERRIDE;
virtual void executeSQL(PassOwnPtr<AbstractSQLStatement>, const String& statement,
virtual void executeSQL(PassOwnPtrWillBeRawPtr<AbstractSQLStatement>, const String& statement,
const Vector<SQLValue>& arguments, int permissions) OVERRIDE;
void doCleanup();
......
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