| Index: content/browser/indexed_db/indexed_db_database.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc
|
| index 8d6329326870f26042825f07609a68d5320c04d3..bc745c25d3025e50b97dd0d8dece7cb7cecf5348 100644
|
| --- a/content/browser/indexed_db/indexed_db_database.cc
|
| +++ b/content/browser/indexed_db/indexed_db_database.cc
|
| @@ -6,22 +6,27 @@
|
|
|
| #include <math.h>
|
| #include <set>
|
| +#include <vector>
|
|
|
| #include "base/auto_reset.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/scoped_vector.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "content/browser/indexed_db/indexed_db_blob_info.h"
|
| #include "content/browser/indexed_db/indexed_db_connection.h"
|
| #include "content/browser/indexed_db/indexed_db_cursor.h"
|
| #include "content/browser/indexed_db/indexed_db_factory.h"
|
| #include "content/browser/indexed_db/indexed_db_index_writer.h"
|
| #include "content/browser/indexed_db/indexed_db_tracing.h"
|
| #include "content/browser/indexed_db/indexed_db_transaction.h"
|
| +#include "content/browser/indexed_db/indexed_db_value.h"
|
| #include "content/common/indexed_db/indexed_db_key_path.h"
|
| #include "content/common/indexed_db/indexed_db_key_range.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
|
| +#include "webkit/browser/blob/blob_data_handle.h"
|
|
|
| using base::Int64ToString16;
|
| using blink::WebIDBKeyTypeNumber;
|
| @@ -34,22 +39,26 @@ class IndexedDBDatabase::PendingOpenCall {
|
| public:
|
| PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks,
|
| scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
|
| + int child_process_id,
|
| int64 transaction_id,
|
| int64 version)
|
| : callbacks_(callbacks),
|
| database_callbacks_(database_callbacks),
|
| + child_process_id_(child_process_id),
|
| version_(version),
|
| transaction_id_(transaction_id) {}
|
| scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
|
| scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() {
|
| return database_callbacks_;
|
| }
|
| + int ChildProcessId() { return child_process_id_; }
|
| int64 Version() { return version_; }
|
| int64 TransactionId() const { return transaction_id_; }
|
|
|
| private:
|
| scoped_refptr<IndexedDBCallbacks> callbacks_;
|
| scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
|
| + int child_process_id_;
|
| int64 version_;
|
| const int64 transaction_id_;
|
| };
|
| @@ -212,6 +221,16 @@ IndexedDBDatabase::~IndexedDBDatabase() {
|
| DCHECK(pending_delete_calls_.empty());
|
| }
|
|
|
| +scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
|
| + scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
|
| + int child_process_id) {
|
| + scoped_ptr<IndexedDBConnection> connection(
|
| + new IndexedDBConnection(this, database_callbacks));
|
| + connections_.insert(connection.get());
|
| + backing_store_->GrantChildProcessPermissions(child_process_id);
|
| + return connection.Pass();
|
| +}
|
| +
|
| IndexedDBTransaction* IndexedDBDatabase::GetTransaction(
|
| int64 transaction_id) const {
|
| TransactionMap::const_iterator trans_iterator =
|
| @@ -574,7 +593,7 @@ void IndexedDBDatabase::GetOperation(
|
| bool ok;
|
| if (index_id == IndexedDBIndexMetadata::kInvalidId) {
|
| // Object Store Retrieval Operation
|
| - std::string value;
|
| + IndexedDBValue value;
|
| ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
|
| id(),
|
| object_store_id,
|
| @@ -627,7 +646,7 @@ void IndexedDBDatabase::GetOperation(
|
| }
|
|
|
| // Index Referenced Value Retrieval Operation
|
| - std::string value;
|
| + IndexedDBValue value;
|
| ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
|
| id(),
|
| object_store_id,
|
| @@ -694,7 +713,8 @@ static bool UpdateKeyGenerator(
|
| struct IndexedDBDatabase::PutOperationParams {
|
| PutOperationParams() {}
|
| int64 object_store_id;
|
| - std::string value;
|
| + IndexedDBValue value;
|
| + ScopedVector<webkit_blob::BlobDataHandle> handles;
|
| scoped_ptr<IndexedDBKey> key;
|
| IndexedDBDatabase::PutMode put_mode;
|
| scoped_refptr<IndexedDBCallbacks> callbacks;
|
| @@ -706,7 +726,8 @@ struct IndexedDBDatabase::PutOperationParams {
|
|
|
| void IndexedDBDatabase::Put(int64 transaction_id,
|
| int64 object_store_id,
|
| - std::string* value,
|
| + IndexedDBValue* value,
|
| + ScopedVector<webkit_blob::BlobDataHandle>* handles,
|
| scoped_ptr<IndexedDBKey> key,
|
| PutMode put_mode,
|
| scoped_refptr<IndexedDBCallbacks> callbacks,
|
| @@ -722,9 +743,11 @@ void IndexedDBDatabase::Put(int64 transaction_id,
|
| return;
|
|
|
| DCHECK(key);
|
| + DCHECK(value);
|
| scoped_ptr<PutOperationParams> params(new PutOperationParams());
|
| params->object_store_id = object_store_id;
|
| params->value.swap(*value);
|
| + params->handles.swap(*handles);
|
| params->key = key.Pass();
|
| params->put_mode = put_mode;
|
| params->callbacks = callbacks;
|
| @@ -824,6 +847,7 @@ void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params,
|
| params->object_store_id,
|
| *key,
|
| params->value,
|
| + ¶ms->handles,
|
| &record_identifier);
|
| if (!backing_store_success) {
|
| params->callbacks->OnError(IndexedDBDatabaseError(
|
| @@ -1055,7 +1079,7 @@ void IndexedDBDatabase::OpenCursorOperation(
|
| }
|
|
|
| if (!backing_store_cursor) {
|
| - params->callbacks->OnSuccess(static_cast<std::string*>(NULL));
|
| + params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
|
| return;
|
| }
|
|
|
| @@ -1154,28 +1178,15 @@ void IndexedDBDatabase::DeleteRangeOperation(
|
| scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation");
|
| - scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor =
|
| - backing_store_->OpenObjectStoreCursor(
|
| - transaction->BackingStoreTransaction(),
|
| - id(),
|
| - object_store_id,
|
| - *key_range,
|
| - indexed_db::CURSOR_NEXT);
|
| - if (backing_store_cursor) {
|
| - do {
|
| - if (!backing_store_->DeleteRecord(
|
| - transaction->BackingStoreTransaction(),
|
| - id(),
|
| - object_store_id,
|
| - backing_store_cursor->record_identifier())) {
|
| - callbacks->OnError(
|
| - IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
|
| - "Internal error deleting data in range"));
|
| - return;
|
| - }
|
| - } while (backing_store_cursor->Continue());
|
| + if (!backing_store_->DeleteRange(transaction->BackingStoreTransaction(),
|
| + id(),
|
| + object_store_id,
|
| + *key_range)) {
|
| + callbacks->OnError(
|
| + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
|
| + "Internal error deleting data in range"));
|
| + return;
|
| }
|
| -
|
| callbacks->OnSuccess();
|
| }
|
|
|
| @@ -1378,6 +1389,7 @@ void IndexedDBDatabase::ProcessPendingCalls() {
|
| pending_open_calls.pop_front();
|
| OpenConnection(pending_open_call->Callbacks(),
|
| pending_open_call->DatabaseCallbacks(),
|
| + pending_open_call->ChildProcessId(),
|
| pending_open_call->TransactionId(),
|
| pending_open_call->Version());
|
| }
|
| @@ -1413,17 +1425,24 @@ bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
|
| void IndexedDBDatabase::OpenConnection(
|
| scoped_refptr<IndexedDBCallbacks> callbacks,
|
| scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
|
| + int child_process_id,
|
| int64 transaction_id,
|
| int64 version) {
|
| const blink::WebIDBDataLoss kDataLoss =
|
| blink::WebIDBDataLossNone;
|
| - OpenConnection(
|
| - callbacks, database_callbacks, transaction_id, version, kDataLoss, "");
|
| + OpenConnection(callbacks,
|
| + database_callbacks,
|
| + child_process_id,
|
| + transaction_id,
|
| + version,
|
| + kDataLoss,
|
| + "");
|
| }
|
|
|
| void IndexedDBDatabase::OpenConnection(
|
| scoped_refptr<IndexedDBCallbacks> callbacks,
|
| scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
|
| + int child_process_id,
|
| int64 transaction_id,
|
| int64 version,
|
| blink::WebIDBDataLoss data_loss,
|
| @@ -1437,8 +1456,11 @@ void IndexedDBDatabase::OpenConnection(
|
| // presence of existing connections means we didn't even check for data loss
|
| // so there'd better not be any.
|
| DCHECK_NE(blink::WebIDBDataLossTotal, data_loss);
|
| - pending_open_calls_.push_back(new PendingOpenCall(
|
| - callbacks, database_callbacks, transaction_id, version));
|
| + pending_open_calls_.push_back(new PendingOpenCall(callbacks,
|
| + database_callbacks,
|
| + child_process_id,
|
| + transaction_id,
|
| + version));
|
| return;
|
| }
|
|
|
| @@ -1469,23 +1491,22 @@ void IndexedDBDatabase::OpenConnection(
|
| metadata_.version == kNoStringVersion &&
|
| metadata_.int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION;
|
|
|
| - scoped_ptr<IndexedDBConnection> connection(
|
| - new IndexedDBConnection(this, database_callbacks));
|
| -
|
| if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) {
|
| // For unit tests only - skip upgrade steps. Calling from script with
|
| // DEFAULT_INT_VERSION throws exception.
|
| // TODO(jsbell): DCHECK that not in unit tests.
|
| DCHECK(is_new_database);
|
| - connections_.insert(connection.get());
|
| - callbacks->OnSuccess(connection.Pass(), this->metadata());
|
| + callbacks->OnSuccess(
|
| + CreateConnection(database_callbacks, child_process_id),
|
| + this->metadata());
|
| return;
|
| }
|
|
|
| if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) {
|
| if (!is_new_database) {
|
| - connections_.insert(connection.get());
|
| - callbacks->OnSuccess(connection.Pass(), this->metadata());
|
| + callbacks->OnSuccess(
|
| + CreateConnection(database_callbacks, child_process_id),
|
| + this->metadata());
|
| return;
|
| }
|
| // Spec says: If no version is specified and no database exists, set
|
| @@ -1494,13 +1515,13 @@ void IndexedDBDatabase::OpenConnection(
|
| }
|
|
|
| if (version > metadata_.int_version) {
|
| - connections_.insert(connection.get());
|
| - RunVersionChangeTransaction(callbacks,
|
| - connection.Pass(),
|
| - transaction_id,
|
| - version,
|
| - data_loss,
|
| - data_loss_message);
|
| + RunVersionChangeTransaction(
|
| + callbacks,
|
| + CreateConnection(database_callbacks, child_process_id),
|
| + transaction_id,
|
| + version,
|
| + data_loss,
|
| + data_loss_message);
|
| return;
|
| }
|
| if (version < metadata_.int_version) {
|
| @@ -1512,8 +1533,9 @@ void IndexedDBDatabase::OpenConnection(
|
| return;
|
| }
|
| DCHECK_EQ(version, metadata_.int_version);
|
| - connections_.insert(connection.get());
|
| - callbacks->OnSuccess(connection.Pass(), this->metadata());
|
| + callbacks->OnSuccess(
|
| + CreateConnection(database_callbacks, child_process_id),
|
| + this->metadata());
|
| }
|
|
|
| void IndexedDBDatabase::RunVersionChangeTransaction(
|
|
|