CacheParent.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/cache/CacheParent.h"
  6. #include "mozilla/dom/cache/CacheOpParent.h"
  7. #include "nsCOMPtr.h"
  8. namespace mozilla {
  9. namespace dom {
  10. namespace cache {
  11. // Declared in ActorUtils.h
  12. void
  13. DeallocPCacheParent(PCacheParent* aActor)
  14. {
  15. delete aActor;
  16. }
  17. CacheParent::CacheParent(cache::Manager* aManager, CacheId aCacheId)
  18. : mManager(aManager)
  19. , mCacheId(aCacheId)
  20. {
  21. MOZ_COUNT_CTOR(cache::CacheParent);
  22. MOZ_DIAGNOSTIC_ASSERT(mManager);
  23. mManager->AddRefCacheId(mCacheId);
  24. }
  25. CacheParent::~CacheParent()
  26. {
  27. MOZ_COUNT_DTOR(cache::CacheParent);
  28. MOZ_DIAGNOSTIC_ASSERT(!mManager);
  29. }
  30. void
  31. CacheParent::ActorDestroy(ActorDestroyReason aReason)
  32. {
  33. MOZ_DIAGNOSTIC_ASSERT(mManager);
  34. mManager->ReleaseCacheId(mCacheId);
  35. mManager = nullptr;
  36. }
  37. PCacheOpParent*
  38. CacheParent::AllocPCacheOpParent(const CacheOpArgs& aOpArgs)
  39. {
  40. if (aOpArgs.type() != CacheOpArgs::TCacheMatchArgs &&
  41. aOpArgs.type() != CacheOpArgs::TCacheMatchAllArgs &&
  42. aOpArgs.type() != CacheOpArgs::TCachePutAllArgs &&
  43. aOpArgs.type() != CacheOpArgs::TCacheDeleteArgs &&
  44. aOpArgs.type() != CacheOpArgs::TCacheKeysArgs)
  45. {
  46. MOZ_CRASH("Invalid operation sent to Cache actor!");
  47. }
  48. return new CacheOpParent(Manager(), mCacheId, aOpArgs);
  49. }
  50. bool
  51. CacheParent::DeallocPCacheOpParent(PCacheOpParent* aActor)
  52. {
  53. delete aActor;
  54. return true;
  55. }
  56. bool
  57. CacheParent::RecvPCacheOpConstructor(PCacheOpParent* aActor,
  58. const CacheOpArgs& aOpArgs)
  59. {
  60. auto actor = static_cast<CacheOpParent*>(aActor);
  61. actor->Execute(mManager);
  62. return true;
  63. }
  64. bool
  65. CacheParent::RecvTeardown()
  66. {
  67. if (!Send__delete__(this)) {
  68. // child process is gone, warn and allow actor to clean up normally
  69. NS_WARNING("Cache failed to send delete.");
  70. }
  71. return true;
  72. }
  73. } // namespace cache
  74. } // namespace dom
  75. } // namespace mozilla