2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 20:18:30 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsDeviceStorage_h
|
|
|
|
#define nsDeviceStorage_h
|
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-08-01 11:22:20 +04:00
|
|
|
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
#include "DOMRequest.h"
|
2013-03-02 04:21:01 +04:00
|
|
|
#include "DOMCursor.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-05-21 20:18:30 +04:00
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIURI.h"
|
2012-07-30 18:58:26 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2012-05-21 20:18:30 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2012-08-02 10:29:34 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIObserver.h"
|
2012-09-14 09:37:00 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2012-08-02 10:29:34 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-09-11 10:52:47 +04:00
|
|
|
#include "prtime.h"
|
2012-08-02 10:29:34 +04:00
|
|
|
#include "DeviceStorage.h"
|
2013-05-03 03:26:31 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-03-17 12:51:36 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2015-05-12 15:09:51 +03:00
|
|
|
|
|
|
|
namespace dom {
|
2015-08-26 03:13:34 +03:00
|
|
|
class BlobImpl;
|
|
|
|
class DeviceStorageParams;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-03-17 12:51:36 +04:00
|
|
|
} // namespace mozilla
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
class nsDOMDeviceStorage;
|
|
|
|
class DeviceStorageCursorRequest;
|
|
|
|
|
2015-08-18 14:42:12 +03:00
|
|
|
//#define DS_LOGGING 1
|
|
|
|
|
|
|
|
#ifdef DS_LOGGING
|
2015-08-26 03:13:34 +03:00
|
|
|
// FIXME -- use MOZ_LOG and set to warn by default
|
2015-08-18 14:42:12 +03:00
|
|
|
#define DS_LOG_DEBUG(msg, ...) printf_stderr("[%s:%d] " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
|
|
|
|
#define DS_LOG_INFO DS_LOG_DEBUG
|
|
|
|
#define DS_LOG_WARN DS_LOG_DEBUG
|
|
|
|
#define DS_LOG_ERROR DS_LOG_DEBUG
|
|
|
|
#else
|
|
|
|
#define DS_LOG_DEBUG(msg, ...)
|
|
|
|
#define DS_LOG_INFO(msg, ...)
|
|
|
|
#define DS_LOG_WARN(msg, ...)
|
|
|
|
#define DS_LOG_ERROR(msg, ...)
|
|
|
|
#endif
|
|
|
|
|
2012-10-13 19:20:14 +04:00
|
|
|
#define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError"
|
|
|
|
#define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "NotFoundError"
|
|
|
|
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "TypeMismatchError"
|
|
|
|
#define POST_ERROR_EVENT_PERMISSION_DENIED "SecurityError"
|
|
|
|
#define POST_ERROR_EVENT_ILLEGAL_TYPE "TypeMismatchError"
|
2012-06-20 03:14:39 +04:00
|
|
|
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
|
|
|
|
2012-11-14 04:06:42 +04:00
|
|
|
enum DeviceStorageRequestType {
|
2015-08-26 03:13:34 +03:00
|
|
|
DEVICE_STORAGE_REQUEST_READ,
|
|
|
|
DEVICE_STORAGE_REQUEST_WRITE,
|
|
|
|
DEVICE_STORAGE_REQUEST_APPEND,
|
|
|
|
DEVICE_STORAGE_REQUEST_CREATE,
|
|
|
|
DEVICE_STORAGE_REQUEST_DELETE,
|
|
|
|
DEVICE_STORAGE_REQUEST_WATCH,
|
|
|
|
DEVICE_STORAGE_REQUEST_FREE_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_USED_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_AVAILABLE,
|
|
|
|
DEVICE_STORAGE_REQUEST_STATUS,
|
|
|
|
DEVICE_STORAGE_REQUEST_FORMAT,
|
|
|
|
DEVICE_STORAGE_REQUEST_MOUNT,
|
|
|
|
DEVICE_STORAGE_REQUEST_UNMOUNT,
|
|
|
|
DEVICE_STORAGE_REQUEST_CREATEFD,
|
|
|
|
DEVICE_STORAGE_REQUEST_CURSOR
|
|
|
|
};
|
|
|
|
|
|
|
|
enum DeviceStorageAccessType {
|
|
|
|
DEVICE_STORAGE_ACCESS_READ,
|
|
|
|
DEVICE_STORAGE_ACCESS_WRITE,
|
|
|
|
DEVICE_STORAGE_ACCESS_CREATE,
|
|
|
|
DEVICE_STORAGE_ACCESS_UNDEFINED,
|
|
|
|
DEVICE_STORAGE_ACCESS_COUNT
|
2012-11-14 04:06:42 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DeviceStorageUsedSpaceCache final
|
2013-05-03 03:26:31 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DeviceStorageUsedSpaceCache* CreateOrGet();
|
|
|
|
|
|
|
|
DeviceStorageUsedSpaceCache();
|
|
|
|
~DeviceStorageUsedSpaceCache();
|
|
|
|
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class InvalidateRunnable final : public mozilla::Runnable
|
2013-05-03 03:26:31 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-05-11 13:10:18 +04:00
|
|
|
InvalidateRunnable(DeviceStorageUsedSpaceCache* aCache,
|
|
|
|
const nsAString& aStorageName)
|
|
|
|
: mCache(aCache)
|
|
|
|
, mStorageName(aStorageName) {}
|
2013-05-03 03:26:31 +04:00
|
|
|
|
|
|
|
~InvalidateRunnable() {}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-05-11 13:10:18 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageUsedSpaceCache::CacheEntry> cacheEntry;
|
2013-05-11 13:10:18 +04:00
|
|
|
cacheEntry = mCache->GetCacheEntry(mStorageName);
|
|
|
|
if (cacheEntry) {
|
|
|
|
cacheEntry->mDirty = true;
|
|
|
|
}
|
2013-05-03 03:26:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
2013-05-11 13:10:18 +04:00
|
|
|
DeviceStorageUsedSpaceCache* mCache;
|
|
|
|
nsString mStorageName;
|
2013-05-03 03:26:31 +04:00
|
|
|
};
|
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
void Invalidate(const nsAString& aStorageName)
|
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mIOThread);
|
2013-05-03 03:26:31 +04:00
|
|
|
|
2015-11-20 10:47:49 +03:00
|
|
|
mIOThread->Dispatch(new InvalidateRunnable(this, aStorageName),
|
|
|
|
NS_DISPATCH_NORMAL);
|
2013-05-03 03:26:31 +04:00
|
|
|
}
|
|
|
|
|
2015-11-20 10:47:49 +03:00
|
|
|
void Dispatch(already_AddRefed<nsIRunnable>&& aRunnable)
|
2013-05-11 13:10:18 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mIOThread);
|
2013-05-03 03:26:31 +04:00
|
|
|
|
2015-11-20 10:47:49 +03:00
|
|
|
mIOThread->Dispatch(mozilla::Move(aRunnable), NS_DISPATCH_NORMAL);
|
2013-05-03 03:26:31 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
nsresult AccumUsedSizes(const nsAString& aStorageName,
|
|
|
|
uint64_t* aPictureSize, uint64_t* aVideosSize,
|
|
|
|
uint64_t* aMusicSize, uint64_t* aTotalSize);
|
|
|
|
|
|
|
|
void SetUsedSizes(const nsAString& aStorageName,
|
|
|
|
uint64_t aPictureSize, uint64_t aVideosSize,
|
2013-05-03 03:26:31 +04:00
|
|
|
uint64_t aMusicSize, uint64_t aTotalSize);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class InvalidateRunnable;
|
|
|
|
|
2014-04-14 23:04:24 +04:00
|
|
|
struct CacheEntry
|
2013-05-11 13:10:18 +04:00
|
|
|
{
|
2014-04-23 05:31:04 +04:00
|
|
|
// Technically, this doesn't need to be threadsafe, but the implementation
|
|
|
|
// of the non-thread safe one causes ASSERTS due to the underlying thread
|
|
|
|
// associated with a LazyIdleThread changing from time to time.
|
2014-06-19 06:28:59 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheEntry)
|
2014-04-14 23:04:24 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
bool mDirty;
|
|
|
|
nsString mStorageName;
|
2013-06-04 18:35:33 +04:00
|
|
|
int64_t mFreeBytes;
|
2013-05-11 13:10:18 +04:00
|
|
|
uint64_t mPicturesUsedSize;
|
|
|
|
uint64_t mVideosUsedSize;
|
|
|
|
uint64_t mMusicUsedSize;
|
|
|
|
uint64_t mTotalUsedSize;
|
2014-06-19 06:28:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~CacheEntry() {}
|
2013-05-11 13:10:18 +04:00
|
|
|
};
|
2014-04-14 23:04:24 +04:00
|
|
|
already_AddRefed<CacheEntry> GetCacheEntry(const nsAString& aStorageName);
|
2013-05-03 03:26:31 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<CacheEntry>> mCacheEntries;
|
2013-05-03 03:26:31 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
|
|
|
|
|
|
|
static mozilla::StaticAutoPtr<DeviceStorageUsedSpaceCache> sDeviceStorageUsedSpaceCache;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DeviceStorageTypeChecker final
|
2012-09-14 09:37:00 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DeviceStorageTypeChecker* CreateOrGet();
|
|
|
|
|
|
|
|
DeviceStorageTypeChecker();
|
|
|
|
~DeviceStorageTypeChecker();
|
|
|
|
|
|
|
|
void InitFromBundle(nsIStringBundle* aBundle);
|
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
bool Check(const nsAString& aType, mozilla::dom::BlobImpl* aBlob);
|
2012-09-14 09:37:00 +04:00
|
|
|
bool Check(const nsAString& aType, nsIFile* aFile);
|
2014-10-15 00:50:55 +04:00
|
|
|
bool Check(const nsAString& aType, const nsString& aPath);
|
2013-05-03 03:26:31 +04:00
|
|
|
void GetTypeFromFile(nsIFile* aFile, nsAString& aType);
|
2013-05-11 13:10:18 +04:00
|
|
|
void GetTypeFromFileName(const nsAString& aFileName, nsAString& aType);
|
2015-08-26 03:13:34 +03:00
|
|
|
static nsresult GetPermissionForType(const nsAString& aType,
|
|
|
|
nsACString& aPermissionResult);
|
|
|
|
static nsresult GetAccessForRequest(const DeviceStorageRequestType aRequestType,
|
|
|
|
nsACString& aAccessResult);
|
|
|
|
static nsresult GetAccessForIndex(size_t aAccessIndex, nsACString& aAccessResult);
|
|
|
|
static size_t GetAccessIndexForRequest(const DeviceStorageRequestType aRequestType);
|
2013-04-02 23:52:21 +04:00
|
|
|
static bool IsVolumeBased(const nsAString& aType);
|
2014-10-15 00:50:55 +04:00
|
|
|
static bool IsSharedMediaRoot(const nsAString& aType);
|
2012-09-14 09:37:00 +04:00
|
|
|
|
2012-09-14 09:37:00 +04:00
|
|
|
private:
|
|
|
|
nsString mPicturesExtensions;
|
|
|
|
nsString mVideosExtensions;
|
|
|
|
nsString mMusicExtensions;
|
|
|
|
|
2013-05-03 03:26:31 +04:00
|
|
|
static mozilla::StaticAutoPtr<DeviceStorageTypeChecker> sDeviceStorageTypeChecker;
|
2012-09-14 09:37:00 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDOMDeviceStorageCursor final
|
2013-03-02 04:21:01 +04:00
|
|
|
: public mozilla::dom::DOMCursor
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-03-17 14:20:39 +04:00
|
|
|
NS_FORWARD_NSIDOMDOMCURSOR(mozilla::dom::DOMCursor::)
|
2013-03-02 04:21:01 +04:00
|
|
|
|
2013-03-17 12:51:36 +04:00
|
|
|
// DOMCursor
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Continue(mozilla::ErrorResult& aRv) override;
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
nsDOMDeviceStorageCursor(nsIGlobalObject* aGlobal,
|
|
|
|
DeviceStorageCursorRequest* aRequest);
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
void FireSuccess(JS::Handle<JS::Value> aResult);
|
|
|
|
void FireError(const nsString& aReason);
|
|
|
|
void FireDone();
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~nsDOMDeviceStorageCursor();
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
bool mOkToCallContinue;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageCursorRequest> mRequest;
|
2015-08-26 03:13:34 +03:00
|
|
|
};
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
class DeviceStorageRequestManager final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DeviceStorageRequestManager)
|
|
|
|
|
|
|
|
static const uint32_t INVALID_ID = 0;
|
|
|
|
|
|
|
|
DeviceStorageRequestManager();
|
|
|
|
|
|
|
|
bool IsOwningThread();
|
2015-11-20 10:47:49 +03:00
|
|
|
nsresult DispatchToOwningThread(already_AddRefed<nsIRunnable>&& aRunnable);
|
2015-08-26 03:13:34 +03:00
|
|
|
|
|
|
|
void StorePermission(size_t aAccess, bool aAllow);
|
|
|
|
uint32_t CheckPermission(size_t aAccess);
|
2012-08-31 02:17:38 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
/* These must be called on the owning thread context of the device
|
|
|
|
storage object. It will hold onto a device storage reference until
|
|
|
|
all of the pending requests are completed or shutdown is called. */
|
|
|
|
uint32_t Create(nsDOMDeviceStorage* aDeviceStorage,
|
|
|
|
mozilla::dom::DOMRequest** aRequest);
|
|
|
|
uint32_t Create(nsDOMDeviceStorage* aDeviceStorage,
|
|
|
|
DeviceStorageCursorRequest* aRequest,
|
|
|
|
nsDOMDeviceStorageCursor** aCursor);
|
|
|
|
|
|
|
|
/* These may be called from any thread context and post a request
|
|
|
|
to the owning thread to resolve the underlying DOMRequest or
|
|
|
|
DOMCursor. In order to trigger FireDone for a DOMCursor, one
|
|
|
|
should call Resolve with only the request ID. */
|
|
|
|
nsresult Resolve(uint32_t aId, bool aForceDispatch);
|
|
|
|
nsresult Resolve(uint32_t aId, const nsString& aValue, bool aForceDispatch);
|
|
|
|
nsresult Resolve(uint32_t aId, uint64_t aValue, bool aForceDispatch);
|
|
|
|
nsresult Resolve(uint32_t aId, DeviceStorageFile* aValue, bool aForceDispatch);
|
|
|
|
nsresult Resolve(uint32_t aId, mozilla::dom::BlobImpl* aValue, bool aForceDispatch);
|
|
|
|
nsresult Reject(uint32_t aId, const nsString& aReason);
|
|
|
|
nsresult Reject(uint32_t aId, const char* aReason);
|
|
|
|
|
|
|
|
void Shutdown();
|
2012-10-05 00:40:45 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
private:
|
2015-08-26 03:13:34 +03:00
|
|
|
DeviceStorageRequestManager(const DeviceStorageRequestManager&) = delete;
|
|
|
|
DeviceStorageRequestManager& operator=(const DeviceStorageRequestManager&) = delete;
|
|
|
|
|
|
|
|
struct ListEntry {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::DOMRequest> mRequest;
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t mId;
|
|
|
|
bool mCursor;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTArray<ListEntry> ListType;
|
|
|
|
typedef ListType::index_type ListIndex;
|
|
|
|
|
|
|
|
virtual ~DeviceStorageRequestManager();
|
|
|
|
uint32_t CreateInternal(mozilla::dom::DOMRequest* aRequest, bool aCursor);
|
|
|
|
nsresult ResolveInternal(ListIndex aIndex, JS::HandleValue aResult);
|
|
|
|
nsresult RejectInternal(ListIndex aIndex, const nsString& aReason);
|
2015-11-20 10:47:49 +03:00
|
|
|
nsresult DispatchOrAbandon(uint32_t aId,
|
|
|
|
already_AddRefed<nsIRunnable>&& aRunnable);
|
2015-08-26 03:13:34 +03:00
|
|
|
ListType::index_type Find(uint32_t aId);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> mOwningThread;
|
|
|
|
ListType mPending; // owning thread or destructor only
|
|
|
|
|
|
|
|
mozilla::Mutex mMutex;
|
|
|
|
uint32_t mPermissionCache[DEVICE_STORAGE_ACCESS_COUNT];
|
|
|
|
bool mShutdown;
|
|
|
|
|
|
|
|
static mozilla::Atomic<uint32_t> sLastRequestId;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DeviceStorageRequest
|
2016-04-26 03:23:21 +03:00
|
|
|
: public mozilla::Runnable
|
2015-08-26 03:13:34 +03:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
DeviceStorageRequest();
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
public:
|
|
|
|
virtual void Initialize(DeviceStorageRequestManager* aManager,
|
2015-11-20 10:47:49 +03:00
|
|
|
already_AddRefed<DeviceStorageFile>&& aFile,
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t aRequest);
|
|
|
|
|
|
|
|
virtual void Initialize(DeviceStorageRequestManager* aManager,
|
2015-11-20 10:47:49 +03:00
|
|
|
already_AddRefed<DeviceStorageFile>&& aFile,
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t aRequest,
|
|
|
|
mozilla::dom::BlobImpl* aBlob);
|
|
|
|
|
|
|
|
virtual void Initialize(DeviceStorageRequestManager* aManager,
|
2015-11-20 10:47:49 +03:00
|
|
|
already_AddRefed<DeviceStorageFile>&& aFile,
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t aRequest,
|
|
|
|
DeviceStorageFileDescriptor* aDSFileDescriptor);
|
|
|
|
|
|
|
|
DeviceStorageAccessType GetAccess() const;
|
|
|
|
void GetStorageType(nsAString& aType) const;
|
|
|
|
DeviceStorageFile* GetFile() const;
|
|
|
|
DeviceStorageFileDescriptor* GetFileDescriptor() const;
|
|
|
|
DeviceStorageRequestManager* GetManager() const;
|
|
|
|
|
|
|
|
uint32_t GetId() const
|
|
|
|
{
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PermissionCacheMissed()
|
|
|
|
{
|
|
|
|
mPermissionCached = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Cancel();
|
|
|
|
nsresult Allow();
|
|
|
|
|
|
|
|
nsresult Resolve()
|
|
|
|
{
|
|
|
|
/* Always dispatch an empty resolve because that signals a cursor end
|
|
|
|
and should not be executed directly from the caller's context due
|
|
|
|
to the object potentially getting freed before we return. */
|
|
|
|
uint32_t id = mId;
|
|
|
|
mId = DeviceStorageRequestManager::INVALID_ID;
|
|
|
|
return mManager->Resolve(id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
nsresult Resolve(T aValue)
|
|
|
|
{
|
|
|
|
uint32_t id = mId;
|
|
|
|
if (!mMultipleResolve) {
|
|
|
|
mId = DeviceStorageRequestManager::INVALID_ID;
|
|
|
|
}
|
|
|
|
return mManager->Resolve(id, aValue, ForceDispatch());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
nsresult Reject(T aReason)
|
|
|
|
{
|
|
|
|
uint32_t id = mId;
|
|
|
|
mId = DeviceStorageRequestManager::INVALID_ID;
|
|
|
|
return mManager->Reject(id, aReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool ForceDispatch() const
|
|
|
|
{
|
|
|
|
return !mSendToParent && mPermissionCached;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DeviceStorageRequest();
|
2015-09-16 19:18:25 +03:00
|
|
|
virtual nsresult Prepare();
|
2015-08-26 03:13:34 +03:00
|
|
|
virtual nsresult CreateSendParams(mozilla::dom::DeviceStorageParams& aParams);
|
|
|
|
nsresult AllowInternal();
|
|
|
|
nsresult SendToParentProcess();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageRequestManager> mManager;
|
|
|
|
RefPtr<DeviceStorageFile> mFile;
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t mId;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::BlobImpl> mBlob;
|
|
|
|
RefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
2015-08-26 03:13:34 +03:00
|
|
|
DeviceStorageAccessType mAccess;
|
|
|
|
bool mSendToParent;
|
2015-09-16 19:18:25 +03:00
|
|
|
bool mUseMainThread;
|
2015-08-26 03:13:34 +03:00
|
|
|
bool mUseStreamTransport;
|
|
|
|
bool mCheckFile;
|
|
|
|
bool mCheckBlob;
|
|
|
|
bool mMultipleResolve;
|
|
|
|
bool mPermissionCached;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DeviceStorageRequest(const DeviceStorageRequest&) = delete;
|
|
|
|
DeviceStorageRequest& operator=(const DeviceStorageRequest&) = delete;
|
2012-06-20 03:14:39 +04:00
|
|
|
};
|
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
class DeviceStorageCursorRequest final
|
|
|
|
: public DeviceStorageRequest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeviceStorageCursorRequest();
|
|
|
|
|
|
|
|
using DeviceStorageRequest::Initialize;
|
2013-04-03 03:17:52 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
virtual void Initialize(DeviceStorageRequestManager* aManager,
|
2015-11-20 10:47:49 +03:00
|
|
|
already_AddRefed<DeviceStorageFile>&& aFile,
|
2015-08-26 03:13:34 +03:00
|
|
|
uint32_t aRequest,
|
|
|
|
PRTime aSince);
|
2013-04-03 03:17:52 +04:00
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
void AddFiles(size_t aSize);
|
|
|
|
void AddFile(already_AddRefed<DeviceStorageFile> aFile);
|
|
|
|
nsresult Continue();
|
|
|
|
NS_IMETHOD Run() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~DeviceStorageCursorRequest()
|
|
|
|
{ };
|
|
|
|
|
|
|
|
nsresult SendContinueToParentProcess();
|
|
|
|
nsresult CreateSendParams(mozilla::dom::DeviceStorageParams& aParams) override;
|
|
|
|
|
|
|
|
size_t mIndex;
|
|
|
|
PRTime mSince;
|
|
|
|
nsString mStorageType;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DeviceStorageFile> > mFiles;
|
2015-08-26 03:13:34 +03:00
|
|
|
};
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2012-05-21 20:18:30 +04:00
|
|
|
#endif
|