dom/indexedDB/ipc/IndexedDBChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "base/basictypes.h"
michael@0 6
michael@0 7 #include "IndexedDBChild.h"
michael@0 8
michael@0 9 #include "nsIInputStream.h"
michael@0 10
michael@0 11 #include "mozilla/Assertions.h"
michael@0 12 #include "mozilla/dom/ContentChild.h"
michael@0 13 #include "mozilla/dom/quota/Client.h"
michael@0 14 #include "mozilla/dom/quota/QuotaManager.h"
michael@0 15
michael@0 16 #include "AsyncConnectionHelper.h"
michael@0 17 #include "DatabaseInfo.h"
michael@0 18 #include "IDBEvents.h"
michael@0 19 #include "IDBFactory.h"
michael@0 20 #include "IDBIndex.h"
michael@0 21 #include "IDBObjectStore.h"
michael@0 22 #include "IDBTransaction.h"
michael@0 23
michael@0 24 USING_INDEXEDDB_NAMESPACE
michael@0 25
michael@0 26 using namespace mozilla::dom;
michael@0 27 using mozilla::dom::quota::Client;
michael@0 28 using mozilla::dom::quota::QuotaManager;
michael@0 29
michael@0 30 namespace {
michael@0 31
michael@0 32 class IPCOpenDatabaseHelper : public AsyncConnectionHelper
michael@0 33 {
michael@0 34 public:
michael@0 35 IPCOpenDatabaseHelper(IDBDatabase* aDatabase, IDBOpenDBRequest* aRequest)
michael@0 36 : AsyncConnectionHelper(aDatabase, aRequest)
michael@0 37 {
michael@0 38 MOZ_ASSERT(aRequest);
michael@0 39 }
michael@0 40
michael@0 41 virtual nsresult UnpackResponseFromParentProcess(
michael@0 42 const ResponseValue& aResponseValue)
michael@0 43 MOZ_OVERRIDE;
michael@0 44
michael@0 45 virtual ChildProcessSendResult
michael@0 46 SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
michael@0 47
michael@0 48 virtual nsresult
michael@0 49 GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
michael@0 50
michael@0 51 virtual nsresult
michael@0 52 OnSuccess() MOZ_OVERRIDE
michael@0 53 {
michael@0 54 static_cast<IDBOpenDBRequest*>(mRequest.get())->SetTransaction(nullptr);
michael@0 55 return AsyncConnectionHelper::OnSuccess();
michael@0 56 }
michael@0 57
michael@0 58 virtual void
michael@0 59 OnError() MOZ_OVERRIDE
michael@0 60 {
michael@0 61 static_cast<IDBOpenDBRequest*>(mRequest.get())->SetTransaction(nullptr);
michael@0 62 AsyncConnectionHelper::OnError();
michael@0 63 }
michael@0 64
michael@0 65 virtual nsresult
michael@0 66 DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE;
michael@0 67 };
michael@0 68
michael@0 69 class IPCSetVersionHelper : public AsyncConnectionHelper
michael@0 70 {
michael@0 71 nsRefPtr<IDBOpenDBRequest> mOpenRequest;
michael@0 72 uint64_t mOldVersion;
michael@0 73 uint64_t mRequestedVersion;
michael@0 74
michael@0 75 public:
michael@0 76 IPCSetVersionHelper(IDBTransaction* aTransaction, IDBOpenDBRequest* aRequest,
michael@0 77 uint64_t aOldVersion, uint64_t aRequestedVersion)
michael@0 78 : AsyncConnectionHelper(aTransaction, aRequest),
michael@0 79 mOpenRequest(aRequest), mOldVersion(aOldVersion),
michael@0 80 mRequestedVersion(aRequestedVersion)
michael@0 81 {
michael@0 82 MOZ_ASSERT(aTransaction);
michael@0 83 MOZ_ASSERT(aRequest);
michael@0 84 }
michael@0 85
michael@0 86 virtual nsresult UnpackResponseFromParentProcess(
michael@0 87 const ResponseValue& aResponseValue)
michael@0 88 MOZ_OVERRIDE;
michael@0 89
michael@0 90 virtual ChildProcessSendResult
michael@0 91 SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
michael@0 92
michael@0 93 virtual nsresult
michael@0 94 DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE;
michael@0 95
michael@0 96 virtual already_AddRefed<nsIDOMEvent>
michael@0 97 CreateSuccessEvent(mozilla::dom::EventTarget* aOwner) MOZ_OVERRIDE;
michael@0 98
michael@0 99 virtual nsresult
michael@0 100 GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
michael@0 101 };
michael@0 102
michael@0 103 class IPCDeleteDatabaseHelper : public AsyncConnectionHelper
michael@0 104 {
michael@0 105 public:
michael@0 106 IPCDeleteDatabaseHelper(IDBRequest* aRequest)
michael@0 107 : AsyncConnectionHelper(static_cast<IDBDatabase*>(nullptr), aRequest)
michael@0 108 { }
michael@0 109
michael@0 110 virtual nsresult UnpackResponseFromParentProcess(
michael@0 111 const ResponseValue& aResponseValue)
michael@0 112 MOZ_OVERRIDE;
michael@0 113
michael@0 114 virtual ChildProcessSendResult
michael@0 115 SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
michael@0 116
michael@0 117 virtual nsresult
michael@0 118 GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
michael@0 119
michael@0 120 virtual nsresult
michael@0 121 DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE;
michael@0 122 };
michael@0 123
michael@0 124 class VersionChangeRunnable : public nsRunnable
michael@0 125 {
michael@0 126 nsRefPtr<IDBDatabase> mDatabase;
michael@0 127 uint64_t mOldVersion;
michael@0 128 uint64_t mNewVersion;
michael@0 129
michael@0 130 public:
michael@0 131 VersionChangeRunnable(IDBDatabase* aDatabase, const uint64_t& aOldVersion,
michael@0 132 const uint64_t& aNewVersion)
michael@0 133 : mDatabase(aDatabase), mOldVersion(aOldVersion), mNewVersion(aNewVersion)
michael@0 134 {
michael@0 135 MOZ_ASSERT(aDatabase);
michael@0 136 }
michael@0 137
michael@0 138 NS_IMETHOD Run() MOZ_OVERRIDE
michael@0 139 {
michael@0 140 if (mDatabase->IsClosed()) {
michael@0 141 return NS_OK;
michael@0 142 }
michael@0 143
michael@0 144 nsRefPtr<Event> event =
michael@0 145 IDBVersionChangeEvent::Create(mDatabase, mOldVersion, mNewVersion);
michael@0 146 MOZ_ASSERT(event);
michael@0 147
michael@0 148 bool dummy;
michael@0 149 nsresult rv = mDatabase->DispatchEvent(event, &dummy);
michael@0 150 NS_ENSURE_SUCCESS(rv, rv);
michael@0 151
michael@0 152 return NS_OK;
michael@0 153 }
michael@0 154 };
michael@0 155
michael@0 156 } // anonymous namespace
michael@0 157
michael@0 158 /*******************************************************************************
michael@0 159 * IndexedDBChild
michael@0 160 ******************************************************************************/
michael@0 161
michael@0 162 IndexedDBChild::IndexedDBChild(const nsCString& aASCIIOrigin)
michael@0 163 : mFactory(nullptr), mASCIIOrigin(aASCIIOrigin)
michael@0 164 #ifdef DEBUG
michael@0 165 , mDisconnected(false)
michael@0 166 #endif
michael@0 167 {
michael@0 168 MOZ_COUNT_CTOR(IndexedDBChild);
michael@0 169 }
michael@0 170
michael@0 171 IndexedDBChild::~IndexedDBChild()
michael@0 172 {
michael@0 173 MOZ_COUNT_DTOR(IndexedDBChild);
michael@0 174 MOZ_ASSERT(!mFactory);
michael@0 175 }
michael@0 176
michael@0 177 void
michael@0 178 IndexedDBChild::SetFactory(IDBFactory* aFactory)
michael@0 179 {
michael@0 180 MOZ_ASSERT(aFactory);
michael@0 181 MOZ_ASSERT(!mFactory);
michael@0 182
michael@0 183 aFactory->SetActor(this);
michael@0 184 mFactory = aFactory;
michael@0 185 }
michael@0 186
michael@0 187 void
michael@0 188 IndexedDBChild::Disconnect()
michael@0 189 {
michael@0 190 #ifdef DEBUG
michael@0 191 MOZ_ASSERT(!mDisconnected);
michael@0 192 mDisconnected = true;
michael@0 193 #endif
michael@0 194
michael@0 195 const InfallibleTArray<PIndexedDBDatabaseChild*>& databases =
michael@0 196 ManagedPIndexedDBDatabaseChild();
michael@0 197 for (uint32_t i = 0; i < databases.Length(); ++i) {
michael@0 198 static_cast<IndexedDBDatabaseChild*>(databases[i])->Disconnect();
michael@0 199 }
michael@0 200 }
michael@0 201
michael@0 202 void
michael@0 203 IndexedDBChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 204 {
michael@0 205 if (mFactory) {
michael@0 206 mFactory->SetActor(static_cast<IndexedDBChild*>(nullptr));
michael@0 207 #ifdef DEBUG
michael@0 208 mFactory = nullptr;
michael@0 209 #endif
michael@0 210 }
michael@0 211 }
michael@0 212
michael@0 213 PIndexedDBDatabaseChild*
michael@0 214 IndexedDBChild::AllocPIndexedDBDatabaseChild(
michael@0 215 const nsString& aName,
michael@0 216 const uint64_t& aVersion,
michael@0 217 const PersistenceType& aPersistenceType)
michael@0 218 {
michael@0 219 return new IndexedDBDatabaseChild(aName, aVersion);
michael@0 220 }
michael@0 221
michael@0 222 bool
michael@0 223 IndexedDBChild::DeallocPIndexedDBDatabaseChild(PIndexedDBDatabaseChild* aActor)
michael@0 224 {
michael@0 225 delete aActor;
michael@0 226 return true;
michael@0 227 }
michael@0 228
michael@0 229 PIndexedDBDeleteDatabaseRequestChild*
michael@0 230 IndexedDBChild::AllocPIndexedDBDeleteDatabaseRequestChild(
michael@0 231 const nsString& aName,
michael@0 232 const PersistenceType& aPersistenceType)
michael@0 233 {
michael@0 234 MOZ_CRASH("Caller is supposed to manually construct a request!");
michael@0 235 }
michael@0 236
michael@0 237 bool
michael@0 238 IndexedDBChild::DeallocPIndexedDBDeleteDatabaseRequestChild(
michael@0 239 PIndexedDBDeleteDatabaseRequestChild* aActor)
michael@0 240 {
michael@0 241 delete aActor;
michael@0 242 return true;
michael@0 243 }
michael@0 244
michael@0 245 /*******************************************************************************
michael@0 246 * IndexedDBDatabaseChild
michael@0 247 ******************************************************************************/
michael@0 248
michael@0 249 IndexedDBDatabaseChild::IndexedDBDatabaseChild(const nsString& aName,
michael@0 250 uint64_t aVersion)
michael@0 251 : mDatabase(nullptr), mName(aName), mVersion(aVersion)
michael@0 252 {
michael@0 253 MOZ_COUNT_CTOR(IndexedDBDatabaseChild);
michael@0 254 }
michael@0 255
michael@0 256 IndexedDBDatabaseChild::~IndexedDBDatabaseChild()
michael@0 257 {
michael@0 258 MOZ_COUNT_DTOR(IndexedDBDatabaseChild);
michael@0 259 MOZ_ASSERT(!mDatabase);
michael@0 260 MOZ_ASSERT(!mStrongDatabase);
michael@0 261 }
michael@0 262
michael@0 263 void
michael@0 264 IndexedDBDatabaseChild::SetRequest(IDBOpenDBRequest* aRequest)
michael@0 265 {
michael@0 266 MOZ_ASSERT(aRequest);
michael@0 267 MOZ_ASSERT(!mRequest);
michael@0 268
michael@0 269 mRequest = aRequest;
michael@0 270 }
michael@0 271
michael@0 272 void
michael@0 273 IndexedDBDatabaseChild::Disconnect()
michael@0 274 {
michael@0 275 const InfallibleTArray<PIndexedDBTransactionChild*>& transactions =
michael@0 276 ManagedPIndexedDBTransactionChild();
michael@0 277 for (uint32_t i = 0; i < transactions.Length(); ++i) {
michael@0 278 static_cast<IndexedDBTransactionChild*>(transactions[i])->Disconnect();
michael@0 279 }
michael@0 280 }
michael@0 281
michael@0 282 bool
michael@0 283 IndexedDBDatabaseChild::EnsureDatabase(
michael@0 284 IDBOpenDBRequest* aRequest,
michael@0 285 const DatabaseInfoGuts& aDBInfo,
michael@0 286 const InfallibleTArray<ObjectStoreInfoGuts>& aOSInfo)
michael@0 287 {
michael@0 288 nsCString databaseId;
michael@0 289 if (mDatabase) {
michael@0 290 databaseId = mDatabase->Id();
michael@0 291 }
michael@0 292 else {
michael@0 293 QuotaManager::GetStorageId(aDBInfo.persistenceType, aDBInfo.origin,
michael@0 294 Client::IDB, aDBInfo.name, databaseId);
michael@0 295 }
michael@0 296 MOZ_ASSERT(!databaseId.IsEmpty());
michael@0 297
michael@0 298 nsRefPtr<DatabaseInfo> dbInfo;
michael@0 299 if (DatabaseInfo::Get(databaseId, getter_AddRefs(dbInfo))) {
michael@0 300 dbInfo->version = aDBInfo.version;
michael@0 301 }
michael@0 302 else {
michael@0 303 nsRefPtr<DatabaseInfo> newInfo = new DatabaseInfo();
michael@0 304
michael@0 305 *static_cast<DatabaseInfoGuts*>(newInfo.get()) = aDBInfo;
michael@0 306 newInfo->id = databaseId;
michael@0 307
michael@0 308 if (!DatabaseInfo::Put(newInfo)) {
michael@0 309 NS_WARNING("Out of memory!");
michael@0 310 return false;
michael@0 311 }
michael@0 312
michael@0 313 newInfo.swap(dbInfo);
michael@0 314
michael@0 315 // This is more or less copied from IDBFactory::SetDatabaseMetadata.
michael@0 316 for (uint32_t i = 0; i < aOSInfo.Length(); i++) {
michael@0 317 nsRefPtr<ObjectStoreInfo> newInfo = new ObjectStoreInfo();
michael@0 318 *static_cast<ObjectStoreInfoGuts*>(newInfo.get()) = aOSInfo[i];
michael@0 319
michael@0 320 if (!dbInfo->PutObjectStore(newInfo)) {
michael@0 321 NS_WARNING("Out of memory!");
michael@0 322 return false;
michael@0 323 }
michael@0 324 }
michael@0 325 }
michael@0 326
michael@0 327 if (!mDatabase) {
michael@0 328 nsRefPtr<IDBDatabase> database =
michael@0 329 IDBDatabase::Create(aRequest, aRequest->Factory(), dbInfo.forget(),
michael@0 330 aDBInfo.origin, nullptr, nullptr);
michael@0 331 if (!database) {
michael@0 332 NS_WARNING("Failed to create database!");
michael@0 333 return false;
michael@0 334 }
michael@0 335
michael@0 336 database->SetActor(this);
michael@0 337
michael@0 338 mDatabase = database;
michael@0 339 mStrongDatabase = database.forget();
michael@0 340 }
michael@0 341
michael@0 342 return true;
michael@0 343 }
michael@0 344
michael@0 345 void
michael@0 346 IndexedDBDatabaseChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 347 {
michael@0 348 if (mDatabase) {
michael@0 349 mDatabase->SetActor(static_cast<IndexedDBDatabaseChild*>(nullptr));
michael@0 350 #ifdef DEBUG
michael@0 351 mDatabase = nullptr;
michael@0 352 #endif
michael@0 353 }
michael@0 354 }
michael@0 355
michael@0 356 bool
michael@0 357 IndexedDBDatabaseChild::RecvSuccess(
michael@0 358 const DatabaseInfoGuts& aDBInfo,
michael@0 359 const InfallibleTArray<ObjectStoreInfoGuts>& aOSInfo)
michael@0 360 {
michael@0 361 #ifdef DEBUG
michael@0 362 {
michael@0 363 IndexedDBChild* manager = static_cast<IndexedDBChild*>(Manager());
michael@0 364 MOZ_ASSERT(aDBInfo.origin == manager->ASCIIOrigin());
michael@0 365 MOZ_ASSERT(aDBInfo.name == mName);
michael@0 366 MOZ_ASSERT(!mVersion || aDBInfo.version == mVersion);
michael@0 367 }
michael@0 368 #endif
michael@0 369
michael@0 370 MOZ_ASSERT(mRequest);
michael@0 371
michael@0 372 nsRefPtr<IDBOpenDBRequest> request;
michael@0 373 mRequest.swap(request);
michael@0 374
michael@0 375 nsRefPtr<AsyncConnectionHelper> openHelper;
michael@0 376 mOpenHelper.swap(openHelper);
michael@0 377
michael@0 378 if (!EnsureDatabase(request, aDBInfo, aOSInfo)) {
michael@0 379 return false;
michael@0 380 }
michael@0 381
michael@0 382 MOZ_ASSERT(mStrongDatabase);
michael@0 383 nsRefPtr<IDBDatabase> database;
michael@0 384 mStrongDatabase.swap(database);
michael@0 385
michael@0 386 if (openHelper) {
michael@0 387 request->Reset();
michael@0 388 }
michael@0 389 else {
michael@0 390 openHelper = new IPCOpenDatabaseHelper(mDatabase, request);
michael@0 391 }
michael@0 392
michael@0 393 ImmediateRunEventTarget target;
michael@0 394 if (NS_FAILED(openHelper->Dispatch(&target))) {
michael@0 395 NS_WARNING("Dispatch of IPCOpenDatabaseHelper failed!");
michael@0 396 return false;
michael@0 397 }
michael@0 398
michael@0 399 return true;
michael@0 400 }
michael@0 401
michael@0 402 bool
michael@0 403 IndexedDBDatabaseChild::RecvError(const nsresult& aRv)
michael@0 404 {
michael@0 405 MOZ_ASSERT(mRequest);
michael@0 406
michael@0 407 nsRefPtr<IDBOpenDBRequest> request;
michael@0 408 mRequest.swap(request);
michael@0 409
michael@0 410 nsRefPtr<IDBDatabase> database;
michael@0 411 mStrongDatabase.swap(database);
michael@0 412
michael@0 413 nsRefPtr<AsyncConnectionHelper> openHelper;
michael@0 414 mOpenHelper.swap(openHelper);
michael@0 415
michael@0 416 if (openHelper) {
michael@0 417 request->Reset();
michael@0 418 }
michael@0 419 else {
michael@0 420 openHelper = new IPCOpenDatabaseHelper(nullptr, request);
michael@0 421 }
michael@0 422
michael@0 423 openHelper->SetError(aRv);
michael@0 424
michael@0 425 ImmediateRunEventTarget target;
michael@0 426 if (NS_FAILED(openHelper->Dispatch(&target))) {
michael@0 427 NS_WARNING("Dispatch of IPCOpenDatabaseHelper failed!");
michael@0 428 return false;
michael@0 429 }
michael@0 430
michael@0 431 return true;
michael@0 432 }
michael@0 433
michael@0 434 bool
michael@0 435 IndexedDBDatabaseChild::RecvBlocked(const uint64_t& aOldVersion)
michael@0 436 {
michael@0 437 MOZ_ASSERT(mRequest);
michael@0 438 MOZ_ASSERT(!mDatabase);
michael@0 439
michael@0 440 nsCOMPtr<nsIRunnable> runnable =
michael@0 441 IDBVersionChangeEvent::CreateBlockedRunnable(mRequest, aOldVersion, mVersion);
michael@0 442
michael@0 443 ImmediateRunEventTarget target;
michael@0 444 if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) {
michael@0 445 NS_WARNING("Dispatch of blocked event failed!");
michael@0 446 }
michael@0 447
michael@0 448 return true;
michael@0 449 }
michael@0 450
michael@0 451 bool
michael@0 452 IndexedDBDatabaseChild::RecvVersionChange(const uint64_t& aOldVersion,
michael@0 453 const uint64_t& aNewVersion)
michael@0 454 {
michael@0 455 MOZ_ASSERT(mDatabase);
michael@0 456
michael@0 457 nsCOMPtr<nsIRunnable> runnable =
michael@0 458 new VersionChangeRunnable(mDatabase, aOldVersion, aNewVersion);
michael@0 459
michael@0 460 ImmediateRunEventTarget target;
michael@0 461 if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) {
michael@0 462 NS_WARNING("Dispatch of versionchange event failed!");
michael@0 463 }
michael@0 464
michael@0 465 return true;
michael@0 466 }
michael@0 467
michael@0 468 bool
michael@0 469 IndexedDBDatabaseChild::RecvInvalidate()
michael@0 470 {
michael@0 471 if (mDatabase) {
michael@0 472 mDatabase->Invalidate();
michael@0 473 }
michael@0 474 return true;
michael@0 475 }
michael@0 476
michael@0 477 bool
michael@0 478 IndexedDBDatabaseChild::RecvPIndexedDBTransactionConstructor(
michael@0 479 PIndexedDBTransactionChild* aActor,
michael@0 480 const TransactionParams& aParams)
michael@0 481 {
michael@0 482 // This only happens when the parent has created a version-change transaction
michael@0 483 // for us.
michael@0 484
michael@0 485 IndexedDBTransactionChild* actor =
michael@0 486 static_cast<IndexedDBTransactionChild*>(aActor);
michael@0 487 MOZ_ASSERT(!actor->GetTransaction());
michael@0 488
michael@0 489 MOZ_ASSERT(aParams.type() ==
michael@0 490 TransactionParams::TVersionChangeTransactionParams);
michael@0 491
michael@0 492 const VersionChangeTransactionParams& params =
michael@0 493 aParams.get_VersionChangeTransactionParams();
michael@0 494
michael@0 495 const DatabaseInfoGuts& dbInfo = params.dbInfo();
michael@0 496 const InfallibleTArray<ObjectStoreInfoGuts>& osInfo = params.osInfo();
michael@0 497 uint64_t oldVersion = params.oldVersion();
michael@0 498
michael@0 499 MOZ_ASSERT(dbInfo.origin ==
michael@0 500 static_cast<IndexedDBChild*>(Manager())->ASCIIOrigin());
michael@0 501 MOZ_ASSERT(dbInfo.name == mName);
michael@0 502 MOZ_ASSERT(!mVersion || dbInfo.version == mVersion);
michael@0 503 MOZ_ASSERT(!mVersion || oldVersion < mVersion);
michael@0 504
michael@0 505 MOZ_ASSERT(mRequest);
michael@0 506 MOZ_ASSERT(!mDatabase);
michael@0 507 MOZ_ASSERT(!mOpenHelper);
michael@0 508
michael@0 509 if (!EnsureDatabase(mRequest, dbInfo, osInfo)) {
michael@0 510 return false;
michael@0 511 }
michael@0 512
michael@0 513 nsRefPtr<IPCOpenDatabaseHelper> helper =
michael@0 514 new IPCOpenDatabaseHelper(mDatabase, mRequest);
michael@0 515
michael@0 516 Sequence<nsString> storesToOpen;
michael@0 517 nsRefPtr<IDBTransaction> transaction =
michael@0 518 IDBTransaction::CreateInternal(mDatabase, storesToOpen,
michael@0 519 IDBTransaction::VERSION_CHANGE, false, true);
michael@0 520 NS_ENSURE_TRUE(transaction, false);
michael@0 521
michael@0 522 nsRefPtr<IPCSetVersionHelper> versionHelper =
michael@0 523 new IPCSetVersionHelper(transaction, mRequest, oldVersion, mVersion);
michael@0 524
michael@0 525 mDatabase->EnterSetVersionTransaction();
michael@0 526 mDatabase->mPreviousDatabaseInfo->version = oldVersion;
michael@0 527
michael@0 528 actor->SetTransaction(transaction);
michael@0 529
michael@0 530 ImmediateRunEventTarget target;
michael@0 531 if (NS_FAILED(versionHelper->Dispatch(&target))) {
michael@0 532 NS_WARNING("Dispatch of IPCSetVersionHelper failed!");
michael@0 533 return false;
michael@0 534 }
michael@0 535
michael@0 536 mOpenHelper = helper.forget();
michael@0 537 return true;
michael@0 538 }
michael@0 539
michael@0 540 PIndexedDBTransactionChild*
michael@0 541 IndexedDBDatabaseChild::AllocPIndexedDBTransactionChild(
michael@0 542 const TransactionParams& aParams)
michael@0 543 {
michael@0 544 MOZ_ASSERT(aParams.type() ==
michael@0 545 TransactionParams::TVersionChangeTransactionParams);
michael@0 546 return new IndexedDBTransactionChild();
michael@0 547 }
michael@0 548
michael@0 549 bool
michael@0 550 IndexedDBDatabaseChild::DeallocPIndexedDBTransactionChild(
michael@0 551 PIndexedDBTransactionChild* aActor)
michael@0 552 {
michael@0 553 delete aActor;
michael@0 554 return true;
michael@0 555 }
michael@0 556
michael@0 557 /*******************************************************************************
michael@0 558 * IndexedDBTransactionChild
michael@0 559 ******************************************************************************/
michael@0 560
michael@0 561 IndexedDBTransactionChild::IndexedDBTransactionChild()
michael@0 562 : mTransaction(nullptr)
michael@0 563 {
michael@0 564 MOZ_COUNT_CTOR(IndexedDBTransactionChild);
michael@0 565 }
michael@0 566
michael@0 567 IndexedDBTransactionChild::~IndexedDBTransactionChild()
michael@0 568 {
michael@0 569 MOZ_COUNT_DTOR(IndexedDBTransactionChild);
michael@0 570 MOZ_ASSERT(!mTransaction);
michael@0 571 MOZ_ASSERT(!mStrongTransaction);
michael@0 572 }
michael@0 573
michael@0 574 void
michael@0 575 IndexedDBTransactionChild::SetTransaction(IDBTransaction* aTransaction)
michael@0 576 {
michael@0 577 MOZ_ASSERT(aTransaction);
michael@0 578 MOZ_ASSERT(!mTransaction);
michael@0 579
michael@0 580 aTransaction->SetActor(this);
michael@0 581
michael@0 582 mTransaction = aTransaction;
michael@0 583 mStrongTransaction = aTransaction;
michael@0 584 }
michael@0 585
michael@0 586 void
michael@0 587 IndexedDBTransactionChild::Disconnect()
michael@0 588 {
michael@0 589 const InfallibleTArray<PIndexedDBObjectStoreChild*>& objectStores =
michael@0 590 ManagedPIndexedDBObjectStoreChild();
michael@0 591 for (uint32_t i = 0; i < objectStores.Length(); ++i) {
michael@0 592 static_cast<IndexedDBObjectStoreChild*>(objectStores[i])->Disconnect();
michael@0 593 }
michael@0 594 }
michael@0 595
michael@0 596 void
michael@0 597 IndexedDBTransactionChild::FireCompleteEvent(nsresult aRv)
michael@0 598 {
michael@0 599 MOZ_ASSERT(mTransaction);
michael@0 600 MOZ_ASSERT(mStrongTransaction);
michael@0 601
michael@0 602 nsRefPtr<IDBTransaction> transaction;
michael@0 603 mStrongTransaction.swap(transaction);
michael@0 604
michael@0 605 if (transaction->GetMode() == IDBTransaction::VERSION_CHANGE) {
michael@0 606 transaction->Database()->ExitSetVersionTransaction();
michael@0 607 }
michael@0 608
michael@0 609 nsRefPtr<CommitHelper> helper = new CommitHelper(transaction, aRv);
michael@0 610
michael@0 611 ImmediateRunEventTarget target;
michael@0 612 if (NS_FAILED(target.Dispatch(helper, NS_DISPATCH_NORMAL))) {
michael@0 613 NS_WARNING("Dispatch of CommitHelper failed!");
michael@0 614 }
michael@0 615 }
michael@0 616
michael@0 617 void
michael@0 618 IndexedDBTransactionChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 619 {
michael@0 620 if (mStrongTransaction) {
michael@0 621 // We're being torn down before we received a complete event from the parent
michael@0 622 // so fake one here.
michael@0 623 FireCompleteEvent(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
michael@0 624
michael@0 625 MOZ_ASSERT(!mStrongTransaction);
michael@0 626 }
michael@0 627
michael@0 628 if (mTransaction) {
michael@0 629 mTransaction->SetActor(static_cast<IndexedDBTransactionChild*>(nullptr));
michael@0 630 #ifdef DEBUG
michael@0 631 mTransaction = nullptr;
michael@0 632 #endif
michael@0 633 }
michael@0 634 }
michael@0 635
michael@0 636 bool
michael@0 637 IndexedDBTransactionChild::RecvComplete(const CompleteParams& aParams)
michael@0 638 {
michael@0 639 MOZ_ASSERT(mTransaction);
michael@0 640 MOZ_ASSERT(mStrongTransaction);
michael@0 641
michael@0 642 nsresult resultCode;
michael@0 643
michael@0 644 switch (aParams.type()) {
michael@0 645 case CompleteParams::TCompleteResult:
michael@0 646 resultCode = NS_OK;
michael@0 647 break;
michael@0 648 case CompleteParams::TAbortResult:
michael@0 649 resultCode = aParams.get_AbortResult().errorCode();
michael@0 650 if (NS_SUCCEEDED(resultCode)) {
michael@0 651 resultCode = NS_ERROR_DOM_INDEXEDDB_ABORT_ERR;
michael@0 652 }
michael@0 653 break;
michael@0 654
michael@0 655 default:
michael@0 656 MOZ_CRASH("Unknown union type!");
michael@0 657 }
michael@0 658
michael@0 659 FireCompleteEvent(resultCode);
michael@0 660 return true;
michael@0 661 }
michael@0 662
michael@0 663 PIndexedDBObjectStoreChild*
michael@0 664 IndexedDBTransactionChild::AllocPIndexedDBObjectStoreChild(
michael@0 665 const ObjectStoreConstructorParams& aParams)
michael@0 666 {
michael@0 667 MOZ_CRASH("Caller is supposed to manually construct an object store!");
michael@0 668 }
michael@0 669
michael@0 670 bool
michael@0 671 IndexedDBTransactionChild::DeallocPIndexedDBObjectStoreChild(
michael@0 672 PIndexedDBObjectStoreChild* aActor)
michael@0 673 {
michael@0 674 delete aActor;
michael@0 675 return true;
michael@0 676 }
michael@0 677
michael@0 678 /*******************************************************************************
michael@0 679 * IndexedDBObjectStoreChild
michael@0 680 ******************************************************************************/
michael@0 681
michael@0 682 IndexedDBObjectStoreChild::IndexedDBObjectStoreChild(
michael@0 683 IDBObjectStore* aObjectStore)
michael@0 684 : mObjectStore(aObjectStore)
michael@0 685 {
michael@0 686 MOZ_COUNT_CTOR(IndexedDBObjectStoreChild);
michael@0 687 aObjectStore->SetActor(this);
michael@0 688 }
michael@0 689
michael@0 690 IndexedDBObjectStoreChild::~IndexedDBObjectStoreChild()
michael@0 691 {
michael@0 692 MOZ_COUNT_DTOR(IndexedDBObjectStoreChild);
michael@0 693 MOZ_ASSERT(!mObjectStore);
michael@0 694 }
michael@0 695
michael@0 696 void
michael@0 697 IndexedDBObjectStoreChild::Disconnect()
michael@0 698 {
michael@0 699 const InfallibleTArray<PIndexedDBRequestChild*>& requests =
michael@0 700 ManagedPIndexedDBRequestChild();
michael@0 701 for (uint32_t i = 0; i < requests.Length(); ++i) {
michael@0 702 static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect();
michael@0 703 }
michael@0 704
michael@0 705 const InfallibleTArray<PIndexedDBIndexChild*>& indexes =
michael@0 706 ManagedPIndexedDBIndexChild();
michael@0 707 for (uint32_t i = 0; i < indexes.Length(); ++i) {
michael@0 708 static_cast<IndexedDBIndexChild*>(indexes[i])->Disconnect();
michael@0 709 }
michael@0 710
michael@0 711 const InfallibleTArray<PIndexedDBCursorChild*>& cursors =
michael@0 712 ManagedPIndexedDBCursorChild();
michael@0 713 for (uint32_t i = 0; i < cursors.Length(); ++i) {
michael@0 714 static_cast<IndexedDBCursorChild*>(cursors[i])->Disconnect();
michael@0 715 }
michael@0 716 }
michael@0 717
michael@0 718 void
michael@0 719 IndexedDBObjectStoreChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 720 {
michael@0 721 if (mObjectStore) {
michael@0 722 mObjectStore->SetActor(static_cast<IndexedDBObjectStoreChild*>(nullptr));
michael@0 723 #ifdef DEBUG
michael@0 724 mObjectStore = nullptr;
michael@0 725 #endif
michael@0 726 }
michael@0 727 }
michael@0 728
michael@0 729 bool
michael@0 730 IndexedDBObjectStoreChild::RecvPIndexedDBCursorConstructor(
michael@0 731 PIndexedDBCursorChild* aActor,
michael@0 732 const ObjectStoreCursorConstructorParams& aParams)
michael@0 733 {
michael@0 734 IndexedDBCursorChild* actor = static_cast<IndexedDBCursorChild*>(aActor);
michael@0 735
michael@0 736 IndexedDBObjectStoreRequestChild* requestActor =
michael@0 737 static_cast<IndexedDBObjectStoreRequestChild*>(aParams.requestChild());
michael@0 738 NS_ASSERTION(requestActor, "Must have an actor here!");
michael@0 739
michael@0 740 nsRefPtr<IDBRequest> request = requestActor->GetRequest();
michael@0 741 NS_ASSERTION(request, "Must have a request here!");
michael@0 742
michael@0 743 size_t direction = static_cast<size_t>(aParams.direction());
michael@0 744
michael@0 745 nsRefPtr<IDBCursor> cursor;
michael@0 746 nsresult rv;
michael@0 747
michael@0 748 typedef ipc::OptionalStructuredCloneReadInfo CursorUnionType;
michael@0 749
michael@0 750 switch (aParams.optionalCloneInfo().type()) {
michael@0 751 case CursorUnionType::TSerializedStructuredCloneReadInfo: {
michael@0 752 nsTArray<StructuredCloneFile> blobs;
michael@0 753 IDBObjectStore::ConvertActorsToBlobs(aParams.blobsChild(), blobs);
michael@0 754
michael@0 755 const SerializedStructuredCloneReadInfo& cloneInfo =
michael@0 756 aParams.optionalCloneInfo().get_SerializedStructuredCloneReadInfo();
michael@0 757
michael@0 758 rv = mObjectStore->OpenCursorFromChildProcess(request, direction,
michael@0 759 aParams.key(), cloneInfo,
michael@0 760 blobs,
michael@0 761 getter_AddRefs(cursor));
michael@0 762 NS_ENSURE_SUCCESS(rv, false);
michael@0 763
michael@0 764 MOZ_ASSERT(blobs.IsEmpty(), "Should have swapped blob elements!");
michael@0 765 } break;
michael@0 766
michael@0 767 case CursorUnionType::Tvoid_t:
michael@0 768 MOZ_ASSERT(aParams.blobsChild().IsEmpty());
michael@0 769
michael@0 770 rv = mObjectStore->OpenCursorFromChildProcess(request, direction,
michael@0 771 aParams.key(),
michael@0 772 getter_AddRefs(cursor));
michael@0 773 NS_ENSURE_SUCCESS(rv, false);
michael@0 774 break;
michael@0 775
michael@0 776 default:
michael@0 777 MOZ_CRASH("Unknown union type!");
michael@0 778 }
michael@0 779
michael@0 780 actor->SetCursor(cursor);
michael@0 781 return true;
michael@0 782 }
michael@0 783
michael@0 784 PIndexedDBRequestChild*
michael@0 785 IndexedDBObjectStoreChild::AllocPIndexedDBRequestChild(
michael@0 786 const ObjectStoreRequestParams& aParams)
michael@0 787 {
michael@0 788 MOZ_CRASH("Caller is supposed to manually construct a request!");
michael@0 789 }
michael@0 790
michael@0 791 bool
michael@0 792 IndexedDBObjectStoreChild::DeallocPIndexedDBRequestChild(
michael@0 793 PIndexedDBRequestChild* aActor)
michael@0 794 {
michael@0 795 delete aActor;
michael@0 796 return false;
michael@0 797 }
michael@0 798
michael@0 799 PIndexedDBIndexChild*
michael@0 800 IndexedDBObjectStoreChild::AllocPIndexedDBIndexChild(
michael@0 801 const IndexConstructorParams& aParams)
michael@0 802 {
michael@0 803 MOZ_CRASH("Caller is supposed to manually construct an index!");
michael@0 804 }
michael@0 805
michael@0 806 bool
michael@0 807 IndexedDBObjectStoreChild::DeallocPIndexedDBIndexChild(PIndexedDBIndexChild* aActor)
michael@0 808 {
michael@0 809 delete aActor;
michael@0 810 return true;
michael@0 811 }
michael@0 812
michael@0 813 PIndexedDBCursorChild*
michael@0 814 IndexedDBObjectStoreChild::AllocPIndexedDBCursorChild(
michael@0 815 const ObjectStoreCursorConstructorParams& aParams)
michael@0 816 {
michael@0 817 return new IndexedDBCursorChild();
michael@0 818 }
michael@0 819
michael@0 820 bool
michael@0 821 IndexedDBObjectStoreChild::DeallocPIndexedDBCursorChild(
michael@0 822 PIndexedDBCursorChild* aActor)
michael@0 823 {
michael@0 824 delete aActor;
michael@0 825 return true;
michael@0 826 }
michael@0 827
michael@0 828 /*******************************************************************************
michael@0 829 * IndexedDBIndexChild
michael@0 830 ******************************************************************************/
michael@0 831
michael@0 832 IndexedDBIndexChild::IndexedDBIndexChild(IDBIndex* aIndex)
michael@0 833 : mIndex(aIndex)
michael@0 834 {
michael@0 835 MOZ_COUNT_CTOR(IndexedDBIndexChild);
michael@0 836 aIndex->SetActor(this);
michael@0 837 }
michael@0 838
michael@0 839 IndexedDBIndexChild::~IndexedDBIndexChild()
michael@0 840 {
michael@0 841 MOZ_COUNT_DTOR(IndexedDBIndexChild);
michael@0 842 MOZ_ASSERT(!mIndex);
michael@0 843 }
michael@0 844
michael@0 845 void
michael@0 846 IndexedDBIndexChild::Disconnect()
michael@0 847 {
michael@0 848 const InfallibleTArray<PIndexedDBRequestChild*>& requests =
michael@0 849 ManagedPIndexedDBRequestChild();
michael@0 850 for (uint32_t i = 0; i < requests.Length(); ++i) {
michael@0 851 static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect();
michael@0 852 }
michael@0 853
michael@0 854 const InfallibleTArray<PIndexedDBCursorChild*>& cursors =
michael@0 855 ManagedPIndexedDBCursorChild();
michael@0 856 for (uint32_t i = 0; i < cursors.Length(); ++i) {
michael@0 857 static_cast<IndexedDBCursorChild*>(cursors[i])->Disconnect();
michael@0 858 }
michael@0 859 }
michael@0 860
michael@0 861 void
michael@0 862 IndexedDBIndexChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 863 {
michael@0 864 if (mIndex) {
michael@0 865 mIndex->SetActor(static_cast<IndexedDBIndexChild*>(nullptr));
michael@0 866 #ifdef DEBUG
michael@0 867 mIndex = nullptr;
michael@0 868 #endif
michael@0 869 }
michael@0 870 }
michael@0 871
michael@0 872 bool
michael@0 873 IndexedDBIndexChild::RecvPIndexedDBCursorConstructor(
michael@0 874 PIndexedDBCursorChild* aActor,
michael@0 875 const IndexCursorConstructorParams& aParams)
michael@0 876 {
michael@0 877 IndexedDBCursorChild* actor = static_cast<IndexedDBCursorChild*>(aActor);
michael@0 878
michael@0 879 IndexedDBObjectStoreRequestChild* requestActor =
michael@0 880 static_cast<IndexedDBObjectStoreRequestChild*>(aParams.requestChild());
michael@0 881 NS_ASSERTION(requestActor, "Must have an actor here!");
michael@0 882
michael@0 883 nsRefPtr<IDBRequest> request = requestActor->GetRequest();
michael@0 884 NS_ASSERTION(request, "Must have a request here!");
michael@0 885
michael@0 886 size_t direction = static_cast<size_t>(aParams.direction());
michael@0 887
michael@0 888 nsRefPtr<IDBCursor> cursor;
michael@0 889 nsresult rv;
michael@0 890
michael@0 891 typedef ipc::OptionalStructuredCloneReadInfo CursorUnionType;
michael@0 892
michael@0 893 switch (aParams.optionalCloneInfo().type()) {
michael@0 894 case CursorUnionType::TSerializedStructuredCloneReadInfo: {
michael@0 895 nsTArray<StructuredCloneFile> blobs;
michael@0 896 IDBObjectStore::ConvertActorsToBlobs(aParams.blobsChild(), blobs);
michael@0 897
michael@0 898 const SerializedStructuredCloneReadInfo& cloneInfo =
michael@0 899 aParams.optionalCloneInfo().get_SerializedStructuredCloneReadInfo();
michael@0 900
michael@0 901 rv = mIndex->OpenCursorFromChildProcess(request, direction, aParams.key(),
michael@0 902 aParams.objectKey(), cloneInfo,
michael@0 903 blobs,
michael@0 904 getter_AddRefs(cursor));
michael@0 905 NS_ENSURE_SUCCESS(rv, false);
michael@0 906 } break;
michael@0 907
michael@0 908 case CursorUnionType::Tvoid_t:
michael@0 909 MOZ_ASSERT(aParams.blobsChild().IsEmpty());
michael@0 910
michael@0 911 rv = mIndex->OpenCursorFromChildProcess(request, direction, aParams.key(),
michael@0 912 aParams.objectKey(),
michael@0 913 getter_AddRefs(cursor));
michael@0 914 NS_ENSURE_SUCCESS(rv, false);
michael@0 915 break;
michael@0 916
michael@0 917 default:
michael@0 918 MOZ_CRASH("Unknown union type!");
michael@0 919 }
michael@0 920
michael@0 921 actor->SetCursor(cursor);
michael@0 922 return true;
michael@0 923 }
michael@0 924
michael@0 925 PIndexedDBRequestChild*
michael@0 926 IndexedDBIndexChild::AllocPIndexedDBRequestChild(const IndexRequestParams& aParams)
michael@0 927 {
michael@0 928 MOZ_CRASH("Caller is supposed to manually construct a request!");
michael@0 929 }
michael@0 930
michael@0 931 bool
michael@0 932 IndexedDBIndexChild::DeallocPIndexedDBRequestChild(PIndexedDBRequestChild* aActor)
michael@0 933 {
michael@0 934 delete aActor;
michael@0 935 return true;
michael@0 936 }
michael@0 937
michael@0 938 PIndexedDBCursorChild*
michael@0 939 IndexedDBIndexChild::AllocPIndexedDBCursorChild(
michael@0 940 const IndexCursorConstructorParams& aParams)
michael@0 941 {
michael@0 942 return new IndexedDBCursorChild();
michael@0 943 }
michael@0 944
michael@0 945 bool
michael@0 946 IndexedDBIndexChild::DeallocPIndexedDBCursorChild(PIndexedDBCursorChild* aActor)
michael@0 947 {
michael@0 948 delete aActor;
michael@0 949 return true;
michael@0 950 }
michael@0 951
michael@0 952 /*******************************************************************************
michael@0 953 * IndexedDBCursorChild
michael@0 954 ******************************************************************************/
michael@0 955
michael@0 956 IndexedDBCursorChild::IndexedDBCursorChild()
michael@0 957 : mCursor(nullptr)
michael@0 958 {
michael@0 959 MOZ_COUNT_CTOR(IndexedDBCursorChild);
michael@0 960 }
michael@0 961
michael@0 962 IndexedDBCursorChild::~IndexedDBCursorChild()
michael@0 963 {
michael@0 964 MOZ_COUNT_DTOR(IndexedDBCursorChild);
michael@0 965 MOZ_ASSERT(!mCursor);
michael@0 966 MOZ_ASSERT(!mStrongCursor);
michael@0 967 }
michael@0 968
michael@0 969 void
michael@0 970 IndexedDBCursorChild::SetCursor(IDBCursor* aCursor)
michael@0 971 {
michael@0 972 MOZ_ASSERT(aCursor);
michael@0 973 MOZ_ASSERT(!mCursor);
michael@0 974
michael@0 975 aCursor->SetActor(this);
michael@0 976
michael@0 977 mCursor = aCursor;
michael@0 978 mStrongCursor = aCursor;
michael@0 979 }
michael@0 980
michael@0 981 void
michael@0 982 IndexedDBCursorChild::Disconnect()
michael@0 983 {
michael@0 984 const InfallibleTArray<PIndexedDBRequestChild*>& requests =
michael@0 985 ManagedPIndexedDBRequestChild();
michael@0 986 for (uint32_t i = 0; i < requests.Length(); ++i) {
michael@0 987 static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect();
michael@0 988 }
michael@0 989 }
michael@0 990
michael@0 991 void
michael@0 992 IndexedDBCursorChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 993 {
michael@0 994 if (mCursor) {
michael@0 995 mCursor->SetActor(static_cast<IndexedDBCursorChild*>(nullptr));
michael@0 996 #ifdef DEBUG
michael@0 997 mCursor = nullptr;
michael@0 998 #endif
michael@0 999 }
michael@0 1000 }
michael@0 1001
michael@0 1002 PIndexedDBRequestChild*
michael@0 1003 IndexedDBCursorChild::AllocPIndexedDBRequestChild(const CursorRequestParams& aParams)
michael@0 1004 {
michael@0 1005 MOZ_CRASH("Caller is supposed to manually construct a request!");
michael@0 1006 }
michael@0 1007
michael@0 1008 bool
michael@0 1009 IndexedDBCursorChild::DeallocPIndexedDBRequestChild(PIndexedDBRequestChild* aActor)
michael@0 1010 {
michael@0 1011 delete aActor;
michael@0 1012 return true;
michael@0 1013 }
michael@0 1014
michael@0 1015 /*******************************************************************************
michael@0 1016 * IndexedDBRequestChildBase
michael@0 1017 ******************************************************************************/
michael@0 1018
michael@0 1019 IndexedDBRequestChildBase::IndexedDBRequestChildBase(
michael@0 1020 AsyncConnectionHelper* aHelper)
michael@0 1021 : mHelper(aHelper)
michael@0 1022 {
michael@0 1023 MOZ_COUNT_CTOR(IndexedDBRequestChildBase);
michael@0 1024 }
michael@0 1025
michael@0 1026 IndexedDBRequestChildBase::~IndexedDBRequestChildBase()
michael@0 1027 {
michael@0 1028 MOZ_COUNT_DTOR(IndexedDBRequestChildBase);
michael@0 1029 }
michael@0 1030
michael@0 1031 IDBRequest*
michael@0 1032 IndexedDBRequestChildBase::GetRequest() const
michael@0 1033 {
michael@0 1034 return mHelper ? mHelper->GetRequest() : nullptr;
michael@0 1035 }
michael@0 1036
michael@0 1037 void
michael@0 1038 IndexedDBRequestChildBase::Disconnect()
michael@0 1039 {
michael@0 1040 if (mHelper) {
michael@0 1041 IDBRequest* request = mHelper->GetRequest();
michael@0 1042
michael@0 1043 if (request->IsPending()) {
michael@0 1044 request->SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
michael@0 1045
michael@0 1046 IDBTransaction* transaction = mHelper->GetTransaction();
michael@0 1047 if (transaction) {
michael@0 1048 transaction->OnRequestDisconnected();
michael@0 1049 }
michael@0 1050 }
michael@0 1051 }
michael@0 1052 }
michael@0 1053
michael@0 1054 bool
michael@0 1055 IndexedDBRequestChildBase::Recv__delete__(const ResponseValue& aResponse)
michael@0 1056 {
michael@0 1057 MOZ_CRASH("This should be overridden!");
michael@0 1058 }
michael@0 1059
michael@0 1060 /*******************************************************************************
michael@0 1061 * IndexedDBObjectStoreRequestChild
michael@0 1062 ******************************************************************************/
michael@0 1063
michael@0 1064 IndexedDBObjectStoreRequestChild::IndexedDBObjectStoreRequestChild(
michael@0 1065 AsyncConnectionHelper* aHelper,
michael@0 1066 IDBObjectStore* aObjectStore,
michael@0 1067 RequestType aRequestType)
michael@0 1068 : IndexedDBRequestChildBase(aHelper), mObjectStore(aObjectStore),
michael@0 1069 mRequestType(aRequestType)
michael@0 1070 {
michael@0 1071 MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestChild);
michael@0 1072 MOZ_ASSERT(aHelper);
michael@0 1073 MOZ_ASSERT(aObjectStore);
michael@0 1074 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
michael@0 1075 aRequestType <= ParamsUnionType::T__Last);
michael@0 1076 }
michael@0 1077
michael@0 1078 IndexedDBObjectStoreRequestChild::~IndexedDBObjectStoreRequestChild()
michael@0 1079 {
michael@0 1080 MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestChild);
michael@0 1081 }
michael@0 1082
michael@0 1083 bool
michael@0 1084 IndexedDBObjectStoreRequestChild::Recv__delete__(const ResponseValue& aResponse)
michael@0 1085 {
michael@0 1086 switch (aResponse.type()) {
michael@0 1087 case ResponseValue::Tnsresult:
michael@0 1088 break;
michael@0 1089 case ResponseValue::TGetResponse:
michael@0 1090 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams);
michael@0 1091 break;
michael@0 1092 case ResponseValue::TGetAllResponse:
michael@0 1093 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams);
michael@0 1094 break;
michael@0 1095 case ResponseValue::TGetAllKeysResponse:
michael@0 1096 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams);
michael@0 1097 break;
michael@0 1098 case ResponseValue::TAddResponse:
michael@0 1099 MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams);
michael@0 1100 break;
michael@0 1101 case ResponseValue::TPutResponse:
michael@0 1102 MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams);
michael@0 1103 break;
michael@0 1104 case ResponseValue::TDeleteResponse:
michael@0 1105 MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams);
michael@0 1106 break;
michael@0 1107 case ResponseValue::TClearResponse:
michael@0 1108 MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams);
michael@0 1109 break;
michael@0 1110 case ResponseValue::TCountResponse:
michael@0 1111 MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams);
michael@0 1112 break;
michael@0 1113 case ResponseValue::TOpenCursorResponse:
michael@0 1114 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams ||
michael@0 1115 mRequestType == ParamsUnionType::TOpenKeyCursorParams);
michael@0 1116 break;
michael@0 1117
michael@0 1118 default:
michael@0 1119 MOZ_CRASH("Received invalid response parameters!");
michael@0 1120 }
michael@0 1121
michael@0 1122 nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse);
michael@0 1123 NS_ENSURE_SUCCESS(rv, false);
michael@0 1124
michael@0 1125 return true;
michael@0 1126 }
michael@0 1127
michael@0 1128 /*******************************************************************************
michael@0 1129 * IndexedDBIndexRequestChild
michael@0 1130 ******************************************************************************/
michael@0 1131
michael@0 1132 IndexedDBIndexRequestChild::IndexedDBIndexRequestChild(
michael@0 1133 AsyncConnectionHelper* aHelper,
michael@0 1134 IDBIndex* aIndex,
michael@0 1135 RequestType aRequestType)
michael@0 1136 : IndexedDBRequestChildBase(aHelper), mIndex(aIndex), mRequestType(aRequestType)
michael@0 1137 {
michael@0 1138 MOZ_COUNT_CTOR(IndexedDBIndexRequestChild);
michael@0 1139 MOZ_ASSERT(aHelper);
michael@0 1140 MOZ_ASSERT(aIndex);
michael@0 1141 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
michael@0 1142 aRequestType <= ParamsUnionType::T__Last);
michael@0 1143 }
michael@0 1144
michael@0 1145 IndexedDBIndexRequestChild::~IndexedDBIndexRequestChild()
michael@0 1146 {
michael@0 1147 MOZ_COUNT_DTOR(IndexedDBIndexRequestChild);
michael@0 1148 }
michael@0 1149
michael@0 1150 bool
michael@0 1151 IndexedDBIndexRequestChild::Recv__delete__(const ResponseValue& aResponse)
michael@0 1152 {
michael@0 1153 switch (aResponse.type()) {
michael@0 1154 case ResponseValue::Tnsresult:
michael@0 1155 break;
michael@0 1156 case ResponseValue::TGetResponse:
michael@0 1157 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams);
michael@0 1158 break;
michael@0 1159 case ResponseValue::TGetKeyResponse:
michael@0 1160 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams);
michael@0 1161 break;
michael@0 1162 case ResponseValue::TGetAllResponse:
michael@0 1163 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams);
michael@0 1164 break;
michael@0 1165 case ResponseValue::TGetAllKeysResponse:
michael@0 1166 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams);
michael@0 1167 break;
michael@0 1168 case ResponseValue::TCountResponse:
michael@0 1169 MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams);
michael@0 1170 break;
michael@0 1171 case ResponseValue::TOpenCursorResponse:
michael@0 1172 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams ||
michael@0 1173 mRequestType == ParamsUnionType::TOpenKeyCursorParams);
michael@0 1174 break;
michael@0 1175
michael@0 1176 default:
michael@0 1177 MOZ_CRASH("Received invalid response parameters!");
michael@0 1178 }
michael@0 1179
michael@0 1180 nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse);
michael@0 1181 NS_ENSURE_SUCCESS(rv, false);
michael@0 1182
michael@0 1183 return true;
michael@0 1184 }
michael@0 1185
michael@0 1186 /*******************************************************************************
michael@0 1187 * IndexedDBCursorRequestChild
michael@0 1188 ******************************************************************************/
michael@0 1189
michael@0 1190 IndexedDBCursorRequestChild::IndexedDBCursorRequestChild(
michael@0 1191 AsyncConnectionHelper* aHelper,
michael@0 1192 IDBCursor* aCursor,
michael@0 1193 RequestType aRequestType)
michael@0 1194 : IndexedDBRequestChildBase(aHelper), mCursor(aCursor),
michael@0 1195 mRequestType(aRequestType)
michael@0 1196 {
michael@0 1197 MOZ_COUNT_CTOR(IndexedDBCursorRequestChild);
michael@0 1198 MOZ_ASSERT(aHelper);
michael@0 1199 MOZ_ASSERT(aCursor);
michael@0 1200 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
michael@0 1201 aRequestType <= ParamsUnionType::T__Last);
michael@0 1202 }
michael@0 1203
michael@0 1204 IndexedDBCursorRequestChild::~IndexedDBCursorRequestChild()
michael@0 1205 {
michael@0 1206 MOZ_COUNT_DTOR(IndexedDBCursorRequestChild);
michael@0 1207 }
michael@0 1208
michael@0 1209 bool
michael@0 1210 IndexedDBCursorRequestChild::Recv__delete__(const ResponseValue& aResponse)
michael@0 1211 {
michael@0 1212 switch (aResponse.type()) {
michael@0 1213 case ResponseValue::Tnsresult:
michael@0 1214 break;
michael@0 1215 case ResponseValue::TContinueResponse:
michael@0 1216 MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams);
michael@0 1217 break;
michael@0 1218
michael@0 1219 default:
michael@0 1220 MOZ_CRASH("Received invalid response parameters!");
michael@0 1221 }
michael@0 1222
michael@0 1223 nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse);
michael@0 1224 NS_ENSURE_SUCCESS(rv, false);
michael@0 1225
michael@0 1226 return true;
michael@0 1227 }
michael@0 1228
michael@0 1229 /*******************************************************************************
michael@0 1230 * IndexedDBDeleteDatabaseRequestChild
michael@0 1231 ******************************************************************************/
michael@0 1232
michael@0 1233 IndexedDBDeleteDatabaseRequestChild::IndexedDBDeleteDatabaseRequestChild(
michael@0 1234 IDBFactory* aFactory,
michael@0 1235 IDBOpenDBRequest* aOpenRequest,
michael@0 1236 const nsACString& aDatabaseId)
michael@0 1237 : mFactory(aFactory), mOpenRequest(aOpenRequest), mDatabaseId(aDatabaseId)
michael@0 1238 {
michael@0 1239 MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestChild);
michael@0 1240 MOZ_ASSERT(aFactory);
michael@0 1241 MOZ_ASSERT(aOpenRequest);
michael@0 1242 MOZ_ASSERT(!aDatabaseId.IsEmpty());
michael@0 1243 }
michael@0 1244
michael@0 1245 IndexedDBDeleteDatabaseRequestChild::~IndexedDBDeleteDatabaseRequestChild()
michael@0 1246 {
michael@0 1247 MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestChild);
michael@0 1248 }
michael@0 1249
michael@0 1250 bool
michael@0 1251 IndexedDBDeleteDatabaseRequestChild::Recv__delete__(const nsresult& aRv)
michael@0 1252 {
michael@0 1253 nsRefPtr<IPCDeleteDatabaseHelper> helper =
michael@0 1254 new IPCDeleteDatabaseHelper(mOpenRequest);
michael@0 1255
michael@0 1256 if (NS_SUCCEEDED(aRv)) {
michael@0 1257 DatabaseInfo::Remove(mDatabaseId);
michael@0 1258 }
michael@0 1259 else {
michael@0 1260 helper->SetError(aRv);
michael@0 1261 }
michael@0 1262
michael@0 1263 ImmediateRunEventTarget target;
michael@0 1264 if (NS_FAILED(helper->Dispatch(&target))) {
michael@0 1265 NS_WARNING("Dispatch of IPCSetVersionHelper failed!");
michael@0 1266 return false;
michael@0 1267 }
michael@0 1268
michael@0 1269 return true;
michael@0 1270 }
michael@0 1271
michael@0 1272 bool
michael@0 1273 IndexedDBDeleteDatabaseRequestChild::RecvBlocked(
michael@0 1274 const uint64_t& aCurrentVersion)
michael@0 1275 {
michael@0 1276 MOZ_ASSERT(mOpenRequest);
michael@0 1277
michael@0 1278 nsCOMPtr<nsIRunnable> runnable =
michael@0 1279 IDBVersionChangeEvent::CreateBlockedRunnable(mOpenRequest,
michael@0 1280 aCurrentVersion, 0);
michael@0 1281
michael@0 1282 ImmediateRunEventTarget target;
michael@0 1283 if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) {
michael@0 1284 NS_WARNING("Dispatch of blocked event failed!");
michael@0 1285 }
michael@0 1286
michael@0 1287 return true;
michael@0 1288 }
michael@0 1289
michael@0 1290 /*******************************************************************************
michael@0 1291 * Helpers
michael@0 1292 ******************************************************************************/
michael@0 1293
michael@0 1294 nsresult
michael@0 1295 IPCOpenDatabaseHelper::UnpackResponseFromParentProcess(
michael@0 1296 const ResponseValue& aResponseValue)
michael@0 1297 {
michael@0 1298 NS_NOTREACHED("Should never get here!");
michael@0 1299 return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
michael@0 1300 }
michael@0 1301
michael@0 1302 AsyncConnectionHelper::ChildProcessSendResult
michael@0 1303 IPCOpenDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode)
michael@0 1304 {
michael@0 1305 MOZ_CRASH("Don't call me!");
michael@0 1306 }
michael@0 1307
michael@0 1308 nsresult
michael@0 1309 IPCOpenDatabaseHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
michael@0 1310 {
michael@0 1311 MOZ_CRASH("Don't call me!");
michael@0 1312 }
michael@0 1313
michael@0 1314 nsresult
michael@0 1315 IPCOpenDatabaseHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
michael@0 1316 {
michael@0 1317 return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, mDatabase),
michael@0 1318 aVal);
michael@0 1319 }
michael@0 1320
michael@0 1321 nsresult
michael@0 1322 IPCSetVersionHelper::UnpackResponseFromParentProcess(
michael@0 1323 const ResponseValue& aResponseValue)
michael@0 1324 {
michael@0 1325 NS_NOTREACHED("Should never get here!");
michael@0 1326 return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
michael@0 1327 }
michael@0 1328
michael@0 1329 AsyncConnectionHelper::ChildProcessSendResult
michael@0 1330 IPCSetVersionHelper::SendResponseToChildProcess(nsresult aResultCode)
michael@0 1331 {
michael@0 1332 MOZ_CRASH("Don't call me!");
michael@0 1333 }
michael@0 1334
michael@0 1335 nsresult
michael@0 1336 IPCSetVersionHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
michael@0 1337 {
michael@0 1338 MOZ_CRASH("Don't call me!");
michael@0 1339 }
michael@0 1340
michael@0 1341 already_AddRefed<nsIDOMEvent>
michael@0 1342 IPCSetVersionHelper::CreateSuccessEvent(mozilla::dom::EventTarget* aOwner)
michael@0 1343 {
michael@0 1344 return IDBVersionChangeEvent::CreateUpgradeNeeded(aOwner,
michael@0 1345 mOldVersion,
michael@0 1346 mRequestedVersion);
michael@0 1347 }
michael@0 1348
michael@0 1349 nsresult
michael@0 1350 IPCSetVersionHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
michael@0 1351 {
michael@0 1352 mOpenRequest->SetTransaction(mTransaction);
michael@0 1353
michael@0 1354 return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, mDatabase),
michael@0 1355 aVal);
michael@0 1356 }
michael@0 1357
michael@0 1358 nsresult
michael@0 1359 IPCDeleteDatabaseHelper::UnpackResponseFromParentProcess(
michael@0 1360 const ResponseValue& aResponseValue)
michael@0 1361 {
michael@0 1362 MOZ_CRASH("Don't call me!");
michael@0 1363 }
michael@0 1364
michael@0 1365 AsyncConnectionHelper::ChildProcessSendResult
michael@0 1366 IPCDeleteDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode)
michael@0 1367 {
michael@0 1368 MOZ_CRASH("Don't call me!");
michael@0 1369 }
michael@0 1370
michael@0 1371 nsresult
michael@0 1372 IPCDeleteDatabaseHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
michael@0 1373 {
michael@0 1374 aVal.setUndefined();
michael@0 1375 return NS_OK;
michael@0 1376 }
michael@0 1377
michael@0 1378 nsresult
michael@0 1379 IPCDeleteDatabaseHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
michael@0 1380 {
michael@0 1381 MOZ_CRASH("Don't call me!");
michael@0 1382 }

mercurial