Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: content/browser/indexed_db/indexed_db_database.cc

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_database.h" 5 #include "content/browser/indexed_db/indexed_db_database.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
(...skipping 13 matching lines...) Expand all
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "content/browser/indexed_db/indexed_db_blob_info.h" 25 #include "content/browser/indexed_db/indexed_db_blob_info.h"
26 #include "content/browser/indexed_db/indexed_db_class_factory.h" 26 #include "content/browser/indexed_db/indexed_db_class_factory.h"
27 #include "content/browser/indexed_db/indexed_db_connection.h" 27 #include "content/browser/indexed_db/indexed_db_connection.h"
28 #include "content/browser/indexed_db/indexed_db_context_impl.h" 28 #include "content/browser/indexed_db/indexed_db_context_impl.h"
29 #include "content/browser/indexed_db/indexed_db_cursor.h" 29 #include "content/browser/indexed_db/indexed_db_cursor.h"
30 #include "content/browser/indexed_db/indexed_db_factory.h" 30 #include "content/browser/indexed_db/indexed_db_factory.h"
31 #include "content/browser/indexed_db/indexed_db_index_writer.h" 31 #include "content/browser/indexed_db/indexed_db_index_writer.h"
32 #include "content/browser/indexed_db/indexed_db_observation.h" 32 #include "content/browser/indexed_db/indexed_db_observation.h"
33 #include "content/browser/indexed_db/indexed_db_observer_changes.h" 33 #include "content/browser/indexed_db/indexed_db_observer_changes.h"
34 #include "content/browser/indexed_db/indexed_db_open_request_observer.h"
34 #include "content/browser/indexed_db/indexed_db_pending_connection.h" 35 #include "content/browser/indexed_db/indexed_db_pending_connection.h"
36 #include "content/browser/indexed_db/indexed_db_pending_delete.h"
35 #include "content/browser/indexed_db/indexed_db_return_value.h" 37 #include "content/browser/indexed_db/indexed_db_return_value.h"
36 #include "content/browser/indexed_db/indexed_db_tracing.h" 38 #include "content/browser/indexed_db/indexed_db_tracing.h"
37 #include "content/browser/indexed_db/indexed_db_transaction.h" 39 #include "content/browser/indexed_db/indexed_db_transaction.h"
38 #include "content/browser/indexed_db/indexed_db_value.h" 40 #include "content/browser/indexed_db/indexed_db_value.h"
39 #include "content/common/indexed_db/indexed_db_constants.h" 41 #include "content/common/indexed_db/indexed_db_constants.h"
40 #include "content/common/indexed_db/indexed_db_key_path.h" 42 #include "content/common/indexed_db/indexed_db_key_path.h"
41 #include "content/common/indexed_db/indexed_db_key_range.h" 43 #include "content/common/indexed_db/indexed_db_key_range.h"
42 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
43 #include "storage/browser/blob/blob_data_handle.h" 45 #include "storage/browser/blob/blob_data_handle.h"
44 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 46 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 std::unique_ptr<IndexedDBPendingConnection> pending_connection) 122 std::unique_ptr<IndexedDBPendingConnection> pending_connection)
121 : ConnectionRequest(db), pending_(std::move(pending_connection)) {} 123 : ConnectionRequest(db), pending_(std::move(pending_connection)) {}
122 124
123 void Perform() override { 125 void Perform() override {
124 if (db_->metadata_.id == kInvalidId) { 126 if (db_->metadata_.id == kInvalidId) {
125 // The database was deleted then immediately re-opened; OpenInternal() 127 // The database was deleted then immediately re-opened; OpenInternal()
126 // recreates it in the backing store. 128 // recreates it in the backing store.
127 if (!db_->OpenInternal().ok()) { 129 if (!db_->OpenInternal().ok()) {
128 // TODO(jsbell): Consider including sanitized leveldb status message. 130 // TODO(jsbell): Consider including sanitized leveldb status message.
129 base::string16 message; 131 base::string16 message;
130 if (pending_->version == IndexedDBDatabaseMetadata::NO_VERSION) { 132 if (pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION) {
131 message = ASCIIToUTF16( 133 message = ASCIIToUTF16(
132 "Internal error opening database with no version specified."); 134 "Internal error opening database with no version specified.");
133 } else { 135 } else {
134 message = 136 message =
135 ASCIIToUTF16("Internal error opening database with version ") + 137 ASCIIToUTF16("Internal error opening database with version ") +
136 Int64ToString16(pending_->version); 138 Int64ToString16(pending_->version());
137 } 139 }
138 pending_->callbacks->OnError(IndexedDBDatabaseError( 140 pending_->OnError(IndexedDBDatabaseError(
139 blink::WebIDBDatabaseExceptionUnknownError, message)); 141 blink::WebIDBDatabaseExceptionUnknownError, message));
140 db_->RequestComplete(this); 142 db_->RequestComplete(this);
141 return; 143 return;
142 } 144 }
143 145
144 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata_.version); 146 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata_.version);
145 } 147 }
146 148
147 const int64_t old_version = db_->metadata_.version; 149 const int64_t old_version = db_->metadata_.version;
148 int64_t& new_version = pending_->version;
149 150
150 bool is_new_database = old_version == IndexedDBDatabaseMetadata::NO_VERSION; 151 bool is_new_database = old_version == IndexedDBDatabaseMetadata::NO_VERSION;
151 152
152 if (new_version == IndexedDBDatabaseMetadata::DEFAULT_VERSION) { 153 if (pending_->version() == IndexedDBDatabaseMetadata::DEFAULT_VERSION) {
153 // For unit tests only - skip upgrade steps. (Calling from script with 154 // For unit tests only - skip upgrade steps. (Calling from script with
154 // DEFAULT_VERSION throws exception.) 155 // DEFAULT_VERSION throws exception.)
155 DCHECK(is_new_database); 156 DCHECK(is_new_database);
156 pending_->callbacks->OnSuccess( 157 pending_->OnSuccess(db_->CreateConnection(pending_->change_handler(),
157 db_->CreateConnection(pending_->database_callbacks, 158 pending_->child_process_id()),
158 pending_->child_process_id), 159 db_->metadata_);
159 db_->metadata_);
160 db_->RequestComplete(this); 160 db_->RequestComplete(this);
161 return; 161 return;
162 } 162 }
163 163
164 if (!is_new_database && 164 if (!is_new_database &&
165 (new_version == old_version || 165 (pending_->version() == old_version ||
166 new_version == IndexedDBDatabaseMetadata::NO_VERSION)) { 166 pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION)) {
167 pending_->callbacks->OnSuccess( 167 pending_->OnSuccess(db_->CreateConnection(pending_->change_handler(),
168 db_->CreateConnection(pending_->database_callbacks, 168 pending_->child_process_id()),
169 pending_->child_process_id), 169 db_->metadata_);
170 db_->metadata_);
171 db_->RequestComplete(this); 170 db_->RequestComplete(this);
172 return; 171 return;
173 } 172 }
174 173
175 if (new_version == IndexedDBDatabaseMetadata::NO_VERSION) { 174 if (pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION) {
176 // If no version is specified and no database exists, upgrade the 175 // If no version is specified and no database exists, upgrade the
177 // database version to 1. 176 // database version to 1.
178 DCHECK(is_new_database); 177 DCHECK(is_new_database);
179 new_version = 1; 178 pending_->set_version(1);
180 } else if (new_version < old_version) { 179 } else if (pending_->version() < old_version) {
181 // Requested version is lower than current version - fail the request. 180 // Requested version is lower than current version - fail the request.
182 DCHECK(!is_new_database); 181 DCHECK(!is_new_database);
183 pending_->callbacks->OnError(IndexedDBDatabaseError( 182 pending_->OnError(IndexedDBDatabaseError(
184 blink::WebIDBDatabaseExceptionVersionError, 183 blink::WebIDBDatabaseExceptionVersionError,
185 ASCIIToUTF16("The requested version (") + 184 ASCIIToUTF16("The requested version (") +
186 Int64ToString16(pending_->version) + 185 Int64ToString16(pending_->version()) +
187 ASCIIToUTF16(") is less than the existing version (") + 186 ASCIIToUTF16(") is less than the existing version (") +
188 Int64ToString16(db_->metadata_.version) + ASCIIToUTF16(")."))); 187 Int64ToString16(db_->metadata_.version) + ASCIIToUTF16(").")));
189 db_->RequestComplete(this); 188 db_->RequestComplete(this);
190 return; 189 return;
191 } 190 }
192 191
193 // Requested version is higher than current version - upgrade needed. 192 // Requested version is higher than current version - upgrade needed.
194 DCHECK_GT(new_version, old_version); 193 DCHECK_GT(pending_->version(), old_version);
195 194
196 if (db_->connections_.empty()) { 195 if (db_->connections_.empty()) {
197 StartUpgrade(); 196 StartUpgrade();
198 return; 197 return;
199 } 198 }
200 199
201 // There are outstanding connections - fire "versionchange" events and 200 // There are outstanding connections - fire "versionchange" events and
202 // wait for the connections to close. Front end ensures the event is not 201 // wait for the connections to close. Front end ensures the event is not
203 // fired at connections that have close_pending set. A "blocked" event 202 // fired at connections that have close_pending set. A "blocked" event
204 // will be fired at the request when one of the connections acks that the 203 // will be fired at the request when one of the connections acks that the
205 // "versionchange" event was ignored. 204 // "versionchange" event was ignored.
206 DCHECK_NE(pending_->data_loss_info.status, blink::WebIDBDataLossTotal); 205 DCHECK_NE(pending_->data_loss_info().status, blink::WebIDBDataLossTotal);
207 for (const auto* connection : db_->connections_) 206 for (const auto* connection : db_->connections_)
208 connection->callbacks()->OnVersionChange(old_version, new_version); 207 connection->change_handler()->OnVersionChange(old_version,
208 pending_->version());
209 209
210 // When all connections have closed the upgrade can proceed. 210 // When all connections have closed the upgrade can proceed.
211 } 211 }
212 212
213 void OnVersionChangeIgnored() const override { 213 void OnVersionChangeIgnored() const override {
214 pending_->callbacks->OnBlocked(db_->metadata_.version); 214 pending_->OnBlocked(db_->metadata_.version);
215 } 215 }
216 216
217 void OnConnectionClosed(IndexedDBConnection* connection) override { 217 void OnConnectionClosed(IndexedDBConnection* connection) override {
218 // This connection closed prematurely; signal an error and complete. 218 // This connection closed prematurely; signal an error and complete.
219 if (connection && connection->callbacks() == pending_->database_callbacks) { 219 if (connection &&
220 pending_->callbacks->OnError( 220 connection->change_handler() == pending_->change_handler()) {
221 pending_->OnError(
221 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, 222 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
222 "The connection was closed.")); 223 "The connection was closed."));
223 db_->RequestComplete(this); 224 db_->RequestComplete(this);
224 return; 225 return;
225 } 226 }
226 227
227 if (!db_->connections_.empty()) 228 if (!db_->connections_.empty())
228 return; 229 return;
229 230
230 StartUpgrade(); 231 StartUpgrade();
231 } 232 }
232 233
233 // Initiate the upgrade. The bulk of the work actually happens in 234 // Initiate the upgrade. The bulk of the work actually happens in
234 // IndexedDBDatabase::VersionChangeOperation in order to kick the 235 // IndexedDBDatabase::VersionChangeOperation in order to kick the
235 // transaction into the correct state. 236 // transaction into the correct state.
236 void StartUpgrade() { 237 void StartUpgrade() {
237 connection_ = db_->CreateConnection(pending_->database_callbacks, 238 connection_ = db_->CreateConnection(pending_->change_handler(),
238 pending_->child_process_id); 239 pending_->child_process_id());
239 DCHECK_EQ(db_->connections_.count(connection_.get()), 1UL); 240 DCHECK_EQ(db_->connections_.count(connection_.get()), 1UL);
240 241
241 std::vector<int64_t> object_store_ids; 242 std::vector<int64_t> object_store_ids;
242 IndexedDBTransaction* transaction = db_->CreateTransaction( 243 IndexedDBTransaction* transaction = db_->CreateTransaction(
243 pending_->transaction_id, connection_.get(), object_store_ids, 244 pending_->transaction_id(), connection_.get(), object_store_ids,
244 blink::WebIDBTransactionModeVersionChange); 245 blink::WebIDBTransactionModeVersionChange);
245 246
246 DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction()); 247 DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction());
247 transaction->ScheduleTask( 248 transaction->ScheduleTask(
248 base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_, 249 base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_,
249 pending_->version, pending_->callbacks)); 250 base::Unretained(pending_.get())));
250 } 251 }
251 252
252 // Called when the upgrade transaction has started executing. 253 // Called when the upgrade transaction has started executing.
253 void UpgradeTransactionStarted(int64_t old_version) override { 254 void UpgradeTransactionStarted(int64_t old_version) override {
254 DCHECK(connection_); 255 DCHECK(connection_);
255 pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_), 256 pending_->OnUpgradeNeeded(old_version, connection_.get(), db_->metadata_);
256 db_->metadata_,
257 pending_->data_loss_info);
258 } 257 }
259 258
260 void UpgradeTransactionFinished(bool committed) override { 259 void UpgradeTransactionFinished(bool committed) override {
261 // Ownership of connection was already passed along in OnUpgradeNeeded. 260 // Ownership of connection was already passed along in OnUpgradeNeeded.
262 DCHECK(!connection_); 261 // Pending connection no longer moved in UpgradeTransactionStarted().
262 // DCHECK(!connection_);
263 263
264 if (committed) { 264 if (committed) {
265 DCHECK_EQ(pending_->version, db_->metadata_.version); 265 DCHECK_EQ(pending_->version(), db_->metadata_.version);
266 pending_->callbacks->OnSuccess(std::unique_ptr<IndexedDBConnection>(), 266 // TODO(cmumford): May still need to call RegisterTransactionId() because
267 db_->metadata()); 267 // onupgradeneeded might not have been called.
268 pending_->OnSuccess(std::move(connection_), db_->metadata());
268 } else { 269 } else {
269 DCHECK_NE(pending_->version, db_->metadata_.version); 270 DCHECK_NE(pending_->version(), db_->metadata_.version);
270 pending_->callbacks->OnError( 271 pending_->OnError(
271 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, 272 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
272 "Version change transaction was aborted in " 273 "Version change transaction was aborted in "
273 "upgradeneeded event handler.")); 274 "upgradeneeded event handler."));
274 } 275 }
275 db_->RequestComplete(this); 276 db_->RequestComplete(this);
276 } 277 }
277 278
278 private: 279 private:
279 std::unique_ptr<IndexedDBPendingConnection> pending_; 280 std::unique_ptr<IndexedDBPendingConnection> pending_;
280 281
281 // If an upgrade is needed, holds the pending connection until ownership is 282 // If an upgrade is needed, holds the pending connection until ownership is
282 // transferred to the IndexedDBDispatcherHost via OnUpgradeNeeded. 283 // transferred to the IndexedDBDispatcherHost via OnUpgradeNeeded.
283 std::unique_ptr<IndexedDBConnection> connection_; 284 std::unique_ptr<IndexedDBConnection> connection_;
284 285
285 DISALLOW_COPY_AND_ASSIGN(OpenRequest); 286 DISALLOW_COPY_AND_ASSIGN(OpenRequest);
286 }; 287 };
287 288
288 class IndexedDBDatabase::DeleteRequest 289 class IndexedDBDatabase::DeleteRequest
289 : public IndexedDBDatabase::ConnectionRequest { 290 : public IndexedDBDatabase::ConnectionRequest {
290 public: 291 public:
291 DeleteRequest(scoped_refptr<IndexedDBDatabase> db, 292 DeleteRequest(scoped_refptr<IndexedDBDatabase> db,
292 scoped_refptr<IndexedDBCallbacks> callbacks) 293 std::unique_ptr<IndexedDBPendingDelete> pending_delete)
293 : ConnectionRequest(db), callbacks_(callbacks) {} 294 : ConnectionRequest(db), pending_delete_(std::move(pending_delete)) {}
294 295
295 void Perform() override { 296 void Perform() override {
296 if (db_->connections_.empty()) { 297 if (db_->connections_.empty()) {
297 // No connections, so delete immediately. 298 // No connections, so delete immediately.
298 DoDelete(); 299 DoDelete();
299 return; 300 return;
300 } 301 }
301 302
302 // Front end ensures the event is not fired at connections that have 303 // Front end ensures the event is not fired at connections that have
303 // close_pending set. 304 // close_pending set.
304 const int64_t old_version = db_->metadata_.version; 305 const int64_t old_version = db_->metadata_.version;
305 const int64_t new_version = IndexedDBDatabaseMetadata::NO_VERSION; 306 const int64_t new_version = IndexedDBDatabaseMetadata::NO_VERSION;
306 for (const auto* connection : db_->connections_) 307 for (const auto* connection : db_->connections_)
307 connection->callbacks()->OnVersionChange(old_version, new_version); 308 connection->change_handler()->OnVersionChange(old_version, new_version);
308 } 309 }
309 310
310 void OnVersionChangeIgnored() const override { 311 void OnVersionChangeIgnored() const override {
311 callbacks_->OnBlocked(db_->metadata_.version); 312 pending_delete_->OnBlocked(db_->metadata_.version);
312 } 313 }
313 314
314 void OnConnectionClosed(IndexedDBConnection* connection) override { 315 void OnConnectionClosed(IndexedDBConnection* connection) override {
315 if (!db_->connections_.empty()) 316 if (!db_->connections_.empty())
316 return; 317 return;
317 DoDelete(); 318 DoDelete();
318 } 319 }
319 320
320 void DoDelete() { 321 void DoDelete() {
321 leveldb::Status s = 322 leveldb::Status s =
322 db_->backing_store_->DeleteDatabase(db_->metadata_.name); 323 db_->backing_store_->DeleteDatabase(db_->metadata_.name);
323 if (!s.ok()) { 324 if (!s.ok()) {
324 // TODO(jsbell): Consider including sanitized leveldb status message. 325 // TODO(jsbell): Consider including sanitized leveldb status message.
325 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 326 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
326 "Internal error deleting database."); 327 "Internal error deleting database.");
327 callbacks_->OnError(error); 328 pending_delete_->OnError(error);
328 if (s.IsCorruption()) { 329 if (s.IsCorruption()) {
329 url::Origin origin = db_->backing_store_->origin(); 330 url::Origin origin = db_->backing_store_->origin();
330 db_->backing_store_ = nullptr; 331 db_->backing_store_ = nullptr;
331 db_->factory_->HandleBackingStoreCorruption(origin, error); 332 db_->factory_->HandleBackingStoreCorruption(origin, error);
332 } 333 }
333 db_->RequestComplete(this); 334 db_->RequestComplete(this);
334 return; 335 return;
335 } 336 }
336 337
337 int64_t old_version = db_->metadata_.version; 338 int64_t old_version = db_->metadata_.version;
338 db_->metadata_.id = kInvalidId; 339 db_->metadata_.id = kInvalidId;
339 db_->metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION; 340 db_->metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION;
340 db_->metadata_.max_object_store_id = kInvalidId; 341 db_->metadata_.max_object_store_id = kInvalidId;
341 db_->metadata_.object_stores.clear(); 342 db_->metadata_.object_stores.clear();
342 callbacks_->OnSuccess(old_version); 343 pending_delete_->OnSuccess(old_version);
343 db_->factory_->DatabaseDeleted(db_->identifier_); 344 db_->factory_->DatabaseDeleted(db_->identifier_);
344 345
345 db_->RequestComplete(this); 346 db_->RequestComplete(this);
346 } 347 }
347 348
348 void UpgradeTransactionStarted(int64_t old_version) override { NOTREACHED(); } 349 void UpgradeTransactionStarted(int64_t old_version) override { NOTREACHED(); }
349 350
350 void UpgradeTransactionFinished(bool committed) override { NOTREACHED(); } 351 void UpgradeTransactionFinished(bool committed) override { NOTREACHED(); }
351 352
352 private: 353 private:
353 scoped_refptr<IndexedDBCallbacks> callbacks_; 354 std::unique_ptr<IndexedDBPendingDelete> pending_delete_;
354 355
355 DISALLOW_COPY_AND_ASSIGN(DeleteRequest); 356 DISALLOW_COPY_AND_ASSIGN(DeleteRequest);
356 }; 357 };
357 358
358 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( 359 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create(
359 const base::string16& name, 360 const base::string16& name,
360 IndexedDBBackingStore* backing_store, 361 IndexedDBBackingStore* backing_store,
361 IndexedDBFactory* factory, 362 IndexedDBFactory* factory,
362 const Identifier& unique_identifier, 363 const Identifier& unique_identifier,
363 leveldb::Status* s) { 364 leveldb::Status* s) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 DCHECK(transactions_.empty()); 455 DCHECK(transactions_.empty());
455 DCHECK(!active_request_); 456 DCHECK(!active_request_);
456 DCHECK(pending_requests_.empty()); 457 DCHECK(pending_requests_.empty());
457 } 458 }
458 459
459 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const { 460 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const {
460 return kMaxIDBMessageSizeInBytes; 461 return kMaxIDBMessageSizeInBytes;
461 } 462 }
462 463
463 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( 464 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
464 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 465 scoped_refptr<IndexedDBChangeHandler> change_handler,
465 int child_process_id) { 466 int child_process_id) {
466 std::unique_ptr<IndexedDBConnection> connection( 467 std::unique_ptr<IndexedDBConnection> connection(
467 base::MakeUnique<IndexedDBConnection>(this, database_callbacks)); 468 base::MakeUnique<IndexedDBConnection>(this, change_handler));
468 connections_.insert(connection.get()); 469 connections_.insert(connection.get());
469 backing_store_->GrantChildProcessPermissions(child_process_id); 470 backing_store_->GrantChildProcessPermissions(child_process_id);
470 return connection; 471 return connection;
471 } 472 }
472 473
473 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( 474 IndexedDBTransaction* IndexedDBDatabase::GetTransaction(
474 int64_t transaction_id) const { 475 int64_t transaction_id) const {
475 const auto& trans_iterator = transactions_.find(transaction_id); 476 const auto& trans_iterator = transactions_.find(transaction_id);
476 if (trans_iterator == transactions_.end()) 477 if (trans_iterator == transactions_.end())
477 return NULL; 478 return NULL;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 observer->id()); 811 observer->id());
811 } 812 }
812 } 813 }
813 } 814 }
814 815
815 void IndexedDBDatabase::SendObservations( 816 void IndexedDBDatabase::SendObservations(
816 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) { 817 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) {
817 for (auto* conn : connections_) { 818 for (auto* conn : connections_) {
818 auto it = changes_map.find(conn->id()); 819 auto it = changes_map.find(conn->id());
819 if (it != changes_map.end()) 820 if (it != changes_map.end())
820 conn->callbacks()->OnDatabaseChange(it->first, std::move(it->second)); 821 conn->change_handler()->OnDatabaseChange(it->first,
822 std::move(it->second));
821 } 823 }
822 } 824 }
823 825
824 void IndexedDBDatabase::GetAll(int64_t transaction_id, 826 void IndexedDBDatabase::GetAll(int64_t transaction_id,
825 int64_t object_store_id, 827 int64_t object_store_id,
826 int64_t index_id, 828 int64_t index_id,
827 std::unique_ptr<IndexedDBKeyRange> key_range, 829 std::unique_ptr<IndexedDBKeyRange> key_range,
828 bool key_only, 830 bool key_only,
829 int64_t max_count, 831 int64_t max_count) {
830 scoped_refptr<IndexedDBCallbacks> callbacks) {
831 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); 832 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id);
832 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 833 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
833 if (!transaction) 834 if (!transaction)
834 return; 835 return;
835 836
836 if (!ValidateObjectStoreId(object_store_id)) 837 if (!ValidateObjectStoreId(object_store_id))
837 return; 838 return;
838 839
839 transaction->ScheduleTask(base::Bind( 840 transaction->ScheduleTask(base::Bind(
840 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, 841 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id,
841 base::Passed(&key_range), 842 base::Passed(&key_range),
842 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, 843 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE,
843 max_count, callbacks)); 844 max_count));
844 } 845 }
845 846
846 void IndexedDBDatabase::Get(int64_t transaction_id, 847 void IndexedDBDatabase::Get(int64_t transaction_id,
847 int64_t object_store_id, 848 int64_t object_store_id,
848 int64_t index_id, 849 int64_t index_id,
849 std::unique_ptr<IndexedDBKeyRange> key_range, 850 std::unique_ptr<IndexedDBKeyRange> key_range,
850 bool key_only, 851 bool key_only) {
851 scoped_refptr<IndexedDBCallbacks> callbacks) {
852 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); 852 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id);
853 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 853 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
854 if (!transaction) 854 if (!transaction)
855 return; 855 return;
856 856
857 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) 857 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id))
858 return; 858 return;
859 859
860 transaction->ScheduleTask(base::Bind( 860 transaction->ScheduleTask(base::Bind(
861 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, 861 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id,
862 base::Passed(&key_range), 862 base::Passed(&key_range), key_only ? indexed_db::CURSOR_KEY_ONLY
863 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, 863 : indexed_db::CURSOR_KEY_AND_VALUE));
864 callbacks));
865 } 864 }
866 865
867 void IndexedDBDatabase::GetOperation( 866 void IndexedDBDatabase::GetOperation(
868 int64_t object_store_id, 867 int64_t object_store_id,
869 int64_t index_id, 868 int64_t index_id,
870 std::unique_ptr<IndexedDBKeyRange> key_range, 869 std::unique_ptr<IndexedDBKeyRange> key_range,
871 indexed_db::CursorType cursor_type, 870 indexed_db::CursorType cursor_type,
872 scoped_refptr<IndexedDBCallbacks> callbacks,
873 IndexedDBTransaction* transaction) { 871 IndexedDBTransaction* transaction) {
874 IDB_TRACE1("IndexedDBDatabase::GetOperation", "txn.id", transaction->id()); 872 IDB_TRACE1("IndexedDBDatabase::GetOperation", "txn.id", transaction->id());
875 873
876 DCHECK(metadata_.object_stores.find(object_store_id) != 874 DCHECK(metadata_.object_stores.find(object_store_id) !=
877 metadata_.object_stores.end()); 875 metadata_.object_stores.end());
878 const IndexedDBObjectStoreMetadata& object_store_metadata = 876 const IndexedDBObjectStoreMetadata& object_store_metadata =
879 metadata_.object_stores[object_store_id]; 877 metadata_.object_stores[object_store_id];
880 878
881 const IndexedDBKey* key; 879 const IndexedDBKey* key;
882 880
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 if (!s.ok()) { 918 if (!s.ok()) {
921 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); 919 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString();
922 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 920 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
923 "Internal error deleting data in range"); 921 "Internal error deleting data in range");
924 if (s.IsCorruption()) { 922 if (s.IsCorruption()) {
925 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 923 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
926 } 924 }
927 } 925 }
928 926
929 if (!backing_store_cursor) { 927 if (!backing_store_cursor) {
928 #ifdef CJM_NEED_CALLBACK
930 callbacks->OnSuccess(); 929 callbacks->OnSuccess();
930 #endif
931 return; 931 return;
932 } 932 }
933 933
934 key = &backing_store_cursor->key(); 934 key = &backing_store_cursor->key();
935 } 935 }
936 936
937 std::unique_ptr<IndexedDBKey> primary_key; 937 std::unique_ptr<IndexedDBKey> primary_key;
938 if (index_id == IndexedDBIndexMetadata::kInvalidId) { 938 if (index_id == IndexedDBIndexMetadata::kInvalidId) {
939 // Object Store Retrieval Operation 939 // Object Store Retrieval Operation
940 IndexedDBReturnValue value; 940 IndexedDBReturnValue value;
941 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 941 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
942 id(), 942 id(),
943 object_store_id, 943 object_store_id,
944 *key, 944 *key,
945 &value); 945 &value);
946 if (!s.ok()) { 946 if (!s.ok()) {
947 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 947 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
948 "Internal error in GetRecord."); 948 "Internal error in GetRecord.");
949 #ifdef CJM_NEED_CALLBACK
949 callbacks->OnError(error); 950 callbacks->OnError(error);
951 #endif
950 952
951 if (s.IsCorruption()) 953 if (s.IsCorruption())
952 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 954 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
953 return; 955 return;
954 } 956 }
955 957
956 if (value.empty()) { 958 if (value.empty()) {
959 #ifdef CJM_NEED_CALLBACK
957 callbacks->OnSuccess(); 960 callbacks->OnSuccess();
961 #endif
958 return; 962 return;
959 } 963 }
960 964
961 if (object_store_metadata.auto_increment && 965 if (object_store_metadata.auto_increment &&
962 !object_store_metadata.key_path.IsNull()) { 966 !object_store_metadata.key_path.IsNull()) {
963 value.primary_key = *key; 967 value.primary_key = *key;
964 value.key_path = object_store_metadata.key_path; 968 value.key_path = object_store_metadata.key_path;
965 } 969 }
966 970
971 #ifdef CJM_NEED_CALLBACK
967 callbacks->OnSuccess(&value); 972 callbacks->OnSuccess(&value);
973 #endif
968 return; 974 return;
969 } 975 }
970 976
971 // From here we are dealing only with indexes. 977 // From here we are dealing only with indexes.
972 s = backing_store_->GetPrimaryKeyViaIndex( 978 s = backing_store_->GetPrimaryKeyViaIndex(
973 transaction->BackingStoreTransaction(), 979 transaction->BackingStoreTransaction(),
974 id(), 980 id(),
975 object_store_id, 981 object_store_id,
976 index_id, 982 index_id,
977 *key, 983 *key,
978 &primary_key); 984 &primary_key);
979 if (!s.ok()) { 985 if (!s.ok()) {
980 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 986 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
981 "Internal error in GetPrimaryKeyViaIndex."); 987 "Internal error in GetPrimaryKeyViaIndex.");
988 #ifdef CJM_NEED_CALLBACK
982 callbacks->OnError(error); 989 callbacks->OnError(error);
990 #endif
983 if (s.IsCorruption()) 991 if (s.IsCorruption())
984 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 992 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
985 return; 993 return;
986 } 994 }
987 if (!primary_key) { 995 if (!primary_key) {
996 #ifdef CJM_NEED_CALLBACK
988 callbacks->OnSuccess(); 997 callbacks->OnSuccess();
998 #endif
989 return; 999 return;
990 } 1000 }
991 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 1001 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
992 // Index Value Retrieval Operation 1002 // Index Value Retrieval Operation
1003 #ifdef CJM_NEED_CALLBACK
993 callbacks->OnSuccess(*primary_key); 1004 callbacks->OnSuccess(*primary_key);
1005 #endif
994 return; 1006 return;
995 } 1007 }
996 1008
997 // Index Referenced Value Retrieval Operation 1009 // Index Referenced Value Retrieval Operation
998 IndexedDBReturnValue value; 1010 IndexedDBReturnValue value;
999 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 1011 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
1000 id(), 1012 id(),
1001 object_store_id, 1013 object_store_id,
1002 *primary_key, 1014 *primary_key,
1003 &value); 1015 &value);
1004 if (!s.ok()) { 1016 if (!s.ok()) {
1005 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1017 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1006 "Internal error in GetRecord."); 1018 "Internal error in GetRecord.");
1019 #ifdef CJM_NEED_CALLBACK
1007 callbacks->OnError(error); 1020 callbacks->OnError(error);
1021 #endif
1008 if (s.IsCorruption()) 1022 if (s.IsCorruption())
1009 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1023 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1010 return; 1024 return;
1011 } 1025 }
1012 1026
1013 if (value.empty()) { 1027 if (value.empty()) {
1028 #ifdef CJM_NEED_CALLBACK
1014 callbacks->OnSuccess(); 1029 callbacks->OnSuccess();
1030 #endif
1015 return; 1031 return;
1016 } 1032 }
1017 if (object_store_metadata.auto_increment && 1033 if (object_store_metadata.auto_increment &&
1018 !object_store_metadata.key_path.IsNull()) { 1034 !object_store_metadata.key_path.IsNull()) {
1019 value.primary_key = *primary_key; 1035 value.primary_key = *primary_key;
1020 value.key_path = object_store_metadata.key_path; 1036 value.key_path = object_store_metadata.key_path;
1021 } 1037 }
1038 #ifdef CJM_NEED_CALLBACK
1022 callbacks->OnSuccess(&value); 1039 callbacks->OnSuccess(&value);
1040 #endif
1023 } 1041 }
1024 1042
1025 void IndexedDBDatabase::GetAllOperation( 1043 void IndexedDBDatabase::GetAllOperation(
1026 int64_t object_store_id, 1044 int64_t object_store_id,
1027 int64_t index_id, 1045 int64_t index_id,
1028 std::unique_ptr<IndexedDBKeyRange> key_range, 1046 std::unique_ptr<IndexedDBKeyRange> key_range,
1029 indexed_db::CursorType cursor_type, 1047 indexed_db::CursorType cursor_type,
1030 int64_t max_count, 1048 int64_t max_count,
1031 scoped_refptr<IndexedDBCallbacks> callbacks,
1032 IndexedDBTransaction* transaction) { 1049 IndexedDBTransaction* transaction) {
1033 IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id()); 1050 IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id());
1034 1051
1035 DCHECK_GT(max_count, 0); 1052 DCHECK_GT(max_count, 0);
1036 1053
1037 DCHECK(metadata_.object_stores.find(object_store_id) != 1054 DCHECK(metadata_.object_stores.find(object_store_id) !=
1038 metadata_.object_stores.end()); 1055 metadata_.object_stores.end());
1039 const IndexedDBObjectStoreMetadata& object_store_metadata = 1056 const IndexedDBObjectStoreMetadata& object_store_metadata =
1040 metadata_.object_stores[object_store_id]; 1057 metadata_.object_stores[object_store_id];
1041 1058
(...skipping 26 matching lines...) Expand all
1068 cursor = backing_store_->OpenIndexCursor( 1085 cursor = backing_store_->OpenIndexCursor(
1069 transaction->BackingStoreTransaction(), id(), object_store_id, 1086 transaction->BackingStoreTransaction(), id(), object_store_id,
1070 index_id, *key_range, blink::WebIDBCursorDirectionNext, &s); 1087 index_id, *key_range, blink::WebIDBCursorDirectionNext, &s);
1071 } 1088 }
1072 } 1089 }
1073 1090
1074 if (!s.ok()) { 1091 if (!s.ok()) {
1075 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); 1092 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString();
1076 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1093 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1077 "Internal error in GetAllOperation"); 1094 "Internal error in GetAllOperation");
1095 #ifdef CJM_NEED_CALLBACK
1078 callbacks->OnError(error); 1096 callbacks->OnError(error);
1097 #endif
1079 if (s.IsCorruption()) { 1098 if (s.IsCorruption()) {
1080 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1099 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1081 } 1100 }
1082 return; 1101 return;
1083 } 1102 }
1084 1103
1085 std::vector<IndexedDBKey> found_keys; 1104 std::vector<IndexedDBKey> found_keys;
1086 std::vector<IndexedDBReturnValue> found_values; 1105 std::vector<IndexedDBReturnValue> found_values;
1087 if (!cursor) { 1106 if (!cursor) {
1088 // Doesn't matter if key or value array here - will be empty array when it 1107 // Doesn't matter if key or value array here - will be empty array when it
1089 // hits JavaScript. 1108 // hits JavaScript.
1109 #ifdef CJM_NEED_CALLBACK
1090 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); 1110 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path);
1111 #endif
1091 return; 1112 return;
1092 } 1113 }
1093 1114
1094 bool did_first_seek = false; 1115 bool did_first_seek = false;
1095 bool generated_key = object_store_metadata.auto_increment && 1116 bool generated_key = object_store_metadata.auto_increment &&
1096 !object_store_metadata.key_path.IsNull(); 1117 !object_store_metadata.key_path.IsNull();
1097 1118
1098 size_t response_size = kMaxIDBMessageOverhead; 1119 size_t response_size = kMaxIDBMessageOverhead;
1099 int64_t num_found_items = 0; 1120 int64_t num_found_items = 0;
1100 while (num_found_items++ < max_count) { 1121 while (num_found_items++ < max_count) {
1101 bool cursor_valid; 1122 bool cursor_valid;
1102 if (did_first_seek) { 1123 if (did_first_seek) {
1103 cursor_valid = cursor->Continue(&s); 1124 cursor_valid = cursor->Continue(&s);
1104 } else { 1125 } else {
1105 cursor_valid = cursor->FirstSeek(&s); 1126 cursor_valid = cursor->FirstSeek(&s);
1106 did_first_seek = true; 1127 did_first_seek = true;
1107 } 1128 }
1108 if (!s.ok()) { 1129 if (!s.ok()) {
1109 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1130 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1110 "Internal error in GetAllOperation."); 1131 "Internal error in GetAllOperation.");
1132 #ifdef CJM_NEED_CALLBACK
1111 callbacks->OnError(error); 1133 callbacks->OnError(error);
1134 #endif
1112 if (s.IsCorruption()) 1135 if (s.IsCorruption())
1113 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1136 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1114 return; 1137 return;
1115 } 1138 }
1116 1139
1117 if (!cursor_valid) 1140 if (!cursor_valid)
1118 break; 1141 break;
1119 1142
1120 IndexedDBReturnValue return_value; 1143 IndexedDBReturnValue return_value;
1121 IndexedDBKey return_key; 1144 IndexedDBKey return_key;
1122 1145
1123 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 1146 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
1124 return_key = cursor->primary_key(); 1147 return_key = cursor->primary_key();
1125 } else { 1148 } else {
1126 // Retrieving values 1149 // Retrieving values
1127 return_value.swap(*cursor->value()); 1150 return_value.swap(*cursor->value());
1128 if (!return_value.empty() && generated_key) { 1151 if (!return_value.empty() && generated_key) {
1129 return_value.primary_key = cursor->primary_key(); 1152 return_value.primary_key = cursor->primary_key();
1130 return_value.key_path = object_store_metadata.key_path; 1153 return_value.key_path = object_store_metadata.key_path;
1131 } 1154 }
1132 } 1155 }
1133 1156
1134 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) 1157 if (cursor_type == indexed_db::CURSOR_KEY_ONLY)
1135 response_size += return_key.size_estimate(); 1158 response_size += return_key.size_estimate();
1136 else 1159 else
1137 response_size += return_value.SizeEstimate(); 1160 response_size += return_value.SizeEstimate();
1138 if (response_size > GetMaxMessageSizeInBytes()) { 1161 if (response_size > GetMaxMessageSizeInBytes()) {
1162 #ifdef CJM_NEED_CALLBACK
1139 callbacks->OnError( 1163 callbacks->OnError(
1140 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 1164 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
1141 "Maximum IPC message size exceeded.")); 1165 "Maximum IPC message size exceeded."));
1166 #endif
1142 return; 1167 return;
1143 } 1168 }
1144 1169
1145 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) 1170 if (cursor_type == indexed_db::CURSOR_KEY_ONLY)
1146 found_keys.push_back(return_key); 1171 found_keys.push_back(return_key);
1147 else 1172 else
1148 found_values.push_back(return_value); 1173 found_values.push_back(return_value);
1149 } 1174 }
1150 1175
1176 #ifdef CJM_NEED_CALLBACK
1151 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 1177 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
1152 // IndexedDBKey already supports an array of values so we can leverage this 1178 // IndexedDBKey already supports an array of values so we can leverage this
1153 // to return an array of keys - no need to create our own array of keys. 1179 // to return an array of keys - no need to create our own array of keys.
1154 callbacks->OnSuccess(IndexedDBKey(found_keys)); 1180 callbacks->OnSuccess(IndexedDBKey(found_keys));
1155 } else { 1181 } else {
1156 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); 1182 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path);
1157 } 1183 }
1184 #endif
1158 } 1185 }
1159 1186
1160 static std::unique_ptr<IndexedDBKey> GenerateKey( 1187 static std::unique_ptr<IndexedDBKey> GenerateKey(
1161 IndexedDBBackingStore* backing_store, 1188 IndexedDBBackingStore* backing_store,
1162 IndexedDBTransaction* transaction, 1189 IndexedDBTransaction* transaction,
1163 int64_t database_id, 1190 int64_t database_id,
1164 int64_t object_store_id) { 1191 int64_t object_store_id) {
1165 const int64_t max_generator_value = 1192 const int64_t max_generator_value =
1166 9007199254740992LL; // Maximum integer storable as ECMAScript number. 1193 9007199254740992LL; // Maximum integer storable as ECMAScript number.
1167 int64_t current_number; 1194 int64_t current_number;
(...skipping 24 matching lines...) Expand all
1192 static_cast<int64_t>(floor(key.number())) + 1, check_current); 1219 static_cast<int64_t>(floor(key.number())) + 1, check_current);
1193 } 1220 }
1194 1221
1195 struct IndexedDBDatabase::PutOperationParams { 1222 struct IndexedDBDatabase::PutOperationParams {
1196 PutOperationParams() {} 1223 PutOperationParams() {}
1197 int64_t object_store_id; 1224 int64_t object_store_id;
1198 IndexedDBValue value; 1225 IndexedDBValue value;
1199 ScopedVector<storage::BlobDataHandle> handles; 1226 ScopedVector<storage::BlobDataHandle> handles;
1200 std::unique_ptr<IndexedDBKey> key; 1227 std::unique_ptr<IndexedDBKey> key;
1201 blink::WebIDBPutMode put_mode; 1228 blink::WebIDBPutMode put_mode;
1202 scoped_refptr<IndexedDBCallbacks> callbacks;
1203 std::vector<IndexKeys> index_keys; 1229 std::vector<IndexKeys> index_keys;
1204 1230
1205 private: 1231 private:
1206 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); 1232 DISALLOW_COPY_AND_ASSIGN(PutOperationParams);
1207 }; 1233 };
1208 1234
1209 void IndexedDBDatabase::Put(int64_t transaction_id, 1235 void IndexedDBDatabase::Put(int64_t transaction_id,
1210 int64_t object_store_id, 1236 int64_t object_store_id,
1211 IndexedDBValue* value, 1237 IndexedDBValue* value,
1212 ScopedVector<storage::BlobDataHandle>* handles, 1238 ScopedVector<storage::BlobDataHandle>* handles,
1213 std::unique_ptr<IndexedDBKey> key, 1239 std::unique_ptr<IndexedDBKey> key,
1214 blink::WebIDBPutMode put_mode, 1240 blink::WebIDBPutMode put_mode,
1215 scoped_refptr<IndexedDBCallbacks> callbacks,
1216 const std::vector<IndexKeys>& index_keys) { 1241 const std::vector<IndexKeys>& index_keys) {
1217 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); 1242 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id);
1218 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1243 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1219 if (!transaction) 1244 if (!transaction)
1220 return; 1245 return;
1221 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1246 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1222 1247
1223 if (!ValidateObjectStoreId(object_store_id)) 1248 if (!ValidateObjectStoreId(object_store_id))
1224 return; 1249 return;
1225 1250
1226 DCHECK(key); 1251 DCHECK(key);
1227 DCHECK(value); 1252 DCHECK(value);
1228 std::unique_ptr<PutOperationParams> params( 1253 std::unique_ptr<PutOperationParams> params(
1229 base::MakeUnique<PutOperationParams>()); 1254 base::MakeUnique<PutOperationParams>());
1230 params->object_store_id = object_store_id; 1255 params->object_store_id = object_store_id;
1231 params->value.swap(*value); 1256 params->value.swap(*value);
1232 params->handles.swap(*handles); 1257 params->handles.swap(*handles);
1233 params->key = std::move(key); 1258 params->key = std::move(key);
1234 params->put_mode = put_mode; 1259 params->put_mode = put_mode;
1235 params->callbacks = callbacks;
1236 params->index_keys = index_keys; 1260 params->index_keys = index_keys;
1237 transaction->ScheduleTask(base::Bind( 1261 transaction->ScheduleTask(base::Bind(
1238 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 1262 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
1239 } 1263 }
1240 1264
1241 void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params, 1265 void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
1242 IndexedDBTransaction* transaction) { 1266 IndexedDBTransaction* transaction) {
1243 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id()); 1267 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id());
1244 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1268 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1245 bool key_was_generated = false; 1269 bool key_was_generated = false;
1246 1270
1247 DCHECK(metadata_.object_stores.find(params->object_store_id) != 1271 DCHECK(metadata_.object_stores.find(params->object_store_id) !=
1248 metadata_.object_stores.end()); 1272 metadata_.object_stores.end());
1249 const IndexedDBObjectStoreMetadata& object_store = 1273 const IndexedDBObjectStoreMetadata& object_store =
1250 metadata_.object_stores[params->object_store_id]; 1274 metadata_.object_stores[params->object_store_id];
1251 DCHECK(object_store.auto_increment || params->key->IsValid()); 1275 DCHECK(object_store.auto_increment || params->key->IsValid());
1252 1276
1253 std::unique_ptr<IndexedDBKey> key; 1277 std::unique_ptr<IndexedDBKey> key;
1254 if (params->put_mode != blink::WebIDBPutModeCursorUpdate && 1278 if (params->put_mode != blink::WebIDBPutModeCursorUpdate &&
1255 object_store.auto_increment && !params->key->IsValid()) { 1279 object_store.auto_increment && !params->key->IsValid()) {
1256 std::unique_ptr<IndexedDBKey> auto_inc_key = GenerateKey( 1280 std::unique_ptr<IndexedDBKey> auto_inc_key = GenerateKey(
1257 backing_store_.get(), transaction, id(), params->object_store_id); 1281 backing_store_.get(), transaction, id(), params->object_store_id);
1258 key_was_generated = true; 1282 key_was_generated = true;
1259 if (!auto_inc_key->IsValid()) { 1283 if (!auto_inc_key->IsValid()) {
1284 #ifdef CJM_NEED_CALLBACK
1260 params->callbacks->OnError( 1285 params->callbacks->OnError(
1261 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, 1286 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
1262 "Maximum key generator value reached.")); 1287 "Maximum key generator value reached."));
1288 #endif
1263 return; 1289 return;
1264 } 1290 }
1265 key = std::move(auto_inc_key); 1291 key = std::move(auto_inc_key);
1266 } else { 1292 } else {
1267 key = std::move(params->key); 1293 key = std::move(params->key);
1268 } 1294 }
1269 1295
1270 DCHECK(key->IsValid()); 1296 DCHECK(key->IsValid());
1271 1297
1272 IndexedDBBackingStore::RecordIdentifier record_identifier; 1298 IndexedDBBackingStore::RecordIdentifier record_identifier;
1273 if (params->put_mode == blink::WebIDBPutModeAddOnly) { 1299 if (params->put_mode == blink::WebIDBPutModeAddOnly) {
1274 bool found = false; 1300 bool found = false;
1275 leveldb::Status s = backing_store_->KeyExistsInObjectStore( 1301 leveldb::Status s = backing_store_->KeyExistsInObjectStore(
1276 transaction->BackingStoreTransaction(), 1302 transaction->BackingStoreTransaction(),
1277 id(), 1303 id(),
1278 params->object_store_id, 1304 params->object_store_id,
1279 *key, 1305 *key,
1280 &record_identifier, 1306 &record_identifier,
1281 &found); 1307 &found);
1282 if (!s.ok()) { 1308 if (!s.ok()) {
1283 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1309 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1284 "Internal error checking key existence."); 1310 "Internal error checking key existence.");
1311 #ifdef CJM_NEED_CALLBACK
1285 params->callbacks->OnError(error); 1312 params->callbacks->OnError(error);
1313 #endif
1286 if (s.IsCorruption()) 1314 if (s.IsCorruption())
1287 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1315 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1288 return; 1316 return;
1289 } 1317 }
1290 if (found) { 1318 if (found) {
1319 #ifdef CJM_NEED_CALLBACK
1291 params->callbacks->OnError( 1320 params->callbacks->OnError(
1292 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, 1321 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
1293 "Key already exists in the object store.")); 1322 "Key already exists in the object store."));
1323 #endif
1294 return; 1324 return;
1295 } 1325 }
1296 } 1326 }
1297 1327
1298 ScopedVector<IndexWriter> index_writers; 1328 ScopedVector<IndexWriter> index_writers;
1299 base::string16 error_message; 1329 base::string16 error_message;
1300 bool obeys_constraints = false; 1330 bool obeys_constraints = false;
1301 bool backing_store_success = MakeIndexWriters(transaction, 1331 bool backing_store_success = MakeIndexWriters(transaction,
1302 backing_store_.get(), 1332 backing_store_.get(),
1303 id(), 1333 id(),
1304 object_store, 1334 object_store,
1305 *key, 1335 *key,
1306 key_was_generated, 1336 key_was_generated,
1307 params->index_keys, 1337 params->index_keys,
1308 &index_writers, 1338 &index_writers,
1309 &error_message, 1339 &error_message,
1310 &obeys_constraints); 1340 &obeys_constraints);
1311 if (!backing_store_success) { 1341 if (!backing_store_success) {
1342 #ifdef CJM_NEED_CALLBACK
1312 params->callbacks->OnError(IndexedDBDatabaseError( 1343 params->callbacks->OnError(IndexedDBDatabaseError(
1313 blink::WebIDBDatabaseExceptionUnknownError, 1344 blink::WebIDBDatabaseExceptionUnknownError,
1314 "Internal error: backing store error updating index keys.")); 1345 "Internal error: backing store error updating index keys."));
1346 #endif
1315 return; 1347 return;
1316 } 1348 }
1317 if (!obeys_constraints) { 1349 if (!obeys_constraints) {
1350 #ifdef CJM_NEED_CALLBACK
1318 params->callbacks->OnError(IndexedDBDatabaseError( 1351 params->callbacks->OnError(IndexedDBDatabaseError(
1319 blink::WebIDBDatabaseExceptionConstraintError, error_message)); 1352 blink::WebIDBDatabaseExceptionConstraintError, error_message));
1353 #endif
1320 return; 1354 return;
1321 } 1355 }
1322 1356
1323 // Before this point, don't do any mutation. After this point, rollback the 1357 // Before this point, don't do any mutation. After this point, rollback the
1324 // transaction in case of error. 1358 // transaction in case of error.
1325 leveldb::Status s = 1359 leveldb::Status s =
1326 backing_store_->PutRecord(transaction->BackingStoreTransaction(), 1360 backing_store_->PutRecord(transaction->BackingStoreTransaction(),
1327 id(), 1361 id(),
1328 params->object_store_id, 1362 params->object_store_id,
1329 *key, 1363 *key,
1330 &params->value, 1364 &params->value,
1331 &params->handles, 1365 &params->handles,
1332 &record_identifier); 1366 &record_identifier);
1333 if (!s.ok()) { 1367 if (!s.ok()) {
1334 IndexedDBDatabaseError error( 1368 IndexedDBDatabaseError error(
1335 blink::WebIDBDatabaseExceptionUnknownError, 1369 blink::WebIDBDatabaseExceptionUnknownError,
1336 "Internal error: backing store error performing put/add."); 1370 "Internal error: backing store error performing put/add.");
1371 #ifdef CJM_NEED_CALLBACK
1337 params->callbacks->OnError(error); 1372 params->callbacks->OnError(error);
1373 #endif
1338 if (s.IsCorruption()) 1374 if (s.IsCorruption())
1339 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1375 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1340 return; 1376 return;
1341 } 1377 }
1342 { 1378 {
1343 IDB_TRACE1("IndexedDBDatabase::PutOperation.UpdateIndexes", "txn.id", 1379 IDB_TRACE1("IndexedDBDatabase::PutOperation.UpdateIndexes", "txn.id",
1344 transaction->id()); 1380 transaction->id());
1345 for (size_t i = 0; i < index_writers.size(); ++i) { 1381 for (size_t i = 0; i < index_writers.size(); ++i) {
1346 IndexWriter* index_writer = index_writers[i]; 1382 IndexWriter* index_writer = index_writers[i];
1347 index_writer->WriteIndexKeys(record_identifier, backing_store_.get(), 1383 index_writer->WriteIndexKeys(record_identifier, backing_store_.get(),
1348 transaction->BackingStoreTransaction(), id(), 1384 transaction->BackingStoreTransaction(), id(),
1349 params->object_store_id); 1385 params->object_store_id);
1350 } 1386 }
1351 } 1387 }
1352 1388
1353 if (object_store.auto_increment && 1389 if (object_store.auto_increment &&
1354 params->put_mode != blink::WebIDBPutModeCursorUpdate && 1390 params->put_mode != blink::WebIDBPutModeCursorUpdate &&
1355 key->type() == WebIDBKeyTypeNumber) { 1391 key->type() == WebIDBKeyTypeNumber) {
1356 IDB_TRACE1("IndexedDBDatabase::PutOperation.AutoIncrement", "txn.id", 1392 IDB_TRACE1("IndexedDBDatabase::PutOperation.AutoIncrement", "txn.id",
1357 transaction->id()); 1393 transaction->id());
1358 leveldb::Status s = UpdateKeyGenerator(backing_store_.get(), 1394 leveldb::Status s = UpdateKeyGenerator(backing_store_.get(),
1359 transaction, 1395 transaction,
1360 id(), 1396 id(),
1361 params->object_store_id, 1397 params->object_store_id,
1362 *key, 1398 *key,
1363 !key_was_generated); 1399 !key_was_generated);
1364 if (!s.ok()) { 1400 if (!s.ok()) {
1365 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1401 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1366 "Internal error updating key generator."); 1402 "Internal error updating key generator.");
1403 #ifdef CJM_NEED_CALLBACK
1367 params->callbacks->OnError(error); 1404 params->callbacks->OnError(error);
1405 #endif
1368 if (s.IsCorruption()) 1406 if (s.IsCorruption())
1369 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1407 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1370 return; 1408 return;
1371 } 1409 }
1372 } 1410 }
1373 { 1411 {
1374 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", 1412 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id",
1375 transaction->id()); 1413 transaction->id());
1414 #ifdef CJM_NEED_CALLBACK
1376 params->callbacks->OnSuccess(*key); 1415 params->callbacks->OnSuccess(*key);
1416 #endif
1377 } 1417 }
1378 FilterObservation(transaction, params->object_store_id, 1418 FilterObservation(transaction, params->object_store_id,
1379 params->put_mode == blink::WebIDBPutModeAddOnly 1419 params->put_mode == blink::WebIDBPutModeAddOnly
1380 ? blink::WebIDBAdd 1420 ? blink::WebIDBAdd
1381 : blink::WebIDBPut, 1421 : blink::WebIDBPut,
1382 IndexedDBKeyRange(*key)); 1422 IndexedDBKeyRange(*key));
1383 } 1423 }
1384 1424
1385 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, 1425 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id,
1386 int64_t object_store_id, 1426 int64_t object_store_id,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 } 1520 }
1481 1521
1482 struct IndexedDBDatabase::OpenCursorOperationParams { 1522 struct IndexedDBDatabase::OpenCursorOperationParams {
1483 OpenCursorOperationParams() {} 1523 OpenCursorOperationParams() {}
1484 int64_t object_store_id; 1524 int64_t object_store_id;
1485 int64_t index_id; 1525 int64_t index_id;
1486 std::unique_ptr<IndexedDBKeyRange> key_range; 1526 std::unique_ptr<IndexedDBKeyRange> key_range;
1487 blink::WebIDBCursorDirection direction; 1527 blink::WebIDBCursorDirection direction;
1488 indexed_db::CursorType cursor_type; 1528 indexed_db::CursorType cursor_type;
1489 blink::WebIDBTaskType task_type; 1529 blink::WebIDBTaskType task_type;
1490 scoped_refptr<IndexedDBCallbacks> callbacks;
1491 1530
1492 private: 1531 private:
1493 DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); 1532 DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams);
1494 }; 1533 };
1495 1534
1496 void IndexedDBDatabase::OpenCursor( 1535 void IndexedDBDatabase::OpenCursor(int64_t transaction_id,
1497 int64_t transaction_id, 1536 int64_t object_store_id,
1498 int64_t object_store_id, 1537 int64_t index_id,
1499 int64_t index_id, 1538 std::unique_ptr<IndexedDBKeyRange> key_range,
1500 std::unique_ptr<IndexedDBKeyRange> key_range, 1539 blink::WebIDBCursorDirection direction,
1501 blink::WebIDBCursorDirection direction, 1540 bool key_only,
1502 bool key_only, 1541 blink::WebIDBTaskType task_type) {
1503 blink::WebIDBTaskType task_type,
1504 scoped_refptr<IndexedDBCallbacks> callbacks) {
1505 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); 1542 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id);
1506 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1543 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1507 if (!transaction) 1544 if (!transaction)
1508 return; 1545 return;
1509 1546
1510 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) 1547 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id))
1511 return; 1548 return;
1512 1549
1513 std::unique_ptr<OpenCursorOperationParams> params( 1550 std::unique_ptr<OpenCursorOperationParams> params(
1514 base::MakeUnique<OpenCursorOperationParams>()); 1551 base::MakeUnique<OpenCursorOperationParams>());
1515 params->object_store_id = object_store_id; 1552 params->object_store_id = object_store_id;
1516 params->index_id = index_id; 1553 params->index_id = index_id;
1517 params->key_range = std::move(key_range); 1554 params->key_range = std::move(key_range);
1518 params->direction = direction; 1555 params->direction = direction;
1519 params->cursor_type = 1556 params->cursor_type =
1520 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; 1557 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE;
1521 params->task_type = task_type; 1558 params->task_type = task_type;
1522 params->callbacks = callbacks;
1523 transaction->ScheduleTask(base::Bind( 1559 transaction->ScheduleTask(base::Bind(
1524 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(&params))); 1560 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(&params)));
1525 } 1561 }
1526 1562
1527 void IndexedDBDatabase::OpenCursorOperation( 1563 void IndexedDBDatabase::OpenCursorOperation(
1528 std::unique_ptr<OpenCursorOperationParams> params, 1564 std::unique_ptr<OpenCursorOperationParams> params,
1529 IndexedDBTransaction* transaction) { 1565 IndexedDBTransaction* transaction) {
1530 IDB_TRACE1( 1566 IDB_TRACE1(
1531 "IndexedDBDatabase::OpenCursorOperation", "txn.id", transaction->id()); 1567 "IndexedDBDatabase::OpenCursorOperation", "txn.id", transaction->id());
1532 1568
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); 1621 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString();
1586 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1622 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1587 "Internal error opening cursor operation"); 1623 "Internal error opening cursor operation");
1588 if (s.IsCorruption()) { 1624 if (s.IsCorruption()) {
1589 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1625 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1590 } 1626 }
1591 } 1627 }
1592 1628
1593 if (!backing_store_cursor) { 1629 if (!backing_store_cursor) {
1594 // Why is Success being called? 1630 // Why is Success being called?
1631 #ifdef CJM_NEED_CALLBACK
1595 params->callbacks->OnSuccess(nullptr); 1632 params->callbacks->OnSuccess(nullptr);
1633 #endif
1596 return; 1634 return;
1597 } 1635 }
1598 1636
1637 #ifdef CJM_NEED_CALLBACK
1599 scoped_refptr<IndexedDBCursor> cursor = 1638 scoped_refptr<IndexedDBCursor> cursor =
1600 new IndexedDBCursor(std::move(backing_store_cursor), params->cursor_type, 1639 new IndexedDBCursor(std::move(backing_store_cursor), params->cursor_type,
1601 params->task_type, transaction); 1640 params->task_type, transaction);
1602 params->callbacks->OnSuccess( 1641 params->callbacks->OnSuccess(
1603 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); 1642 cursor, cursor->key(), cursor->primary_key(), cursor->Value());
1643 #endif
1604 } 1644 }
1605 1645
1606 void IndexedDBDatabase::Count(int64_t transaction_id, 1646 void IndexedDBDatabase::Count(int64_t transaction_id,
1607 int64_t object_store_id, 1647 int64_t object_store_id,
1608 int64_t index_id, 1648 int64_t index_id,
1609 std::unique_ptr<IndexedDBKeyRange> key_range, 1649 std::unique_ptr<IndexedDBKeyRange> key_range) {
1610 scoped_refptr<IndexedDBCallbacks> callbacks) {
1611 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id); 1650 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id);
1612 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1651 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1613 if (!transaction) 1652 if (!transaction)
1614 return; 1653 return;
1615 1654
1616 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) 1655 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id))
1617 return; 1656 return;
1618 1657
1619 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, 1658 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, this,
1620 this, 1659 object_store_id, index_id,
1621 object_store_id, 1660 base::Passed(&key_range)));
1622 index_id,
1623 base::Passed(&key_range),
1624 callbacks));
1625 } 1661 }
1626 1662
1627 void IndexedDBDatabase::CountOperation( 1663 void IndexedDBDatabase::CountOperation(
1628 int64_t object_store_id, 1664 int64_t object_store_id,
1629 int64_t index_id, 1665 int64_t index_id,
1630 std::unique_ptr<IndexedDBKeyRange> key_range, 1666 std::unique_ptr<IndexedDBKeyRange> key_range,
1631 scoped_refptr<IndexedDBCallbacks> callbacks,
1632 IndexedDBTransaction* transaction) { 1667 IndexedDBTransaction* transaction) {
1633 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id()); 1668 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id());
1634 uint32_t count = 0; 1669 uint32_t count = 0;
1635 std::unique_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; 1670 std::unique_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor;
1636 1671
1637 leveldb::Status s; 1672 leveldb::Status s;
1638 if (index_id == IndexedDBIndexMetadata::kInvalidId) { 1673 if (index_id == IndexedDBIndexMetadata::kInvalidId) {
1639 backing_store_cursor = backing_store_->OpenObjectStoreKeyCursor( 1674 backing_store_cursor = backing_store_->OpenObjectStoreKeyCursor(
1640 transaction->BackingStoreTransaction(), 1675 transaction->BackingStoreTransaction(),
1641 id(), 1676 id(),
(...skipping 13 matching lines...) Expand all
1655 } 1690 }
1656 if (!s.ok()) { 1691 if (!s.ok()) {
1657 DLOG(ERROR) << "Unable perform count operation: " << s.ToString(); 1692 DLOG(ERROR) << "Unable perform count operation: " << s.ToString();
1658 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1693 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1659 "Internal error performing count operation"); 1694 "Internal error performing count operation");
1660 if (s.IsCorruption()) { 1695 if (s.IsCorruption()) {
1661 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1696 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1662 } 1697 }
1663 } 1698 }
1664 if (!backing_store_cursor) { 1699 if (!backing_store_cursor) {
1700 #ifdef CJM_NEED_CALLBACK
1665 callbacks->OnSuccess(count); 1701 callbacks->OnSuccess(count);
1702 #endif
1666 return; 1703 return;
1667 } 1704 }
1668 1705
1669 do { 1706 do {
1670 ++count; 1707 ++count;
1671 } while (backing_store_cursor->Continue(&s)); 1708 } while (backing_store_cursor->Continue(&s));
1672 1709
1673 // TODO(cmumford): Check for database corruption. 1710 // TODO(cmumford): Check for database corruption.
1674 1711
1712 #ifdef CJM_NEED_CALLBACK
1675 callbacks->OnSuccess(count); 1713 callbacks->OnSuccess(count);
1714 #endif
1676 } 1715 }
1677 1716
1678 void IndexedDBDatabase::DeleteRange( 1717 void IndexedDBDatabase::DeleteRange(
1679 int64_t transaction_id, 1718 int64_t transaction_id,
1680 int64_t object_store_id, 1719 int64_t object_store_id,
1681 std::unique_ptr<IndexedDBKeyRange> key_range, 1720 std::unique_ptr<IndexedDBKeyRange> key_range) {
1682 scoped_refptr<IndexedDBCallbacks> callbacks) {
1683 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id); 1721 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id);
1684 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1722 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1685 if (!transaction) 1723 if (!transaction)
1686 return; 1724 return;
1687 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1725 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1688 1726
1689 if (!ValidateObjectStoreId(object_store_id)) 1727 if (!ValidateObjectStoreId(object_store_id))
1690 return; 1728 return;
1691 1729
1692 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, 1730 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation,
1693 this, 1731 this, object_store_id,
1694 object_store_id, 1732 base::Passed(&key_range)));
1695 base::Passed(&key_range),
1696 callbacks));
1697 } 1733 }
1698 1734
1699 void IndexedDBDatabase::DeleteRangeOperation( 1735 void IndexedDBDatabase::DeleteRangeOperation(
1700 int64_t object_store_id, 1736 int64_t object_store_id,
1701 std::unique_ptr<IndexedDBKeyRange> key_range, 1737 std::unique_ptr<IndexedDBKeyRange> key_range,
1702 scoped_refptr<IndexedDBCallbacks> callbacks,
1703 IndexedDBTransaction* transaction) { 1738 IndexedDBTransaction* transaction) {
1704 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", 1739 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id",
1705 transaction->id()); 1740 transaction->id());
1706 size_t delete_count = 0; 1741 size_t delete_count = 0;
1707 leveldb::Status s = 1742 leveldb::Status s =
1708 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), 1743 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(),
1709 object_store_id, *key_range, &delete_count); 1744 object_store_id, *key_range, &delete_count);
1710 if (!s.ok()) { 1745 if (!s.ok()) {
1711 base::string16 error_string = 1746 base::string16 error_string =
1712 ASCIIToUTF16("Internal error deleting data in range"); 1747 ASCIIToUTF16("Internal error deleting data in range");
1713 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1748 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1714 error_string); 1749 error_string);
1715 transaction->Abort(error); 1750 transaction->Abort(error);
1716 if (s.IsCorruption()) { 1751 if (s.IsCorruption()) {
1717 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1752 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1718 } 1753 }
1719 return; 1754 return;
1720 } 1755 }
1756 #ifdef CJM_NEED_CALLBACK
1721 if (experimental_web_platform_features_enabled_) { 1757 if (experimental_web_platform_features_enabled_) {
1722 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); 1758 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count));
1723 } else { 1759 } else {
1724 callbacks->OnSuccess(); 1760 callbacks->OnSuccess();
1725 } 1761 }
1762 #endif
1726 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, 1763 FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
1727 *key_range); 1764 *key_range);
1728 } 1765 }
1729 1766
1730 void IndexedDBDatabase::Clear(int64_t transaction_id, 1767 void IndexedDBDatabase::Clear(int64_t transaction_id, int64_t object_store_id) {
1731 int64_t object_store_id,
1732 scoped_refptr<IndexedDBCallbacks> callbacks) {
1733 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); 1768 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id);
1734 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1769 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1735 if (!transaction) 1770 if (!transaction)
1736 return; 1771 return;
1737 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1772 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1738 1773
1739 if (!ValidateObjectStoreId(object_store_id)) 1774 if (!ValidateObjectStoreId(object_store_id))
1740 return; 1775 return;
1741 1776
1742 transaction->ScheduleTask(base::Bind( 1777 transaction->ScheduleTask(
1743 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); 1778 base::Bind(&IndexedDBDatabase::ClearOperation, this, object_store_id));
1744 } 1779 }
1745 1780
1746 void IndexedDBDatabase::ClearOperation( 1781 void IndexedDBDatabase::ClearOperation(
1747 int64_t object_store_id, 1782 int64_t object_store_id,
1748 scoped_refptr<IndexedDBCallbacks> callbacks,
1749 IndexedDBTransaction* transaction) { 1783 IndexedDBTransaction* transaction) {
1750 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); 1784 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id());
1751 leveldb::Status s = backing_store_->ClearObjectStore( 1785 leveldb::Status s = backing_store_->ClearObjectStore(
1752 transaction->BackingStoreTransaction(), id(), object_store_id); 1786 transaction->BackingStoreTransaction(), id(), object_store_id);
1753 if (!s.ok()) { 1787 if (!s.ok()) {
1754 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1788 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1755 "Internal error clearing object store"); 1789 "Internal error clearing object store");
1790 #ifdef CJM_NEED_CALLBACK
1756 callbacks->OnError(error); 1791 callbacks->OnError(error);
1792 #endif
1757 if (s.IsCorruption()) { 1793 if (s.IsCorruption()) {
1758 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1794 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1759 } 1795 }
1760 return; 1796 return;
1761 } 1797 }
1798 #ifdef CJM_NEED_CALLBACK
1762 callbacks->OnSuccess(); 1799 callbacks->OnSuccess();
1800 #endif
1763 1801
1764 FilterObservation(transaction, object_store_id, blink::WebIDBClear, 1802 FilterObservation(transaction, object_store_id, blink::WebIDBClear,
1765 IndexedDBKeyRange()); 1803 IndexedDBKeyRange());
1766 } 1804 }
1767 1805
1768 void IndexedDBDatabase::DeleteObjectStoreOperation( 1806 void IndexedDBDatabase::DeleteObjectStoreOperation(
1769 int64_t object_store_id, 1807 int64_t object_store_id,
1770 IndexedDBTransaction* transaction) { 1808 IndexedDBTransaction* transaction) {
1771 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", 1809 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation",
1772 "txn.id", 1810 "txn.id",
(...skipping 18 matching lines...) Expand all
1791 } 1829 }
1792 1830
1793 RemoveObjectStore(object_store_id); 1831 RemoveObjectStore(object_store_id);
1794 transaction->ScheduleAbortTask( 1832 transaction->ScheduleAbortTask(
1795 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, 1833 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation,
1796 this, 1834 this,
1797 object_store_metadata)); 1835 object_store_metadata));
1798 } 1836 }
1799 1837
1800 void IndexedDBDatabase::VersionChangeOperation( 1838 void IndexedDBDatabase::VersionChangeOperation(
1801 int64_t version, 1839 const IndexedDBPendingConnection* pending_connection,
1802 scoped_refptr<IndexedDBCallbacks> callbacks,
1803 IndexedDBTransaction* transaction) { 1840 IndexedDBTransaction* transaction) {
1804 IDB_TRACE1( 1841 IDB_TRACE1(
1805 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); 1842 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id());
1806 int64_t old_version = metadata_.version; 1843 int64_t old_version = metadata_.version;
1807 DCHECK_GT(version, old_version); 1844 DCHECK_GT(pending_connection->version(), old_version);
1808 1845
1809 if (!backing_store_->UpdateIDBDatabaseIntVersion( 1846 if (!backing_store_->UpdateIDBDatabaseIntVersion(
1810 transaction->BackingStoreTransaction(), id(), version)) { 1847 transaction->BackingStoreTransaction(), id(),
1848 pending_connection->version())) {
1811 IndexedDBDatabaseError error( 1849 IndexedDBDatabaseError error(
1812 blink::WebIDBDatabaseExceptionUnknownError, 1850 blink::WebIDBDatabaseExceptionUnknownError,
1813 ASCIIToUTF16( 1851 ASCIIToUTF16(
1814 "Internal error writing data to stable storage when " 1852 "Internal error writing data to stable storage when "
1815 "updating version.")); 1853 "updating version."));
1816 callbacks->OnError(error); 1854 pending_connection->OnError(error);
1817 transaction->Abort(error); 1855 transaction->Abort(error);
1818 return; 1856 return;
1819 } 1857 }
1820 1858
1821 transaction->ScheduleAbortTask( 1859 transaction->ScheduleAbortTask(
1822 base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this, 1860 base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this,
1823 metadata_.version)); 1861 metadata_.version));
1824 metadata_.version = version; 1862 metadata_.version = pending_connection->version();
1825 1863
1826 active_request_->UpgradeTransactionStarted(old_version); 1864 active_request_->UpgradeTransactionStarted(old_version);
1827 } 1865 }
1828 1866
1829 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, 1867 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction,
1830 bool committed) { 1868 bool committed) {
1831 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", id()); 1869 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", id());
1832 DCHECK(transactions_.find(transaction->id()) != transactions_.end()); 1870 DCHECK(transactions_.find(transaction->id()) != transactions_.end());
1833 DCHECK_EQ(transactions_[transaction->id()], transaction); 1871 DCHECK_EQ(transactions_[transaction->id()], transaction);
1834 transactions_.erase(transaction->id()); 1872 transactions_.erase(transaction->id());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { 1954 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) {
1917 transactions_[transaction->id()] = transaction; 1955 transactions_[transaction->id()] = transaction;
1918 } 1956 }
1919 1957
1920 void IndexedDBDatabase::OpenConnection( 1958 void IndexedDBDatabase::OpenConnection(
1921 std::unique_ptr<IndexedDBPendingConnection> connection) { 1959 std::unique_ptr<IndexedDBPendingConnection> connection) {
1922 AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection))); 1960 AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection)));
1923 } 1961 }
1924 1962
1925 void IndexedDBDatabase::DeleteDatabase( 1963 void IndexedDBDatabase::DeleteDatabase(
1926 scoped_refptr<IndexedDBCallbacks> callbacks) { 1964 std::unique_ptr<IndexedDBPendingDelete> pending_delete) {
1927 AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks)); 1965 AppendRequest(
1966 base::MakeUnique<DeleteRequest>(this, std::move(pending_delete)));
1928 } 1967 }
1929 1968
1930 void IndexedDBDatabase::ForceClose() { 1969 void IndexedDBDatabase::ForceClose() {
1931 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. 1970 // IndexedDBConnection::ForceClose() may delete this database, so hold ref.
1932 scoped_refptr<IndexedDBDatabase> protect(this); 1971 scoped_refptr<IndexedDBDatabase> protect(this);
1933 auto it = connections_.begin(); 1972 auto it = connections_.begin();
1934 while (it != connections_.end()) { 1973 while (it != connections_.end()) {
1935 IndexedDBConnection* connection = *it++; 1974 IndexedDBConnection* connection = *it++;
1936 connection->ForceClose(); 1975 connection->ForceClose();
1937 } 1976 }
(...skipping 12 matching lines...) Expand all
1950 1989
1951 IDB_TRACE("IndexedDBDatabase::Close"); 1990 IDB_TRACE("IndexedDBDatabase::Close");
1952 1991
1953 // Abort outstanding transactions from the closing connection. This can not 1992 // Abort outstanding transactions from the closing connection. This can not
1954 // happen if the close is requested by the connection itself as the 1993 // happen if the close is requested by the connection itself as the
1955 // front-end defers the close until all transactions are complete, but can 1994 // front-end defers the close until all transactions are complete, but can
1956 // occur on process termination or forced close. 1995 // occur on process termination or forced close.
1957 { 1996 {
1958 auto transactions(transactions_); 1997 auto transactions(transactions_);
1959 for (const auto& it : transactions) { 1998 for (const auto& it : transactions) {
1960 if (it.second->callbacks() == connection->callbacks()) 1999 if (it.second->change_handler() == connection->change_handler())
1961 it.second->Abort( 2000 it.second->Abort(
1962 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 2001 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
1963 "Connection is closing.")); 2002 "Connection is closing."));
1964 } 2003 }
1965 } 2004 }
1966 2005
1967 // Abort transactions before removing the connection; aborting may complete 2006 // Abort transactions before removing the connection; aborting may complete
1968 // an upgrade, and thus allow the next open/delete requests to proceed. The 2007 // an upgrade, and thus allow the next open/delete requests to proceed. The
1969 // new active_request_ should see the old connection count until explicitly 2008 // new active_request_ should see the old connection count until explicitly
1970 // notified below. 2009 // notified below.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 } 2042 }
2004 2043
2005 void IndexedDBDatabase::VersionChangeAbortOperation( 2044 void IndexedDBDatabase::VersionChangeAbortOperation(
2006 int64_t previous_version, 2045 int64_t previous_version,
2007 IndexedDBTransaction* transaction) { 2046 IndexedDBTransaction* transaction) {
2008 DCHECK(!transaction); 2047 DCHECK(!transaction);
2009 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 2048 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
2010 metadata_.version = previous_version; 2049 metadata_.version = previous_version;
2011 } 2050 }
2012 2051
2052 IndexedDBContext* IndexedDBDatabase::context() const {
2053 return factory_->context();
2054 }
2055
2013 } // namespace content 2056 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.h ('k') | content/browser/indexed_db/indexed_db_database_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698