Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/fileapi/fileapi_message_filter.h" | 16 #include "content/browser/fileapi/fileapi_message_filter.h" |
| 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 18 #include "content/browser/indexed_db/indexed_db_connection.h" | 18 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 20 #include "content/browser/indexed_db/indexed_db_cursor.h" | 20 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 21 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | |
| 22 #include "content/browser/indexed_db/indexed_db_database_error.h" | 21 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 23 #include "content/browser/indexed_db/indexed_db_metadata.h" | |
| 24 #include "content/browser/indexed_db/indexed_db_return_value.h" | 22 #include "content/browser/indexed_db/indexed_db_return_value.h" |
| 25 #include "content/browser/indexed_db/indexed_db_tracing.h" | 23 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 26 #include "content/browser/indexed_db/indexed_db_value.h" | 24 #include "content/browser/indexed_db/indexed_db_value.h" |
| 27 #include "content/common/indexed_db/indexed_db_constants.h" | 25 #include "content/common/indexed_db/indexed_db_constants.h" |
| 28 #include "content/common/indexed_db/indexed_db_messages.h" | 26 #include "content/common/indexed_db/indexed_db_messages.h" |
| 27 #include "content/common/indexed_db/indexed_db_metadata.h" | |
| 29 #include "storage/browser/blob/blob_storage_context.h" | 28 #include "storage/browser/blob/blob_storage_context.h" |
| 30 #include "storage/browser/blob/shareable_file_reference.h" | 29 #include "storage/browser/blob/shareable_file_reference.h" |
| 31 #include "storage/browser/quota/quota_manager.h" | 30 #include "storage/browser/quota/quota_manager.h" |
| 32 | 31 |
| 32 using indexed_db::mojom::CallbacksAssociatedPtrInfo; | |
| 33 using storage::ShareableFileReference; | 33 using storage::ShareableFileReference; |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | |
|
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
| |
| 38 const int32_t kNoCursor = -1; | 39 const int32_t kNoCursor = -1; |
| 39 const int32_t kNoDatabaseCallbacks = -1; | |
| 40 const int64_t kNoTransaction = -1; | 40 const int64_t kNoTransaction = -1; |
| 41 } | 41 } |
| 42 | 42 |
| 43 class IndexedDBCallbacks::IOThreadHelper { | |
| 44 public: | |
| 45 IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info); | |
|
dcheng
2016/10/17 05:33:44
Nit: explicit
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
Done.
| |
| 46 ~IOThreadHelper(); | |
| 47 | |
| 48 void SendError(const IndexedDBDatabaseError& error); | |
| 49 void SendSuccessStringList(const std::vector<base::string16>& value); | |
| 50 void SendBlocked(int64_t existing_version); | |
| 51 void SendUpgradeNeeded(int32_t database_id, | |
| 52 int64_t old_version, | |
| 53 blink::WebIDBDataLoss data_loss, | |
| 54 const std::string& data_loss_message, | |
| 55 const content::IndexedDBDatabaseMetadata& metadata); | |
| 56 void SendSuccessDatabase(int32_t database_id, | |
| 57 const content::IndexedDBDatabaseMetadata& metadata); | |
| 58 void SendSuccessInteger(int64_t value); | |
| 59 | |
| 60 private: | |
| 61 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); | |
| 64 }; | |
| 65 | |
| 43 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 66 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 44 int32_t ipc_thread_id, | 67 int32_t ipc_thread_id, |
| 45 int32_t ipc_callbacks_id) | 68 int32_t ipc_callbacks_id) |
| 46 : dispatcher_host_(dispatcher_host), | 69 : dispatcher_host_(dispatcher_host), |
| 47 ipc_callbacks_id_(ipc_callbacks_id), | 70 ipc_callbacks_id_(ipc_callbacks_id), |
| 48 ipc_thread_id_(ipc_thread_id), | 71 ipc_thread_id_(ipc_thread_id), |
| 49 ipc_cursor_id_(kNoCursor), | 72 ipc_cursor_id_(kNoCursor), |
| 50 host_transaction_id_(kNoTransaction), | 73 host_transaction_id_(kNoTransaction), |
| 51 ipc_database_id_(kNoDatabase), | 74 ipc_database_id_(kNoDatabase), |
| 52 ipc_database_callbacks_id_(kNoDatabaseCallbacks), | |
| 53 data_loss_(blink::WebIDBDataLossNone), | 75 data_loss_(blink::WebIDBDataLossNone), |
| 54 sent_blocked_(false) {} | 76 sent_blocked_(false), |
| 77 io_helper_(nullptr) {} | |
| 55 | 78 |
| 56 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 79 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 57 int32_t ipc_thread_id, | 80 int32_t ipc_thread_id, |
| 58 int32_t ipc_callbacks_id, | 81 int32_t ipc_callbacks_id, |
| 59 int32_t ipc_cursor_id) | 82 int32_t ipc_cursor_id) |
| 60 : dispatcher_host_(dispatcher_host), | 83 : dispatcher_host_(dispatcher_host), |
| 61 ipc_callbacks_id_(ipc_callbacks_id), | 84 ipc_callbacks_id_(ipc_callbacks_id), |
| 62 ipc_thread_id_(ipc_thread_id), | 85 ipc_thread_id_(ipc_thread_id), |
| 63 ipc_cursor_id_(ipc_cursor_id), | 86 ipc_cursor_id_(ipc_cursor_id), |
| 64 host_transaction_id_(kNoTransaction), | 87 host_transaction_id_(kNoTransaction), |
| 65 ipc_database_id_(kNoDatabase), | 88 ipc_database_id_(kNoDatabase), |
| 66 ipc_database_callbacks_id_(kNoDatabaseCallbacks), | |
| 67 data_loss_(blink::WebIDBDataLossNone), | 89 data_loss_(blink::WebIDBDataLossNone), |
| 68 sent_blocked_(false) {} | 90 sent_blocked_(false), |
| 91 io_helper_(nullptr) {} | |
| 69 | 92 |
| 70 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 93 IndexedDBCallbacks::IndexedDBCallbacks( |
| 71 int32_t ipc_thread_id, | 94 IndexedDBDispatcherHost* dispatcher_host, |
| 72 int32_t ipc_callbacks_id, | 95 const url::Origin& origin, |
| 73 int32_t ipc_database_callbacks_id, | 96 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) |
| 74 int64_t host_transaction_id, | |
| 75 const url::Origin& origin) | |
| 76 : dispatcher_host_(dispatcher_host), | 97 : dispatcher_host_(dispatcher_host), |
| 77 ipc_callbacks_id_(ipc_callbacks_id), | |
| 78 ipc_thread_id_(ipc_thread_id), | |
| 79 ipc_cursor_id_(kNoCursor), | 98 ipc_cursor_id_(kNoCursor), |
| 80 host_transaction_id_(host_transaction_id), | 99 host_transaction_id_(kNoTransaction), |
| 81 origin_(origin), | 100 origin_(origin), |
| 82 ipc_database_id_(kNoDatabase), | 101 ipc_database_id_(kNoDatabase), |
| 83 ipc_database_callbacks_id_(ipc_database_callbacks_id), | |
| 84 data_loss_(blink::WebIDBDataLossNone), | 102 data_loss_(blink::WebIDBDataLossNone), |
| 85 sent_blocked_(false) {} | 103 sent_blocked_(false), |
| 104 io_helper_(nullptr) { | |
| 105 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
| |
| 106 io_helper_ = new IOThreadHelper(std::move(callbacks_info)); | |
| 107 } | |
| 86 | 108 |
| 87 IndexedDBCallbacks::~IndexedDBCallbacks() {} | 109 IndexedDBCallbacks::~IndexedDBCallbacks() { |
| 110 if (io_helper_) | |
| 111 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, io_helper_); | |
| 112 } | |
| 88 | 113 |
| 89 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { | 114 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
| 90 DCHECK(dispatcher_host_.get()); | 115 DCHECK(dispatcher_host_.get()); |
| 91 | 116 |
| 92 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( | 117 if (io_helper_) { |
| 93 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); | 118 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 119 base::Bind(&IOThreadHelper::SendError, | |
| 120 base::Unretained(io_helper_), error)); | |
| 121 } else { | |
| 122 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( | |
| 123 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); | |
| 124 } | |
| 94 dispatcher_host_ = NULL; | 125 dispatcher_host_ = NULL; |
| 95 | 126 |
| 96 if (!connection_open_start_time_.is_null()) { | 127 if (!connection_open_start_time_.is_null()) { |
| 97 UMA_HISTOGRAM_MEDIUM_TIMES( | 128 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 98 "WebCore.IndexedDB.OpenTime.Error", | 129 "WebCore.IndexedDB.OpenTime.Error", |
| 99 base::TimeTicks::Now() - connection_open_start_time_); | 130 base::TimeTicks::Now() - connection_open_start_time_); |
| 100 connection_open_start_time_ = base::TimeTicks(); | 131 connection_open_start_time_ = base::TimeTicks(); |
| 101 } | 132 } |
| 102 } | 133 } |
| 103 | 134 |
| 104 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { | 135 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { |
| 105 DCHECK(dispatcher_host_.get()); | 136 DCHECK(dispatcher_host_.get()); |
| 106 | 137 DCHECK(io_helper_); |
| 107 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 138 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 108 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 139 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 109 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 140 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 110 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 111 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | |
| 112 | 141 |
| 113 std::vector<base::string16> list; | 142 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 114 for (unsigned i = 0; i < value.size(); ++i) | 143 base::Bind(&IOThreadHelper::SendSuccessStringList, |
| 115 list.push_back(value[i]); | 144 base::Unretained(io_helper_), value)); |
| 116 | |
| 117 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessStringList( | |
| 118 ipc_thread_id_, ipc_callbacks_id_, list)); | |
| 119 dispatcher_host_ = NULL; | 145 dispatcher_host_ = NULL; |
| 120 } | 146 } |
| 121 | 147 |
| 122 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { | 148 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { |
| 123 DCHECK(dispatcher_host_.get()); | 149 DCHECK(dispatcher_host_.get()); |
| 124 | 150 DCHECK(io_helper_); |
| 125 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 151 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 126 // No transaction/db callbacks for DeleteDatabase. | |
| 127 DCHECK_EQ(kNoTransaction == host_transaction_id_, | |
| 128 kNoDatabaseCallbacks == ipc_database_callbacks_id_); | |
| 129 DCHECK_EQ(kNoDatabase, ipc_database_id_); | |
| 130 | 152 |
| 131 if (sent_blocked_) | 153 if (sent_blocked_) |
| 132 return; | 154 return; |
| 133 | 155 |
| 134 sent_blocked_ = true; | 156 sent_blocked_ = true; |
| 135 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( | 157 |
| 136 ipc_thread_id_, ipc_callbacks_id_, existing_version)); | 158 BrowserThread::PostTask( |
| 159 BrowserThread::IO, FROM_HERE, | |
| 160 base::Bind(&IOThreadHelper::SendBlocked, base::Unretained(io_helper_), | |
| 161 existing_version)); | |
| 137 | 162 |
| 138 if (!connection_open_start_time_.is_null()) { | 163 if (!connection_open_start_time_.is_null()) { |
| 139 UMA_HISTOGRAM_MEDIUM_TIMES( | 164 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 140 "WebCore.IndexedDB.OpenTime.Blocked", | 165 "WebCore.IndexedDB.OpenTime.Blocked", |
| 141 base::TimeTicks::Now() - connection_open_start_time_); | 166 base::TimeTicks::Now() - connection_open_start_time_); |
| 142 connection_open_start_time_ = base::TimeTicks(); | 167 connection_open_start_time_ = base::TimeTicks(); |
| 143 } | 168 } |
| 144 } | 169 } |
| 145 | 170 |
| 146 void IndexedDBCallbacks::OnUpgradeNeeded( | 171 void IndexedDBCallbacks::OnUpgradeNeeded( |
| 147 int64_t old_version, | 172 int64_t old_version, |
| 148 std::unique_ptr<IndexedDBConnection> connection, | 173 std::unique_ptr<IndexedDBConnection> connection, |
| 149 const IndexedDBDatabaseMetadata& metadata, | 174 const IndexedDBDatabaseMetadata& metadata, |
| 150 const IndexedDBDataLossInfo& data_loss_info) { | 175 const IndexedDBDataLossInfo& data_loss_info) { |
| 151 DCHECK(dispatcher_host_.get()); | 176 DCHECK(dispatcher_host_.get()); |
| 152 | 177 DCHECK(io_helper_); |
| 178 DCHECK_NE(kNoTransaction, host_transaction_id_); | |
| 153 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 179 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 154 DCHECK_NE(kNoTransaction, host_transaction_id_); | |
| 155 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 180 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 156 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 157 | 181 |
| 158 data_loss_ = data_loss_info.status; | 182 data_loss_ = data_loss_info.status; |
| 159 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); | 183 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); |
| 160 int32_t ipc_database_id = | 184 int32_t ipc_database_id = |
| 161 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); | 185 dispatcher_host_->Add(connection.release(), origin_); |
| 162 if (ipc_database_id < 0) | 186 if (ipc_database_id < 0) |
| 163 return; | 187 return; |
| 188 | |
| 164 ipc_database_id_ = ipc_database_id; | 189 ipc_database_id_ = ipc_database_id; |
| 165 IndexedDBMsg_CallbacksUpgradeNeeded_Params params; | 190 |
| 166 params.ipc_thread_id = ipc_thread_id_; | 191 BrowserThread::PostTask( |
| 167 params.ipc_callbacks_id = ipc_callbacks_id_; | 192 BrowserThread::IO, FROM_HERE, |
| 168 params.ipc_database_id = ipc_database_id; | 193 base::Bind(&IOThreadHelper::SendUpgradeNeeded, |
| 169 params.ipc_database_callbacks_id = ipc_database_callbacks_id_; | 194 base::Unretained(io_helper_), ipc_database_id, old_version, |
| 170 params.old_version = old_version; | 195 data_loss_info.status, data_loss_info.message, metadata)); |
| 171 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); | |
| 172 params.data_loss = data_loss_info.status; | |
| 173 params.data_loss_message = data_loss_info.message; | |
| 174 dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params)); | |
| 175 | 196 |
| 176 if (!connection_open_start_time_.is_null()) { | 197 if (!connection_open_start_time_.is_null()) { |
| 177 UMA_HISTOGRAM_MEDIUM_TIMES( | 198 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 178 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", | 199 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", |
| 179 base::TimeTicks::Now() - connection_open_start_time_); | 200 base::TimeTicks::Now() - connection_open_start_time_); |
| 180 connection_open_start_time_ = base::TimeTicks(); | 201 connection_open_start_time_ = base::TimeTicks(); |
| 181 } | 202 } |
| 182 } | 203 } |
| 183 | 204 |
| 184 void IndexedDBCallbacks::OnSuccess( | 205 void IndexedDBCallbacks::OnSuccess( |
| 185 std::unique_ptr<IndexedDBConnection> connection, | 206 std::unique_ptr<IndexedDBConnection> connection, |
| 186 const IndexedDBDatabaseMetadata& metadata) { | 207 const IndexedDBDatabaseMetadata& metadata) { |
| 187 DCHECK(dispatcher_host_.get()); | 208 DCHECK(dispatcher_host_.get()); |
| 188 | 209 DCHECK(io_helper_); |
| 189 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 210 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 190 DCHECK_NE(kNoTransaction, host_transaction_id_); | 211 DCHECK_NE(kNoTransaction, host_transaction_id_); |
| 191 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); | 212 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
| 192 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 193 | 213 |
| 194 scoped_refptr<IndexedDBCallbacks> self(this); | 214 scoped_refptr<IndexedDBCallbacks> self(this); |
| 195 | 215 |
| 196 int32_t ipc_object_id = kNoDatabase; | 216 int32_t ipc_object_id = kNoDatabase; |
| 197 // Only register if the connection was not previously sent in OnUpgradeNeeded. | 217 // Only register if the connection was not previously sent in OnUpgradeNeeded. |
| 198 if (ipc_database_id_ == kNoDatabase) { | 218 if (ipc_database_id_ == kNoDatabase) { |
| 199 ipc_object_id = | 219 ipc_object_id = dispatcher_host_->Add(connection.release(), origin_); |
| 200 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); | |
| 201 } | 220 } |
| 202 | 221 |
| 203 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( | 222 BrowserThread::PostTask( |
| 204 ipc_thread_id_, | 223 BrowserThread::IO, FROM_HERE, |
| 205 ipc_callbacks_id_, | 224 base::Bind(&IOThreadHelper::SendSuccessDatabase, |
| 206 ipc_database_callbacks_id_, | 225 base::Unretained(io_helper_), ipc_object_id, metadata)); |
| 207 ipc_object_id, | |
| 208 IndexedDBDispatcherHost::ConvertMetadata(metadata))); | |
| 209 dispatcher_host_ = NULL; | 226 dispatcher_host_ = NULL; |
| 210 | 227 |
| 211 if (!connection_open_start_time_.is_null()) { | 228 if (!connection_open_start_time_.is_null()) { |
| 212 UMA_HISTOGRAM_MEDIUM_TIMES( | 229 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 213 "WebCore.IndexedDB.OpenTime.Success", | 230 "WebCore.IndexedDB.OpenTime.Success", |
| 214 base::TimeTicks::Now() - connection_open_start_time_); | 231 base::TimeTicks::Now() - connection_open_start_time_); |
| 215 connection_open_start_time_ = base::TimeTicks(); | 232 connection_open_start_time_ = base::TimeTicks(); |
| 216 } | 233 } |
| 217 } | 234 } |
| 218 | 235 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 iter.mark_used_callback().Run(); | 345 iter.mark_used_callback().Run(); |
| 329 } | 346 } |
| 330 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 347 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 331 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); | 348 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); |
| 332 } | 349 } |
| 333 | 350 |
| 334 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, | 351 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, |
| 335 const IndexedDBKey& key, | 352 const IndexedDBKey& key, |
| 336 const IndexedDBKey& primary_key, | 353 const IndexedDBKey& primary_key, |
| 337 IndexedDBValue* value) { | 354 IndexedDBValue* value) { |
| 355 DCHECK(!io_helper_); | |
| 338 DCHECK(dispatcher_host_.get()); | 356 DCHECK(dispatcher_host_.get()); |
| 339 | 357 |
| 340 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 358 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 341 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 359 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 342 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 360 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 343 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 344 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 361 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 345 | 362 |
| 346 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); | 363 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); |
| 347 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( | 364 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( |
| 348 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); | 365 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); |
| 349 params->ipc_thread_id = ipc_thread_id_; | 366 params->ipc_thread_id = ipc_thread_id_; |
| 350 params->ipc_callbacks_id = ipc_callbacks_id_; | 367 params->ipc_callbacks_id = ipc_callbacks_id_; |
| 351 params->ipc_cursor_id = ipc_object_id; | 368 params->ipc_cursor_id = ipc_object_id; |
| 352 params->key = key; | 369 params->key = key; |
| 353 params->primary_key = primary_key; | 370 params->primary_key = primary_key; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 367 IndexedDBMsg_CallbacksSuccessIDBCursor>, | 384 IndexedDBMsg_CallbacksSuccessIDBCursor>, |
| 368 base::Owned(params.release()), dispatcher_host_, value->blob_info, | 385 base::Owned(params.release()), dispatcher_host_, value->blob_info, |
| 369 base::Unretained(&p->value.blob_or_file_info))); | 386 base::Unretained(&p->value.blob_or_file_info))); |
| 370 } | 387 } |
| 371 dispatcher_host_ = NULL; | 388 dispatcher_host_ = NULL; |
| 372 } | 389 } |
| 373 | 390 |
| 374 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, | 391 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, |
| 375 const IndexedDBKey& primary_key, | 392 const IndexedDBKey& primary_key, |
| 376 IndexedDBValue* value) { | 393 IndexedDBValue* value) { |
| 394 DCHECK(!io_helper_); | |
| 377 DCHECK(dispatcher_host_.get()); | 395 DCHECK(dispatcher_host_.get()); |
| 378 | 396 |
| 379 DCHECK_NE(kNoCursor, ipc_cursor_id_); | 397 DCHECK_NE(kNoCursor, ipc_cursor_id_); |
| 380 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 398 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 381 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 399 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 382 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 383 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 400 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 384 | 401 |
| 385 IndexedDBCursor* idb_cursor = | 402 IndexedDBCursor* idb_cursor = |
| 386 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); | 403 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); |
| 387 | 404 |
| 388 DCHECK(idb_cursor); | 405 DCHECK(idb_cursor); |
| 389 if (!idb_cursor) | 406 if (!idb_cursor) |
| 390 return; | 407 return; |
| 391 | 408 |
| 392 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params( | 409 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 415 value->blob_info, | 432 value->blob_info, |
| 416 base::Unretained(&p->value.blob_or_file_info))); | 433 base::Unretained(&p->value.blob_or_file_info))); |
| 417 } | 434 } |
| 418 dispatcher_host_ = NULL; | 435 dispatcher_host_ = NULL; |
| 419 } | 436 } |
| 420 | 437 |
| 421 void IndexedDBCallbacks::OnSuccessWithPrefetch( | 438 void IndexedDBCallbacks::OnSuccessWithPrefetch( |
| 422 const std::vector<IndexedDBKey>& keys, | 439 const std::vector<IndexedDBKey>& keys, |
| 423 const std::vector<IndexedDBKey>& primary_keys, | 440 const std::vector<IndexedDBKey>& primary_keys, |
| 424 std::vector<IndexedDBValue>* values) { | 441 std::vector<IndexedDBValue>* values) { |
| 442 DCHECK(!io_helper_); | |
| 425 DCHECK_EQ(keys.size(), primary_keys.size()); | 443 DCHECK_EQ(keys.size(), primary_keys.size()); |
| 426 DCHECK_EQ(keys.size(), values->size()); | 444 DCHECK_EQ(keys.size(), values->size()); |
| 427 | 445 |
| 428 DCHECK(dispatcher_host_.get()); | 446 DCHECK(dispatcher_host_.get()); |
| 429 | 447 |
| 430 DCHECK_NE(kNoCursor, ipc_cursor_id_); | 448 DCHECK_NE(kNoCursor, ipc_cursor_id_); |
| 431 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 449 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 432 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 450 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 433 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 434 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 451 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 435 | 452 |
| 436 std::vector<IndexedDBKey> msg_keys; | 453 std::vector<IndexedDBKey> msg_keys; |
| 437 std::vector<IndexedDBKey> msg_primary_keys; | 454 std::vector<IndexedDBKey> msg_primary_keys; |
| 438 | 455 |
| 439 for (size_t i = 0; i < keys.size(); ++i) { | 456 for (size_t i = 0; i < keys.size(); ++i) { |
| 440 msg_keys.push_back(keys[i]); | 457 msg_keys.push_back(keys[i]); |
| 441 msg_primary_keys.push_back(primary_keys[i]); | 458 msg_primary_keys.push_back(primary_keys[i]); |
| 442 } | 459 } |
| 443 | 460 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 472 dispatcher_host_, | 489 dispatcher_host_, |
| 473 *values)); | 490 *values)); |
| 474 } else { | 491 } else { |
| 475 dispatcher_host_->Send( | 492 dispatcher_host_->Send( |
| 476 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get())); | 493 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get())); |
| 477 } | 494 } |
| 478 dispatcher_host_ = NULL; | 495 dispatcher_host_ = NULL; |
| 479 } | 496 } |
| 480 | 497 |
| 481 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { | 498 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { |
| 499 DCHECK(!io_helper_); | |
| 482 DCHECK(dispatcher_host_.get()); | 500 DCHECK(dispatcher_host_.get()); |
| 483 | 501 |
| 484 if (value && value->primary_key.IsValid()) { | 502 if (value && value->primary_key.IsValid()) { |
| 485 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 503 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 486 } else { | 504 } else { |
| 487 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); | 505 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); |
| 488 } | 506 } |
| 489 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 507 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 490 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 508 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 491 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 492 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 509 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 493 | 510 |
| 494 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( | 511 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( |
| 495 new IndexedDBMsg_CallbacksSuccessValue_Params()); | 512 new IndexedDBMsg_CallbacksSuccessValue_Params()); |
| 496 params->ipc_thread_id = ipc_thread_id_; | 513 params->ipc_thread_id = ipc_thread_id_; |
| 497 params->ipc_callbacks_id = ipc_callbacks_id_; | 514 params->ipc_callbacks_id = ipc_callbacks_id_; |
| 498 if (value && value->primary_key.IsValid()) { | 515 if (value && value->primary_key.IsValid()) { |
| 499 params->value.primary_key = value->primary_key; | 516 params->value.primary_key = value->primary_key; |
| 500 params->value.key_path = value->key_path; | 517 params->value.key_path = value->key_path; |
| 501 } | 518 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 513 base::Owned(params.release()), dispatcher_host_, | 530 base::Owned(params.release()), dispatcher_host_, |
| 514 value->blob_info, | 531 value->blob_info, |
| 515 base::Unretained(&p->value.blob_or_file_info))); | 532 base::Unretained(&p->value.blob_or_file_info))); |
| 516 } | 533 } |
| 517 dispatcher_host_ = NULL; | 534 dispatcher_host_ = NULL; |
| 518 } | 535 } |
| 519 | 536 |
| 520 void IndexedDBCallbacks::OnSuccessArray( | 537 void IndexedDBCallbacks::OnSuccessArray( |
| 521 std::vector<IndexedDBReturnValue>* values, | 538 std::vector<IndexedDBReturnValue>* values, |
| 522 const IndexedDBKeyPath& key_path) { | 539 const IndexedDBKeyPath& key_path) { |
| 540 DCHECK(!io_helper_); | |
| 523 DCHECK(dispatcher_host_.get()); | 541 DCHECK(dispatcher_host_.get()); |
| 524 | 542 |
| 525 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 543 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 526 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 544 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 527 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 528 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 545 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 529 | 546 |
| 530 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( | 547 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( |
| 531 new IndexedDBMsg_CallbacksSuccessArray_Params()); | 548 new IndexedDBMsg_CallbacksSuccessArray_Params()); |
| 532 params->ipc_thread_id = ipc_thread_id_; | 549 params->ipc_thread_id = ipc_thread_id_; |
| 533 params->ipc_callbacks_id = ipc_callbacks_id_; | 550 params->ipc_callbacks_id = ipc_callbacks_id_; |
| 534 params->values.resize(values->size()); | 551 params->values.resize(values->size()); |
| 535 | 552 |
| 536 bool found_blob_info = false; | 553 bool found_blob_info = false; |
| 537 for (size_t i = 0; i < values->size(); ++i) { | 554 for (size_t i = 0; i < values->size(); ++i) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 556 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), | 573 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), |
| 557 dispatcher_host_, *values)); | 574 dispatcher_host_, *values)); |
| 558 } else { | 575 } else { |
| 559 dispatcher_host_->Send( | 576 dispatcher_host_->Send( |
| 560 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); | 577 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); |
| 561 } | 578 } |
| 562 dispatcher_host_ = NULL; | 579 dispatcher_host_ = NULL; |
| 563 } | 580 } |
| 564 | 581 |
| 565 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { | 582 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { |
| 583 DCHECK(!io_helper_); | |
| 566 DCHECK(dispatcher_host_.get()); | 584 DCHECK(dispatcher_host_.get()); |
| 567 | 585 |
| 568 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 586 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 569 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 587 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 570 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 588 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 571 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 572 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 589 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 573 | 590 |
| 574 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( | 591 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( |
| 575 ipc_thread_id_, ipc_callbacks_id_, value)); | 592 ipc_thread_id_, ipc_callbacks_id_, value)); |
| 576 dispatcher_host_ = NULL; | 593 dispatcher_host_ = NULL; |
| 577 } | 594 } |
| 578 | 595 |
| 579 void IndexedDBCallbacks::OnSuccess(int64_t value) { | 596 void IndexedDBCallbacks::OnSuccess(int64_t value) { |
| 580 DCHECK(dispatcher_host_.get()); | 597 DCHECK(dispatcher_host_.get()); |
| 598 if (io_helper_) { | |
| 599 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 600 base::Bind(&IOThreadHelper::SendSuccessInteger, | |
| 601 base::Unretained(io_helper_), value)); | |
| 602 } else { | |
| 603 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | |
| 604 DCHECK_EQ(kNoTransaction, host_transaction_id_); | |
| 605 DCHECK_EQ(kNoDatabase, ipc_database_id_); | |
| 606 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | |
| 607 | |
| 608 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger( | |
| 609 ipc_thread_id_, ipc_callbacks_id_, value)); | |
| 610 } | |
| 611 dispatcher_host_ = NULL; | |
|
dcheng
2016/10/17 05:33:44
Nit: nullptr
Reilly Grant (use Gerrit)
2016/10/19 00:36:51
Done.
| |
| 612 } | |
| 613 | |
| 614 void IndexedDBCallbacks::OnSuccess() { | |
| 615 DCHECK(!io_helper_); | |
| 616 DCHECK(dispatcher_host_.get()); | |
| 581 | 617 |
| 582 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 618 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 583 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 619 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 584 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 620 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 585 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 586 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | |
| 587 | |
| 588 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger( | |
| 589 ipc_thread_id_, ipc_callbacks_id_, value)); | |
| 590 dispatcher_host_ = NULL; | |
| 591 } | |
| 592 | |
| 593 void IndexedDBCallbacks::OnSuccess() { | |
| 594 DCHECK(dispatcher_host_.get()); | |
| 595 | |
| 596 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | |
| 597 DCHECK_EQ(kNoTransaction, host_transaction_id_); | |
| 598 DCHECK_EQ(kNoDatabase, ipc_database_id_); | |
| 599 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 600 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 621 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 601 | 622 |
| 602 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( | 623 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
| 603 ipc_thread_id_, ipc_callbacks_id_)); | 624 ipc_thread_id_, ipc_callbacks_id_)); |
| 604 dispatcher_host_ = NULL; | 625 dispatcher_host_ = NULL; |
| 605 } | 626 } |
| 606 | 627 |
| 607 bool IndexedDBCallbacks::IsValid() const { | 628 bool IndexedDBCallbacks::IsValid() const { |
| 608 DCHECK(dispatcher_host_.get()); | 629 DCHECK(dispatcher_host_.get()); |
| 609 | 630 |
| 610 return dispatcher_host_->IsOpen(); | 631 return dispatcher_host_->IsOpen(); |
| 611 } | 632 } |
| 612 | 633 |
| 613 void IndexedDBCallbacks::SetConnectionOpenStartTime( | 634 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
| 614 const base::TimeTicks& start_time) { | 635 const base::TimeTicks& start_time) { |
| 615 connection_open_start_time_ = start_time; | 636 connection_open_start_time_ = start_time; |
| 616 } | 637 } |
| 617 | 638 |
| 639 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( | |
| 640 CallbacksAssociatedPtrInfo callbacks_info) { | |
| 641 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 642 callbacks_.Bind(std::move(callbacks_info)); | |
| 643 } | |
| 644 | |
| 645 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} | |
| 646 | |
| 647 void IndexedDBCallbacks::IOThreadHelper::SendError( | |
| 648 const IndexedDBDatabaseError& error) { | |
| 649 callbacks_->Error(error.code(), error.message()); | |
| 650 } | |
| 651 | |
| 652 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( | |
| 653 const std::vector<base::string16>& value) { | |
| 654 callbacks_->SuccessStringList(value); | |
| 655 } | |
| 656 | |
| 657 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { | |
| 658 callbacks_->Blocked(existing_version); | |
| 659 } | |
| 660 | |
| 661 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( | |
| 662 int32_t database_id, | |
| 663 int64_t old_version, | |
| 664 blink::WebIDBDataLoss data_loss, | |
| 665 const std::string& data_loss_message, | |
| 666 const content::IndexedDBDatabaseMetadata& metadata) { | |
| 667 callbacks_->UpgradeNeeded(database_id, old_version, data_loss, | |
| 668 data_loss_message, metadata); | |
| 669 } | |
| 670 | |
| 671 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( | |
| 672 int32_t database_id, | |
| 673 const content::IndexedDBDatabaseMetadata& metadata) { | |
| 674 callbacks_->SuccessDatabase(database_id, metadata); | |
| 675 } | |
| 676 | |
| 677 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { | |
| 678 callbacks_->SuccessInteger(value); | |
| 679 } | |
| 680 | |
| 618 } // namespace content | 681 } // namespace content |
| OLD | NEW |