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