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