Client.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_quota_client_h__
  6. #define mozilla_dom_quota_client_h__
  7. #include "mozilla/dom/quota/QuotaCommon.h"
  8. #include "mozilla/dom/ipc/IdType.h"
  9. #include "PersistenceType.h"
  10. class nsIRunnable;
  11. #define IDB_DIRECTORY_NAME "idb"
  12. #define ASMJSCACHE_DIRECTORY_NAME "asmjs"
  13. #define DOMCACHE_DIRECTORY_NAME "cache"
  14. BEGIN_QUOTA_NAMESPACE
  15. class QuotaManager;
  16. class UsageInfo;
  17. // An abstract interface for quota manager clients.
  18. // Each storage API must provide an implementation of this interface in order
  19. // to participate in centralized quota and storage handling.
  20. class Client
  21. {
  22. public:
  23. typedef mozilla::Atomic<bool> AtomicBool;
  24. NS_IMETHOD_(MozExternalRefCountType)
  25. AddRef() = 0;
  26. NS_IMETHOD_(MozExternalRefCountType)
  27. Release() = 0;
  28. enum Type {
  29. IDB = 0,
  30. //LS,
  31. //APPCACHE,
  32. ASMJS,
  33. DOMCACHE,
  34. TYPE_MAX
  35. };
  36. virtual Type
  37. GetType() = 0;
  38. static nsresult
  39. TypeToText(Type aType, nsAString& aText)
  40. {
  41. switch (aType) {
  42. case IDB:
  43. aText.AssignLiteral(IDB_DIRECTORY_NAME);
  44. break;
  45. case ASMJS:
  46. aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME);
  47. break;
  48. case DOMCACHE:
  49. aText.AssignLiteral(DOMCACHE_DIRECTORY_NAME);
  50. break;
  51. case TYPE_MAX:
  52. default:
  53. NS_NOTREACHED("Bad id value!");
  54. return NS_ERROR_UNEXPECTED;
  55. }
  56. return NS_OK;
  57. }
  58. static nsresult
  59. TypeFromText(const nsAString& aText, Type& aType)
  60. {
  61. if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) {
  62. aType = IDB;
  63. }
  64. else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) {
  65. aType = ASMJS;
  66. }
  67. else if (aText.EqualsLiteral(DOMCACHE_DIRECTORY_NAME)) {
  68. aType = DOMCACHE;
  69. }
  70. else {
  71. return NS_ERROR_FAILURE;
  72. }
  73. return NS_OK;
  74. }
  75. // Methods which are called on the IO thred.
  76. virtual nsresult
  77. InitOrigin(PersistenceType aPersistenceType,
  78. const nsACString& aGroup,
  79. const nsACString& aOrigin,
  80. const AtomicBool& aCanceled,
  81. UsageInfo* aUsageInfo) = 0;
  82. virtual nsresult
  83. GetUsageForOrigin(PersistenceType aPersistenceType,
  84. const nsACString& aGroup,
  85. const nsACString& aOrigin,
  86. const AtomicBool& aCanceled,
  87. UsageInfo* aUsageInfo) = 0;
  88. virtual void
  89. OnOriginClearCompleted(PersistenceType aPersistenceType,
  90. const nsACString& aOrigin) = 0;
  91. virtual void
  92. ReleaseIOThreadObjects() = 0;
  93. // Methods which are called on the background thred.
  94. virtual void
  95. AbortOperations(const nsACString& aOrigin) = 0;
  96. virtual void
  97. AbortOperationsForProcess(ContentParentId aContentParentId) = 0;
  98. virtual void
  99. StartIdleMaintenance() = 0;
  100. virtual void
  101. StopIdleMaintenance() = 0;
  102. virtual void
  103. ShutdownWorkThreads() = 0;
  104. // Methods which are called on the main thread.
  105. virtual void
  106. DidInitialize(QuotaManager* aQuotaManager)
  107. { }
  108. virtual void
  109. WillShutdown()
  110. { }
  111. protected:
  112. virtual ~Client()
  113. { }
  114. };
  115. END_QUOTA_NAMESPACE
  116. #endif // mozilla_dom_quota_client_h__