Commit e3e8f25e authored by jsbell@chromium.org's avatar jsbell@chromium.org

IndexedDB: Make IndexedDBDatabaseError non-RefCounted

BUG=234278
R=alecflett@chromium.org

Review URL: https://chromiumcodereview.appspot.com/15927032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204080 0039d316-1c4b-4281-b951-d872f2087c98
parent aba67044
......@@ -29,11 +29,10 @@ IndexedDBCallbacksWrapper::IndexedDBCallbacksWrapper(
IndexedDBCallbacksWrapper::~IndexedDBCallbacksWrapper() {}
void IndexedDBCallbacksWrapper::OnError(
scoped_refptr<IndexedDBDatabaseError> error) {
void IndexedDBCallbacksWrapper::OnError(const IndexedDBDatabaseError& error) {
DCHECK(callbacks_);
callbacks_->onError(
WebKit::WebIDBDatabaseError(error->code(), error->message()));
WebKit::WebIDBDatabaseError(error.code(), error.message()));
callbacks_.reset();
}
......
......@@ -34,7 +34,7 @@ class CONTENT_EXPORT IndexedDBCallbacksWrapper
return make_scoped_refptr(new IndexedDBCallbacksWrapper(callbacks));
}
virtual void OnError(scoped_refptr<IndexedDBDatabaseError> error);
virtual void OnError(const IndexedDBDatabaseError& error);
// From IDBFactory.webkitGetDatabaseNames()
virtual void OnSuccess(const std::vector<string16>& string);
// From IDBObjectStore/IDBIndex.openCursor(),
......
......@@ -47,7 +47,7 @@ class IndexedDBDatabase : public base::RefCounted<IndexedDBDatabase> {
virtual void Commit(int64 transaction_id) = 0;
virtual void Abort(int64 transaction_id) = 0;
virtual void Abort(int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error) = 0;
const IndexedDBDatabaseError& error) = 0;
virtual void CreateIndex(int64 transaction_id,
int64 object_store_id,
......
......@@ -26,12 +26,12 @@ void IndexedDBDatabaseCallbacksWrapper::OnVersionChange(int64 old_version,
void IndexedDBDatabaseCallbacksWrapper::OnAbort(
int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error) {
const IndexedDBDatabaseError& error) {
if (!callbacks_)
return;
callbacks_->onAbort(
transaction_id,
WebKit::WebIDBDatabaseError(error->code(), error->message()));
WebKit::WebIDBDatabaseError(error.code(), error.message()));
}
void IndexedDBDatabaseCallbacksWrapper::OnComplete(int64 transaction_id) {
if (!callbacks_)
......
......@@ -27,7 +27,7 @@ class CONTENT_EXPORT IndexedDBDatabaseCallbacksWrapper
virtual void OnVersionChange(int64 old_version, int64 new_version);
virtual void OnAbort(int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error);
const IndexedDBDatabaseError& error);
virtual void OnComplete(int64 transaction_id);
protected:
......
......@@ -6,34 +6,26 @@
#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_ERROR_H_
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/WebKit/public/platform/WebIDBDatabaseError.h"
namespace content {
class IndexedDBDatabaseError : public base::RefCounted<IndexedDBDatabaseError> {
class IndexedDBDatabaseError {
public:
static scoped_refptr<IndexedDBDatabaseError> Create(uint16 code,
const string16& message) {
// TODO(jsbell): Assert that this is a valid WebIDBDatabaseException code.
return make_scoped_refptr(new IndexedDBDatabaseError(code, message));
}
static scoped_refptr<IndexedDBDatabaseError> Create(
const WebKit::WebIDBDatabaseError& other) {
return make_scoped_refptr(
new IndexedDBDatabaseError(other.code(), other.message()));
}
IndexedDBDatabaseError(uint16 code, const char* message)
: code_(code), message_(ASCIIToUTF16(message)) {}
IndexedDBDatabaseError(uint16 code, const string16& message)
: code_(code), message_(message) {}
IndexedDBDatabaseError(const WebKit::WebIDBDatabaseError& other)
: code_(other.code()), message_(other.message()) {}
~IndexedDBDatabaseError() {}
uint16 code() const { return code_; }
const string16& message() const { return message_; }
private:
IndexedDBDatabaseError(uint16 code, const string16& message)
: code_(code), message_(message) {}
~IndexedDBDatabaseError() {}
friend class base::RefCounted<IndexedDBDatabaseError>;
const uint16 code_;
const string16 message_;
};
......
......@@ -68,8 +68,8 @@ class CONTENT_EXPORT IndexedDBDatabaseImpl
virtual void Commit(int64 transaction_id) OVERRIDE;
virtual void Abort(int64 transaction_id) OVERRIDE;
virtual void Abort(int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error) OVERRIDE;
virtual void Abort(int64 transaction_id, const IndexedDBDatabaseError& error)
OVERRIDE;
virtual void CreateIndex(int64 transaction_id,
int64 object_store_id,
......
......@@ -47,7 +47,7 @@ class MockIDBCallbacks : public IndexedDBCallbacksWrapper {
static scoped_refptr<MockIDBCallbacks> Create() {
return make_scoped_refptr(new MockIDBCallbacks());
}
virtual void OnError(scoped_refptr<IndexedDBDatabaseError>) OVERRIDE {}
virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE {}
virtual void OnSuccess(const std::vector<string16>&) OVERRIDE {}
virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
const IndexedDBKey&,
......@@ -87,7 +87,7 @@ class FakeIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacksWrapper {
virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {}
virtual void OnForcedClose() OVERRIDE {}
virtual void OnAbort(int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error) OVERRIDE {}
const IndexedDBDatabaseError& error) OVERRIDE {}
virtual void OnComplete(int64 transaction_id) OVERRIDE {}
private:
......@@ -151,7 +151,7 @@ class MockIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacksWrapper {
virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {}
virtual void OnForcedClose() OVERRIDE {}
virtual void OnAbort(int64 transaction_id,
scoped_refptr<IndexedDBDatabaseError> error) OVERRIDE {
const IndexedDBDatabaseError& error) OVERRIDE {
was_abort_called_ = true;
}
virtual void OnComplete(int64 transaction_id) OVERRIDE {}
......@@ -176,7 +176,7 @@ class WebIDBDatabaseCallbacksImpl : public WebIDBDatabaseCallbacks {
}
virtual void onAbort(long long transaction_id,
const WebIDBDatabaseError& error) {
callbacks_->OnAbort(transaction_id, IndexedDBDatabaseError::Create(error));
callbacks_->OnAbort(transaction_id, IndexedDBDatabaseError(error));
}
virtual void onComplete(long long transaction_id) {
callbacks_->OnComplete(transaction_id);
......
......@@ -58,10 +58,10 @@ void IndexedDBFactoryImpl::GetDatabaseNames(
scoped_refptr<IndexedDBBackingStore> backing_store =
OpenBackingStore(database_identifier, data_directory);
if (!backing_store) {
callbacks->OnError(IndexedDBDatabaseError::Create(
callbacks->OnError(IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16("Internal error opening backing store for "
"indexed_db.webkit_get_database_names.")));
"Internal error opening backing store for "
"indexed_db.webkit_get_database_names."));
return;
}
......@@ -90,7 +90,7 @@ void IndexedDBFactoryImpl::DeleteDatabase(
scoped_refptr<IndexedDBBackingStore> backing_store =
OpenBackingStore(database_identifier, data_directory);
if (!backing_store) {
callbacks->OnError(IndexedDBDatabaseError::Create(
callbacks->OnError(IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16("Internal error opening backing store "
"for indexed_db.delete_database.")));
......@@ -101,7 +101,7 @@ void IndexedDBFactoryImpl::DeleteDatabase(
IndexedDBDatabaseImpl::Create(
name, backing_store.get(), this, unique_identifier);
if (!database_backend) {
callbacks->OnError(IndexedDBDatabaseError::Create(
callbacks->OnError(IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16("Internal error creating database backend for "
"indexed_db.delete_database.")));
......@@ -168,7 +168,7 @@ void IndexedDBFactoryImpl::Open(
scoped_refptr<IndexedDBBackingStore> backing_store =
OpenBackingStore(database_identifier, data_directory);
if (!backing_store) {
callbacks->OnError(IndexedDBDatabaseError::Create(
callbacks->OnError(IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16(
"Internal error opening backing store for indexedDB.open.")));
......@@ -178,7 +178,7 @@ void IndexedDBFactoryImpl::Open(
database_backend = IndexedDBDatabaseImpl::Create(
name, backing_store.get(), this, unique_identifier);
if (!database_backend) {
callbacks->OnError(IndexedDBDatabaseError::Create(
callbacks->OnError(IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16(
"Internal error creating database backend for indexedDB.open.")));
......
......@@ -114,12 +114,11 @@ void IndexedDBTransaction::ScheduleTask(IndexedDBDatabase::TaskType type,
}
void IndexedDBTransaction::Abort() {
Abort(IndexedDBDatabaseError::Create(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16("Internal error (unknown cause)")));
Abort(IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
"Internal error (unknown cause)"));
}
void IndexedDBTransaction::Abort(scoped_refptr<IndexedDBDatabaseError> error) {
void IndexedDBTransaction::Abort(const IndexedDBDatabaseError& error) {
IDB_TRACE("IndexedDBTransaction::abort");
if (state_ == FINISHED)
return;
......@@ -255,9 +254,9 @@ void IndexedDBTransaction::Commit() {
} else {
callbacks_->OnAbort(
id_,
IndexedDBDatabaseError::Create(
IndexedDBDatabaseError(
WebKit::WebIDBDatabaseExceptionUnknownError,
ASCIIToUTF16("Internal error committing transaction.")));
"Internal error committing transaction."));
database_->TransactionFinishedAndAbortFired(this);
}
......
......@@ -43,7 +43,7 @@ class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
virtual void Perform(IndexedDBTransaction* transaction) = 0;
};
void Abort(scoped_refptr<IndexedDBDatabaseError> error);
void Abort(const IndexedDBDatabaseError& error);
void Run();
indexed_db::TransactionMode mode() const { return mode_; }
const std::set<int64>& scope() const { return object_store_ids_; }
......
......@@ -97,8 +97,7 @@ void WebIDBDatabaseImpl::abort(long long transaction_id) {
void WebIDBDatabaseImpl::abort(long long transaction_id,
const WebIDBDatabaseError& error) {
if (database_backend_)
database_backend_->Abort(transaction_id,
IndexedDBDatabaseError::Create(error));
database_backend_->Abort(transaction_id, IndexedDBDatabaseError(error));
}
void WebIDBDatabaseImpl::commit(long long transaction_id) {
......
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