Index: content/browser/indexed_db/indexed_db_callbacks.cc |
diff --git a/content/browser/indexed_db/indexed_db_callbacks.cc b/content/browser/indexed_db/indexed_db_callbacks.cc |
index 8783d3b1049623997bd3145a5593259b8334a222..0b8d99145d96cee479eb740c04a3ba318f164a76 100644 |
--- a/content/browser/indexed_db/indexed_db_callbacks.cc |
+++ b/content/browser/indexed_db/indexed_db_callbacks.cc |
@@ -18,28 +18,51 @@ |
#include "content/browser/indexed_db/indexed_db_connection.h" |
#include "content/browser/indexed_db/indexed_db_context_impl.h" |
#include "content/browser/indexed_db/indexed_db_cursor.h" |
-#include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
#include "content/browser/indexed_db/indexed_db_database_error.h" |
-#include "content/browser/indexed_db/indexed_db_metadata.h" |
#include "content/browser/indexed_db/indexed_db_return_value.h" |
#include "content/browser/indexed_db/indexed_db_tracing.h" |
#include "content/browser/indexed_db/indexed_db_value.h" |
#include "content/common/indexed_db/indexed_db_constants.h" |
#include "content/common/indexed_db/indexed_db_messages.h" |
+#include "content/common/indexed_db/indexed_db_metadata.h" |
#include "storage/browser/blob/blob_storage_context.h" |
#include "storage/browser/blob/shareable_file_reference.h" |
#include "storage/browser/quota/quota_manager.h" |
+using indexed_db::mojom::CallbacksAssociatedPtrInfo; |
using storage::ShareableFileReference; |
namespace content { |
namespace { |
+ |
dcheng
2016/10/17 05:33:44
Nit: be consistent with newlines surrounding the c
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
clang-format keeps eating my newlines. I need to f
|
const int32_t kNoCursor = -1; |
-const int32_t kNoDatabaseCallbacks = -1; |
const int64_t kNoTransaction = -1; |
} |
+class IndexedDBCallbacks::IOThreadHelper { |
+ public: |
+ IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info); |
dcheng
2016/10/17 05:33:44
Nit: explicit
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
Done.
|
+ ~IOThreadHelper(); |
+ |
+ void SendError(const IndexedDBDatabaseError& error); |
+ void SendSuccessStringList(const std::vector<base::string16>& value); |
+ void SendBlocked(int64_t existing_version); |
+ void SendUpgradeNeeded(int32_t database_id, |
+ int64_t old_version, |
+ blink::WebIDBDataLoss data_loss, |
+ const std::string& data_loss_message, |
+ const content::IndexedDBDatabaseMetadata& metadata); |
+ void SendSuccessDatabase(int32_t database_id, |
+ const content::IndexedDBDatabaseMetadata& metadata); |
+ void SendSuccessInteger(int64_t value); |
+ |
+ private: |
+ ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
+}; |
+ |
IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
int32_t ipc_thread_id, |
int32_t ipc_callbacks_id) |
@@ -49,9 +72,9 @@ IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
ipc_cursor_id_(kNoCursor), |
host_transaction_id_(kNoTransaction), |
ipc_database_id_(kNoDatabase), |
- ipc_database_callbacks_id_(kNoDatabaseCallbacks), |
data_loss_(blink::WebIDBDataLossNone), |
- sent_blocked_(false) {} |
+ sent_blocked_(false), |
+ io_helper_(nullptr) {} |
IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
int32_t ipc_thread_id, |
@@ -63,34 +86,42 @@ IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
ipc_cursor_id_(ipc_cursor_id), |
host_transaction_id_(kNoTransaction), |
ipc_database_id_(kNoDatabase), |
- ipc_database_callbacks_id_(kNoDatabaseCallbacks), |
data_loss_(blink::WebIDBDataLossNone), |
- sent_blocked_(false) {} |
+ sent_blocked_(false), |
+ io_helper_(nullptr) {} |
-IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
- int32_t ipc_thread_id, |
- int32_t ipc_callbacks_id, |
- int32_t ipc_database_callbacks_id, |
- int64_t host_transaction_id, |
- const url::Origin& origin) |
+IndexedDBCallbacks::IndexedDBCallbacks( |
+ IndexedDBDispatcherHost* dispatcher_host, |
+ const url::Origin& origin, |
+ ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) |
: dispatcher_host_(dispatcher_host), |
- ipc_callbacks_id_(ipc_callbacks_id), |
- ipc_thread_id_(ipc_thread_id), |
ipc_cursor_id_(kNoCursor), |
- host_transaction_id_(host_transaction_id), |
+ host_transaction_id_(kNoTransaction), |
origin_(origin), |
ipc_database_id_(kNoDatabase), |
- ipc_database_callbacks_id_(ipc_database_callbacks_id), |
data_loss_(blink::WebIDBDataLossNone), |
- sent_blocked_(false) {} |
+ sent_blocked_(false), |
+ io_helper_(nullptr) { |
+ if (callbacks_info.is_valid()) |
dcheng
2016/10/17 05:33:44
What are the circumstances where this wouldn't be
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
|callbacks_info| is invalid in tests, where this c
|
+ io_helper_ = new IOThreadHelper(std::move(callbacks_info)); |
+} |
-IndexedDBCallbacks::~IndexedDBCallbacks() {} |
+IndexedDBCallbacks::~IndexedDBCallbacks() { |
+ if (io_helper_) |
+ BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, io_helper_); |
+} |
void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
DCHECK(dispatcher_host_.get()); |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( |
- ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); |
+ if (io_helper_) { |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendError, |
+ base::Unretained(io_helper_), error)); |
+ } else { |
+ dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( |
+ ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); |
+ } |
dispatcher_host_ = NULL; |
if (!connection_open_start_time_.is_null()) { |
@@ -103,37 +134,31 @@ void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { |
DCHECK(dispatcher_host_.get()); |
- |
+ DCHECK(io_helper_); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
- DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
- |
- std::vector<base::string16> list; |
- for (unsigned i = 0; i < value.size(); ++i) |
- list.push_back(value[i]); |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessStringList( |
- ipc_thread_id_, ipc_callbacks_id_, list)); |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendSuccessStringList, |
+ base::Unretained(io_helper_), value)); |
dispatcher_host_ = NULL; |
} |
void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { |
DCHECK(dispatcher_host_.get()); |
- |
+ DCHECK(io_helper_); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
- // No transaction/db callbacks for DeleteDatabase. |
- DCHECK_EQ(kNoTransaction == host_transaction_id_, |
- kNoDatabaseCallbacks == ipc_database_callbacks_id_); |
- DCHECK_EQ(kNoDatabase, ipc_database_id_); |
if (sent_blocked_) |
return; |
sent_blocked_ = true; |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( |
- ipc_thread_id_, ipc_callbacks_id_, existing_version)); |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendBlocked, base::Unretained(io_helper_), |
+ existing_version)); |
if (!connection_open_start_time_.is_null()) { |
UMA_HISTOGRAM_MEDIUM_TIMES( |
@@ -149,29 +174,25 @@ void IndexedDBCallbacks::OnUpgradeNeeded( |
const IndexedDBDatabaseMetadata& metadata, |
const IndexedDBDataLossInfo& data_loss_info) { |
DCHECK(dispatcher_host_.get()); |
- |
- DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
+ DCHECK(io_helper_); |
DCHECK_NE(kNoTransaction, host_transaction_id_); |
+ DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
data_loss_ = data_loss_info.status; |
dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); |
int32_t ipc_database_id = |
- dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); |
+ dispatcher_host_->Add(connection.release(), origin_); |
if (ipc_database_id < 0) |
return; |
+ |
ipc_database_id_ = ipc_database_id; |
- IndexedDBMsg_CallbacksUpgradeNeeded_Params params; |
- params.ipc_thread_id = ipc_thread_id_; |
- params.ipc_callbacks_id = ipc_callbacks_id_; |
- params.ipc_database_id = ipc_database_id; |
- params.ipc_database_callbacks_id = ipc_database_callbacks_id_; |
- params.old_version = old_version; |
- params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); |
- params.data_loss = data_loss_info.status; |
- params.data_loss_message = data_loss_info.message; |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params)); |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendUpgradeNeeded, |
+ base::Unretained(io_helper_), ipc_database_id, old_version, |
+ data_loss_info.status, data_loss_info.message, metadata)); |
if (!connection_open_start_time_.is_null()) { |
UMA_HISTOGRAM_MEDIUM_TIMES( |
@@ -185,27 +206,23 @@ void IndexedDBCallbacks::OnSuccess( |
std::unique_ptr<IndexedDBConnection> connection, |
const IndexedDBDatabaseMetadata& metadata) { |
DCHECK(dispatcher_host_.get()); |
- |
+ DCHECK(io_helper_); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_NE(kNoTransaction, host_transaction_id_); |
DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
- DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
scoped_refptr<IndexedDBCallbacks> self(this); |
int32_t ipc_object_id = kNoDatabase; |
// Only register if the connection was not previously sent in OnUpgradeNeeded. |
if (ipc_database_id_ == kNoDatabase) { |
- ipc_object_id = |
- dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); |
+ ipc_object_id = dispatcher_host_->Add(connection.release(), origin_); |
} |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( |
- ipc_thread_id_, |
- ipc_callbacks_id_, |
- ipc_database_callbacks_id_, |
- ipc_object_id, |
- IndexedDBDispatcherHost::ConvertMetadata(metadata))); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendSuccessDatabase, |
+ base::Unretained(io_helper_), ipc_object_id, metadata)); |
dispatcher_host_ = NULL; |
if (!connection_open_start_time_.is_null()) { |
@@ -335,12 +352,12 @@ void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, |
const IndexedDBKey& key, |
const IndexedDBKey& primary_key, |
IndexedDBValue* value) { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); |
@@ -374,12 +391,12 @@ void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, |
void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, |
const IndexedDBKey& primary_key, |
IndexedDBValue* value) { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
DCHECK_NE(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
IndexedDBCursor* idb_cursor = |
@@ -422,6 +439,7 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch( |
const std::vector<IndexedDBKey>& keys, |
const std::vector<IndexedDBKey>& primary_keys, |
std::vector<IndexedDBValue>* values) { |
+ DCHECK(!io_helper_); |
DCHECK_EQ(keys.size(), primary_keys.size()); |
DCHECK_EQ(keys.size(), values->size()); |
@@ -430,7 +448,6 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch( |
DCHECK_NE(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
std::vector<IndexedDBKey> msg_keys; |
@@ -479,6 +496,7 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch( |
} |
void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
if (value && value->primary_key.IsValid()) { |
@@ -488,7 +506,6 @@ void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { |
} |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( |
@@ -520,11 +537,11 @@ void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { |
void IndexedDBCallbacks::OnSuccessArray( |
std::vector<IndexedDBReturnValue>* values, |
const IndexedDBKeyPath& key_path) { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( |
@@ -563,12 +580,12 @@ void IndexedDBCallbacks::OnSuccessArray( |
} |
void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( |
@@ -578,25 +595,29 @@ void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { |
void IndexedDBCallbacks::OnSuccess(int64_t value) { |
DCHECK(dispatcher_host_.get()); |
+ if (io_helper_) { |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&IOThreadHelper::SendSuccessInteger, |
+ base::Unretained(io_helper_), value)); |
+ } else { |
+ DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
+ DCHECK_EQ(kNoTransaction, host_transaction_id_); |
+ DCHECK_EQ(kNoDatabase, ipc_database_id_); |
+ DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
- DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
- DCHECK_EQ(kNoTransaction, host_transaction_id_); |
- DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
- DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
- |
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger( |
- ipc_thread_id_, ipc_callbacks_id_, value)); |
+ dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger( |
+ ipc_thread_id_, ipc_callbacks_id_, value)); |
+ } |
dispatcher_host_ = NULL; |
dcheng
2016/10/17 05:33:44
Nit: nullptr
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
Done.
|
} |
void IndexedDBCallbacks::OnSuccess() { |
+ DCHECK(!io_helper_); |
DCHECK(dispatcher_host_.get()); |
DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
DCHECK_EQ(kNoTransaction, host_transaction_id_); |
DCHECK_EQ(kNoDatabase, ipc_database_id_); |
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
@@ -615,4 +636,46 @@ void IndexedDBCallbacks::SetConnectionOpenStartTime( |
connection_open_start_time_ = start_time; |
} |
+IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( |
+ CallbacksAssociatedPtrInfo callbacks_info) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ callbacks_.Bind(std::move(callbacks_info)); |
+} |
+ |
+IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendError( |
+ const IndexedDBDatabaseError& error) { |
+ callbacks_->Error(error.code(), error.message()); |
+} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( |
+ const std::vector<base::string16>& value) { |
+ callbacks_->SuccessStringList(value); |
+} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { |
+ callbacks_->Blocked(existing_version); |
+} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
+ int32_t database_id, |
+ int64_t old_version, |
+ blink::WebIDBDataLoss data_loss, |
+ const std::string& data_loss_message, |
+ const content::IndexedDBDatabaseMetadata& metadata) { |
+ callbacks_->UpgradeNeeded(database_id, old_version, data_loss, |
+ data_loss_message, metadata); |
+} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( |
+ int32_t database_id, |
+ const content::IndexedDBDatabaseMetadata& metadata) { |
+ callbacks_->SuccessDatabase(database_id, metadata); |
+} |
+ |
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { |
+ callbacks_->SuccessInteger(value); |
+} |
+ |
} // namespace content |