DBAction.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef mozilla_dom_cache_DBAction_h
  6. #define mozilla_dom_cache_DBAction_h
  7. #include "mozilla/dom/cache/Action.h"
  8. #include "mozilla/RefPtr.h"
  9. #include "nsString.h"
  10. class mozIStorageConnection;
  11. class nsIFile;
  12. namespace mozilla {
  13. namespace dom {
  14. namespace cache {
  15. class DBAction : public Action
  16. {
  17. protected:
  18. // The mode specifies whether the database should already exist or if its
  19. // ok to create a new database.
  20. enum Mode
  21. {
  22. Existing,
  23. Create
  24. };
  25. explicit DBAction(Mode aMode);
  26. // Action objects are deleted through their base pointer
  27. virtual ~DBAction();
  28. // Just as the resolver must be ref'd until resolve, you may also
  29. // ref the DB connection. The connection can only be referenced from the
  30. // target thread and must be released upon resolve.
  31. virtual void
  32. RunWithDBOnTarget(Resolver* aResolver, const QuotaInfo& aQuotaInfo,
  33. nsIFile* aDBDir, mozIStorageConnection* aConn) = 0;
  34. private:
  35. virtual void
  36. RunOnTarget(Resolver* aResolver, const QuotaInfo& aQuotaInfo,
  37. Data* aOptionalData) override;
  38. nsresult OpenConnection(const QuotaInfo& aQuotaInfo, nsIFile* aQuotaDir,
  39. mozIStorageConnection** aConnOut);
  40. nsresult WipeDatabase(nsIFile* aDBFile, nsIFile* aDBDir);
  41. const Mode mMode;
  42. };
  43. class SyncDBAction : public DBAction
  44. {
  45. protected:
  46. explicit SyncDBAction(Mode aMode);
  47. // Action objects are deleted through their base pointer
  48. virtual ~SyncDBAction();
  49. virtual nsresult
  50. RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
  51. mozIStorageConnection* aConn) = 0;
  52. private:
  53. virtual void
  54. RunWithDBOnTarget(Resolver* aResolver, const QuotaInfo& aQuotaInfo,
  55. nsIFile* aDBDir, mozIStorageConnection* aConn) override;
  56. };
  57. } // namespace cache
  58. } // namespace dom
  59. } // namespace mozilla
  60. #endif // mozilla_dom_cache_DBAction_h