nsICacheEntryDescriptor.idl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsICacheVisitor.idl"
  7. #include "nsICache.idl"
  8. interface nsISimpleEnumerator;
  9. interface nsICacheListener;
  10. interface nsIInputStream;
  11. interface nsIOutputStream;
  12. interface nsIFile;
  13. interface nsICacheMetaDataVisitor;
  14. [scriptable, uuid(90b17d31-46aa-4fb1-a206-473c966cbc18)]
  15. interface nsICacheEntryDescriptor : nsICacheEntryInfo
  16. {
  17. /**
  18. * Set the time at which the cache entry should be considered invalid (in
  19. * seconds since the Epoch).
  20. */
  21. void setExpirationTime(in uint32_t expirationTime);
  22. /**
  23. * Set the cache entry data size. This will fail if the cache entry
  24. * IS stream based.
  25. */
  26. void setDataSize(in unsigned long size);
  27. /**
  28. * Open blocking input stream to cache data. This will fail if the cache
  29. * entry IS NOT stream based. Use the stream transport service to
  30. * asynchronously read this stream on a background thread. The returned
  31. * stream MAY implement nsISeekableStream.
  32. *
  33. * @param offset
  34. * read starting from this offset into the cached data. an offset
  35. * beyond the end of the stream has undefined consequences.
  36. *
  37. * @return blocking, unbuffered input stream.
  38. */
  39. nsIInputStream openInputStream(in unsigned long offset);
  40. /**
  41. * Open blocking output stream to cache data. This will fail if the cache
  42. * entry IS NOT stream based. Use the stream transport service to
  43. * asynchronously write to this stream on a background thread. The returned
  44. * stream MAY implement nsISeekableStream.
  45. *
  46. * If opening an output stream to existing cached data, the data will be
  47. * truncated to the specified offset.
  48. *
  49. * @param offset
  50. * write starting from this offset into the cached data. an offset
  51. * beyond the end of the stream has undefined consequences.
  52. *
  53. * @return blocking, unbuffered output stream.
  54. */
  55. nsIOutputStream openOutputStream(in unsigned long offset);
  56. /**
  57. * Get/set the cache data element. This will fail if the cache entry
  58. * IS stream based. The cache entry holds a strong reference to this
  59. * object. The object will be released when the cache entry is destroyed.
  60. */
  61. attribute nsISupports cacheElement;
  62. /**
  63. * Stores the Content-Length specified in the HTTP header for this
  64. * entry. Checked before we write to the cache entry, to prevent ever
  65. * taking up space in the cache for an entry that we know up front
  66. * is going to have to be evicted anyway. See bug 588507.
  67. */
  68. attribute int64_t predictedDataSize;
  69. /**
  70. * Get the access granted to this descriptor. See nsICache.idl for the
  71. * definitions of the access modes and a thorough description of their
  72. * corresponding meanings.
  73. */
  74. readonly attribute nsCacheAccessMode accessGranted;
  75. /**
  76. * Get/set the storage policy of the cache entry. See nsICache.idl for
  77. * the definitions of the storage policies.
  78. */
  79. attribute nsCacheStoragePolicy storagePolicy;
  80. /**
  81. * Get the disk file associated with the cache entry.
  82. */
  83. readonly attribute nsIFile file;
  84. /**
  85. * Get/set security info on the cache entry for this descriptor. This fails
  86. * if the storage policy is not STORE_IN_MEMORY.
  87. */
  88. attribute nsISupports securityInfo;
  89. /**
  90. * Get the size of the cache entry data, as stored. This may differ
  91. * from the entry's dataSize, if the entry is compressed.
  92. */
  93. readonly attribute unsigned long storageDataSize;
  94. /**
  95. * Doom the cache entry this descriptor references in order to slate it for
  96. * removal. Once doomed a cache entry cannot be undoomed.
  97. *
  98. * A descriptor with WRITE access can doom the cache entry and choose to
  99. * fail pending requests. This means that pending requests will not get
  100. * a cache descriptor. This is meant as a tool for clients that wish to
  101. * instruct pending requests to skip the cache.
  102. */
  103. void doom();
  104. void doomAndFailPendingRequests(in nsresult status);
  105. /**
  106. * Asynchronously doom an entry. Listener will be notified about the status
  107. * of the operation. Null may be passed if caller doesn't care about the
  108. * result.
  109. */
  110. void asyncDoom(in nsICacheListener listener);
  111. /**
  112. * A writer must validate this cache object before any readers are given
  113. * a descriptor to the object.
  114. */
  115. void markValid();
  116. /**
  117. * Explicitly close the descriptor (optional).
  118. */
  119. void close();
  120. /**
  121. * Methods for accessing meta data. Meta data is a table of key/value
  122. * string pairs. The strings do not have to conform to any particular
  123. * charset, but they must be null terminated.
  124. */
  125. string getMetaDataElement(in string key);
  126. void setMetaDataElement(in string key, in string value);
  127. /**
  128. * Visitor will be called with key/value pair for each meta data element.
  129. */
  130. void visitMetaData(in nsICacheMetaDataVisitor visitor);
  131. };
  132. [scriptable, uuid(22f9a49c-3cf8-4c23-8006-54efb11ac562)]
  133. interface nsICacheMetaDataVisitor : nsISupports
  134. {
  135. /**
  136. * Called for each key/value pair in the meta data for a cache entry
  137. */
  138. boolean visitMetaDataElement(in string key,
  139. in string value);
  140. };