mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
e3d7542d66
- Bug 1145326 - String#normalize form parameter might not be an atom. r=Waldo (291a9d9c3)
- 1156886 - Optimize toLowerCase and toUpperCase on ASCII characters. r=luke (6dad527a9)
- Bug 1102219 - Part 0: Combine WARNED_* slots in GlobalObject and turn it into a bitset. r=till (1496c25c4)
- Bug 1102219 - Part 1: Add `String.prototype.includes`; keep `String.prototype.contains` around as an alias with a (non-release builds only) warning. r=till (8502ce4c4)
- Bug 1102219 - Part 3: Replace more `String.prototype.contains` with `String.prototype.includes` in JS code. r=till (d2d3e3455)
- Bug 1102219 - followup for Part 0: Fix code alignment and argument name in GlobalObject.h. r=me (df2063dba)
- Bug 863515 - Expose hasContentOpener on nsITabParent. r=smaug. (0e1c18870)
- Bug 1157454 - Satisfy TSan by removing the unneeded mEarlyRv read in WebCryptoTask::CalculateResult() r=rbarnes (ba5fca0ae)
- Bug 1106087 - Recreate newly generated ECDH private keys with an CKA_EC_POINT attribute to support JWK and PKCS8 export r=rbarnes (07634e876)
- Bug 1158927 - Calls to CryptoKey::PrivateKeyToPkcs8() and ::PublicKeyToSpki() should check return values r=rbarnes (03787e2fb)
- Bug 1050175 - Add raw import/export for EC public keys to the WebCrypto API r=rbarnes,smaug (168a93425)
- Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::SetLength calls. r=froydnj (f85ec3e02)
- Bug 977586 - omit quotes in top-level strings logged via console.log(), and omit extra spaces when custom styles (%c) are used. r=past,baku (58391e3d0)
- Bug 1167423 - patch 1 - Handle return values of FallibleTArray functions in Console API, r=smaug (7e36592a4)
- Bug 1167423 - patch 2 - Handle return values of FallibleTArray functions in WebSocket, r=smaug (286dc7745)
- Bug 1167423 - patch 3 - Handle return values of FallibleTArray functions in MutationObserver, r=smaug (e4cc88cfb)
- Bug 1167423 - patch 4 - Handle return values of FallibleTArray functions in CanvasRenderingContext2D, r=smaug (d02bfff6c)
- Bug 1167423 - patch 5 - Handle return values of FallibleTArray functions in WebGL2Context, r=smaug (789aac4ea)
- Bug 1167423 - patch 6 - Handle return values of FallibleTArray functions in WebCryptTask, r=smaug (7ca60765a)
- Bug 968520 - Use FallibleTArray::TruncateLength instead of SetLength where possible. r=froydnj (bb8e960b4)
- Bug 1167423 - patch 7 - Handle return values of FallibleTArray functions in DataStore API, r=smaug (e207e7371)
- Bug 1167423 - patch 8 - Handle return values of FallibleTArray functions in HTMLInputElement, r=smaug (f87b9d4fb)
- Bug 1167423 - patch 9 - Handle return values of FallibleTArray functions in MediaSource, r=jya (9d2905c5a)
- Bug 1167423 - patch 10 - Handle return values of FallibleTArray functions in MobileMessage, r=smaug (6e8b7ce0f)
- Bug 1167418 - Check fallible AppendElements call in FontFaceSet. r=poiru (cd64d2b69)
- Bug 968520 - Add mozilla::fallible to FallibleTArray::AppendElements calls. r=froydnj (a16f43ea9)
- Bug 947854 part 2 - Avoid exiting fullscreen mode when exit from DOM fullscreen. r=smaug,dao (4fed384bc) (partly)
- Bug 947854 part 3 - Include testing MozExitedFullscreen event in existing chrome test. r=smaug (b463bf2e8)
- Bug 1105939 part 1 - Backout workaround from bug 740923. r=smichaud (08ae588b7)
- Bug 1105939 part 2 - Suppress windows animation when hiding chrome on OS X. r=smichaud (f1792f1e8)
- Bug 1105939 part 3 - Save and restore window collection behavior when showing/hiding window chrome. r=mstange (359c2d820)
- Bug 1105939 part 4 - Treat cocoa window without titlebar as fullscreen to avoid drawing rounded corners on it. r=mstange (40a921643)
- Bug 1105939 part 5 - Rename parameter aRequireTrust of SetFullScreenInternal to aFullscreenMode for increased clarity. r=smaug (650f229c3)
- Bug 1105939 part 6 - Add a method to nsIWidget for widget to distinguish between fullscreen mode and DOM fullscreen. r=roc (e1d03316d)
- Bug 1105939 part 7 - Use tranditional fullscreen on Mac for DOM fullscreen. r=smichaud (8e737b365)
- Bug 1164625 - Don't redraw the titlebar for unified toolbar height changes when the titlebar is under Gecko's control. r=smichaud (683c87ff4)
- Bug 1171210 - Add a telemetry probe for how long it takes to clear plugin cookies during sanitize. r=vladan (26cd118c5) (partly)
- Bug 1148012 - Add a run ID for plugins to differentiate subsequent runs of the same plugins. r=jimm. (dd89a0278)
- Bug 1148012 - Expose run ID through nsIObjectLoadingContent.idl. r=josh,smaug. (82080018e)
- Bug 1148012 - Send the run ID and plugin name along with the plugin-crashed observer notification. r=josh. (d0f26b99a)
- Bug 1152395: Ensure that NP_Shutdown respects async plugin init; r=jimm (6c94915e5)
- Bug 1146955 - Unify pluginID for GMP and runID for NPAPI plugins to use the same internal incrementor. r=jesup, mrbkap. (b5db7ac02)
- Bug 1146955 - Dispatch PluginCrashed event in content process on GMP crash for PeerConnection. r=jesup. (3eedefe8c)
- Bug 1123759: Set low integrity on NPAPI processes for Windows sandboxing policy level >= 2. r=bbondy, r=bsmedberg (bc795adba)
- bits of Bug 1008435 - Let the Gecko Profiler work with child processes. (7db2f4f82)
- Bug 1116188 - Add async ProfileGatherer as the mechanism for gathering profiles from subprocesses. r=bgirard,bz (23aed75ce)
- add ProcessHangMonitor.jsm as of Bug 1120650: add telemetry probe for slow script notices. (7501c04d7)
- Bug 1160142 - For e10s plugin hangs take the minidump of the browser process before we message the chrome UI about the hang. r=billm (557ae5892)
- Bug 1175975 - Null crash fix in ProcessHangMonitor (r=jimm) (52fce4c7c)
- Bug 1164543 - Add HasLocalInstance support (r=jimm) (572e9e17e)
- Bug 699860 - Removed useJSTransfer and deleteAllLike usage from ForgetAboutSite.jsm. r=paolo (e3f9013bc)
- Bug 1189967 - Add cmath to the wrapped STL headers. r=nfroyd Somehow, TimeStamp.cpp fails to build with MSVC 2015 without this. (692e3d17d)
- Bug 1249167 - Fix dependencies involving stdc++compat and clang-plugin. r=mshal (96af922d7)
- Bug 1248416 - add symbols for bad_function_call exception for C++ runtimes. r=nfroyd (fa28f7568)
- Bug 1228641. Add a polyfill of std::initializer_list. r=froydnj (5625de4ac)
- Bug 1163329 - Add a utility for expanding a tuple into a variadic argument list to MFBT. r=froydnj (ff41a27b7)
- Bug 1255540 - Properly run the clang-plugin tests. r=gps (bdf4d9ac4)
- Bug 1152759 - Regroup Performance Monitoring modules/components;r=yoric (cfdc3c13a)
- Bug 1151750 - about:performance now recapitulates alerts. r=mossop (e9d2a3a42)
- Bug 1150863 - added play and pause button to about:performance in addition to a dropdown list to select the refresh rate. r=Yoric (944b00cfc)
- Bug 1149486 - Extract a window title and window ID for PerformanceStats. r=mossop (c57e65841)
- fix getTop() (df8bdbc5c)
- Bug 1152950 - AddonWatcher should not inform the user at the first infraction. r=mossop (2cf902efe)
- Bug 1157471 - AddonWatcher console noise. r=yoric (44c67d528)
- Bug 1154239 - Rework PerformanceStats.jsm for modularity and asynchronicity. r=Mossop (4f9ba2236)
- Bug 1156264 - Activate/deactivate jank and CPOW monitoring separately (high-level). r=mossop (9fcb6ca88)
- Bug 1188616 - CPOW monitoring should use JS_Now instead of PR_IntervalNow. r=jandem (45cc23a05)
- Bug 1157870 - Performance Groups should have a unique ID (low-level). r=jandem (ead7d288e)
- Bug 1157870 - Performance Groups should have a unique ID (high-level). r=mossop (20c9fa6df)
- Bug 1157870 - Cross compilation fixup. (627c99d4c)
- Bug 1169890 - Check return values for CryptoBuffer.Assign() calls r=rbarnes (681f04148)
- Bug 1172785 - RTCCertificate implementation, r=rbarnes (c30068f20)
- Bug 1155898 - Expose fetch on JS sandbox. r=gabor, r=peterv (b965210af)
- Bug 1181262 - Disabling more code under --disable-webrtc, r=dholbert,bwc (0e93112cb)
- fix mispatch (f09b69b91)
- Bug 1172785 - RTCCertificate interfaces, r=peterv (9cbcbbffb)
- backport some profiler stuff (b7d68cafc)
- Bug 1137245 - ServiceWorkerManager should set WorkerPrivate::LoadInfo::mIndexedDBAllowed correctly. r=bent, bkelly (58ef4c286)
- Bug 1176434 - Enabling indexedDB for content JS sandboxes, r=bent (c891b518f)
- Bug 1158399 - Expose the [[DateValue]] field in Date objects only through a ClippedTime class that enforces prior TimeClip-ing on the given value. r=evilpie, r=bz, r=dhylands, r=mt, r=froydnj, r=khuey, r=baku, r=smaug Bug 1158399 - Ensure/assert that DateObject::setUTCTime never stores a non-TimeClip'd value in the reserved slot. r=evilpie (9c06bf765)
- Bug 861219 - Part 0: Make ClassSpec be able to delegate to another ClassSpec. r=bholley (85d88193e)
- Bug 861219 - Part 1: Make Date.prototype not be a Date object. r=bholley (19355939b)
- Bug 1177907 - Handle ObjectClassIs exception in date_toString. r=till (a2adb9c10)
1133 lines
32 KiB
C++
1133 lines
32 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
#include "nsIDiskSpaceWatcher.h"
|
|
#include "nsIDOMWindow.h"
|
|
#include "nsIFile.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsIScriptError.h"
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "jsapi.h"
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/CondVar.h"
|
|
#include "mozilla/ContentEvents.h"
|
|
#include "mozilla/EventDispatcher.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/dom/ContentChild.h"
|
|
#include "mozilla/dom/DOMError.h"
|
|
#include "mozilla/dom/ErrorEvent.h"
|
|
#include "mozilla/dom/ErrorEventBinding.h"
|
|
#include "mozilla/dom/PBlobChild.h"
|
|
#include "mozilla/dom/quota/OriginOrPatternString.h"
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
|
#include "mozilla/dom/quota/Utilities.h"
|
|
#include "mozilla/dom/TabContext.h"
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsGlobalWindow.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "mozilla/Logging.h"
|
|
|
|
#include "IDBEvents.h"
|
|
#include "IDBFactory.h"
|
|
#include "IDBKeyRange.h"
|
|
#include "IDBRequest.h"
|
|
#include "ProfilerHelpers.h"
|
|
#include "WorkerScope.h"
|
|
#include "WorkerPrivate.h"
|
|
|
|
// Bindings for ResolveConstructors
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
|
#include "mozilla/dom/IDBDatabaseBinding.h"
|
|
#include "mozilla/dom/IDBFactoryBinding.h"
|
|
#include "mozilla/dom/IDBIndexBinding.h"
|
|
#include "mozilla/dom/IDBKeyRangeBinding.h"
|
|
#include "mozilla/dom/IDBMutableFileBinding.h"
|
|
#include "mozilla/dom/IDBObjectStoreBinding.h"
|
|
#include "mozilla/dom/IDBOpenDBRequestBinding.h"
|
|
#include "mozilla/dom/IDBRequestBinding.h"
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
|
#include "mozilla/dom/IDBVersionChangeEventBinding.h"
|
|
|
|
#define IDB_STR "indexedDB"
|
|
|
|
// The two possible values for the data argument when receiving the disk space
|
|
// observer notification.
|
|
#define LOW_DISK_SPACE_DATA_FULL "full"
|
|
#define LOW_DISK_SPACE_DATA_FREE "free"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
namespace indexedDB {
|
|
|
|
using namespace mozilla::dom::quota;
|
|
using namespace mozilla::dom::workers;
|
|
|
|
class FileManagerInfo
|
|
{
|
|
public:
|
|
already_AddRefed<FileManager>
|
|
GetFileManager(PersistenceType aPersistenceType,
|
|
const nsAString& aName) const;
|
|
|
|
void
|
|
AddFileManager(FileManager* aFileManager);
|
|
|
|
bool
|
|
HasFileManagers() const
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
return !mPersistentStorageFileManagers.IsEmpty() ||
|
|
!mTemporaryStorageFileManagers.IsEmpty() ||
|
|
!mDefaultStorageFileManagers.IsEmpty();
|
|
}
|
|
|
|
void
|
|
InvalidateAllFileManagers() const;
|
|
|
|
void
|
|
InvalidateAndRemoveFileManagers(PersistenceType aPersistenceType);
|
|
|
|
void
|
|
InvalidateAndRemoveFileManager(PersistenceType aPersistenceType,
|
|
const nsAString& aName);
|
|
|
|
private:
|
|
nsTArray<nsRefPtr<FileManager> >&
|
|
GetArray(PersistenceType aPersistenceType);
|
|
|
|
const nsTArray<nsRefPtr<FileManager> >&
|
|
GetImmutableArray(PersistenceType aPersistenceType) const
|
|
{
|
|
return const_cast<FileManagerInfo*>(this)->GetArray(aPersistenceType);
|
|
}
|
|
|
|
nsTArray<nsRefPtr<FileManager> > mPersistentStorageFileManagers;
|
|
nsTArray<nsRefPtr<FileManager> > mTemporaryStorageFileManagers;
|
|
nsTArray<nsRefPtr<FileManager> > mDefaultStorageFileManagers;
|
|
};
|
|
|
|
namespace {
|
|
|
|
NS_DEFINE_IID(kIDBRequestIID, PRIVATE_IDBREQUEST_IID);
|
|
|
|
#define IDB_PREF_BRANCH_ROOT "dom.indexedDB."
|
|
|
|
const char kTestingPref[] = IDB_PREF_BRANCH_ROOT "testing";
|
|
const char kPrefExperimental[] = IDB_PREF_BRANCH_ROOT "experimental";
|
|
|
|
#define IDB_PREF_LOGGING_BRANCH_ROOT IDB_PREF_BRANCH_ROOT "logging."
|
|
|
|
const char kPrefLoggingEnabled[] = IDB_PREF_LOGGING_BRANCH_ROOT "enabled";
|
|
const char kPrefLoggingDetails[] = IDB_PREF_LOGGING_BRANCH_ROOT "details";
|
|
|
|
#undef IDB_PREF_LOGGING_BRANCH_ROOT
|
|
#undef IDB_PREF_BRANCH_ROOT
|
|
|
|
StaticRefPtr<IndexedDatabaseManager> gDBManager;
|
|
|
|
Atomic<bool> gInitialized(false);
|
|
Atomic<bool> gClosed(false);
|
|
Atomic<bool> gTestingMode(false);
|
|
Atomic<bool> gExperimentalFeaturesEnabled(false);
|
|
|
|
class AsyncDeleteFileRunnable final : public nsIRunnable
|
|
{
|
|
public:
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
AsyncDeleteFileRunnable(FileManager* aFileManager, int64_t aFileId);
|
|
|
|
private:
|
|
~AsyncDeleteFileRunnable() {}
|
|
|
|
nsRefPtr<FileManager> mFileManager;
|
|
int64_t mFileId;
|
|
};
|
|
|
|
class GetFileReferencesHelper final : public nsIRunnable
|
|
{
|
|
public:
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
GetFileReferencesHelper(PersistenceType aPersistenceType,
|
|
const nsACString& aOrigin,
|
|
const nsAString& aDatabaseName,
|
|
int64_t aFileId)
|
|
: mPersistenceType(aPersistenceType),
|
|
mOrigin(aOrigin),
|
|
mDatabaseName(aDatabaseName),
|
|
mFileId(aFileId),
|
|
mMutex(IndexedDatabaseManager::FileMutex()),
|
|
mCondVar(mMutex, "GetFileReferencesHelper::mCondVar"),
|
|
mMemRefCnt(-1),
|
|
mDBRefCnt(-1),
|
|
mSliceRefCnt(-1),
|
|
mResult(false),
|
|
mWaiting(true)
|
|
{ }
|
|
|
|
nsresult
|
|
DispatchAndReturnFileReferences(int32_t* aMemRefCnt,
|
|
int32_t* aDBRefCnt,
|
|
int32_t* aSliceRefCnt,
|
|
bool* aResult);
|
|
|
|
private:
|
|
~GetFileReferencesHelper() {}
|
|
|
|
PersistenceType mPersistenceType;
|
|
nsCString mOrigin;
|
|
nsString mDatabaseName;
|
|
int64_t mFileId;
|
|
|
|
mozilla::Mutex& mMutex;
|
|
mozilla::CondVar mCondVar;
|
|
int32_t mMemRefCnt;
|
|
int32_t mDBRefCnt;
|
|
int32_t mSliceRefCnt;
|
|
bool mResult;
|
|
bool mWaiting;
|
|
};
|
|
|
|
void
|
|
AtomicBoolPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aClosure);
|
|
|
|
*static_cast<Atomic<bool>*>(aClosure) = Preferences::GetBool(aPrefName);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
IndexedDatabaseManager::IndexedDatabaseManager()
|
|
: mFileMutex("IndexedDatabaseManager.mFileMutex")
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
}
|
|
|
|
IndexedDatabaseManager::~IndexedDatabaseManager()
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
}
|
|
|
|
bool IndexedDatabaseManager::sIsMainProcess = false;
|
|
bool IndexedDatabaseManager::sFullSynchronousMode = false;
|
|
|
|
PRLogModuleInfo* IndexedDatabaseManager::sLoggingModule;
|
|
|
|
Atomic<IndexedDatabaseManager::LoggingMode>
|
|
IndexedDatabaseManager::sLoggingMode(
|
|
IndexedDatabaseManager::Logging_Disabled);
|
|
|
|
mozilla::Atomic<bool> IndexedDatabaseManager::sLowDiskSpaceMode(false);
|
|
|
|
// static
|
|
IndexedDatabaseManager*
|
|
IndexedDatabaseManager::GetOrCreate()
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
if (IsClosed()) {
|
|
NS_ERROR("Calling GetOrCreate() after shutdown!");
|
|
return nullptr;
|
|
}
|
|
|
|
if (!gDBManager) {
|
|
sIsMainProcess = XRE_GetProcessType() == GeckoProcessType_Default;
|
|
|
|
if (!sLoggingModule) {
|
|
sLoggingModule = PR_NewLogModule("IndexedDB");
|
|
}
|
|
|
|
if (sIsMainProcess && Preferences::GetBool("disk_space_watcher.enabled", false)) {
|
|
// See if we're starting up in low disk space conditions.
|
|
nsCOMPtr<nsIDiskSpaceWatcher> watcher =
|
|
do_GetService(DISKSPACEWATCHER_CONTRACTID);
|
|
if (watcher) {
|
|
bool isDiskFull;
|
|
if (NS_SUCCEEDED(watcher->GetIsDiskFull(&isDiskFull))) {
|
|
sLowDiskSpaceMode = isDiskFull;
|
|
}
|
|
else {
|
|
NS_WARNING("GetIsDiskFull failed!");
|
|
}
|
|
}
|
|
else {
|
|
NS_WARNING("No disk space watcher component available!");
|
|
}
|
|
}
|
|
|
|
nsRefPtr<IndexedDatabaseManager> instance(new IndexedDatabaseManager());
|
|
|
|
nsresult rv = instance->Init();
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
if (gInitialized.exchange(true)) {
|
|
NS_ERROR("Initialized more than once?!");
|
|
}
|
|
|
|
gDBManager = instance;
|
|
|
|
ClearOnShutdown(&gDBManager);
|
|
}
|
|
|
|
return gDBManager;
|
|
}
|
|
|
|
// static
|
|
IndexedDatabaseManager*
|
|
IndexedDatabaseManager::Get()
|
|
{
|
|
// Does not return an owning reference.
|
|
return gDBManager;
|
|
}
|
|
|
|
nsresult
|
|
IndexedDatabaseManager::Init()
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
// During Init() we can't yet call IsMainProcess(), just check sIsMainProcess
|
|
// directly.
|
|
if (sIsMainProcess) {
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
NS_ENSURE_STATE(obs);
|
|
|
|
nsresult rv =
|
|
obs->AddObserver(this, DISKSPACEWATCHER_OBSERVER_TOPIC, false);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
Preferences::RegisterCallbackAndCall(AtomicBoolPrefChangedCallback,
|
|
kTestingPref,
|
|
&gTestingMode);
|
|
Preferences::RegisterCallbackAndCall(AtomicBoolPrefChangedCallback,
|
|
kPrefExperimental,
|
|
&gExperimentalFeaturesEnabled);
|
|
|
|
// By default IndexedDB uses SQLite with PRAGMA synchronous = NORMAL. This
|
|
// guarantees (unlike synchronous = OFF) atomicity and consistency, but not
|
|
// necessarily durability in situations such as power loss. This preference
|
|
// allows enabling PRAGMA synchronous = FULL on SQLite, which does guarantee
|
|
// durability, but with an extra fsync() and the corresponding performance
|
|
// hit.
|
|
sFullSynchronousMode = Preferences::GetBool("dom.indexedDB.fullSynchronous");
|
|
|
|
Preferences::RegisterCallback(LoggingModePrefChangedCallback,
|
|
kPrefLoggingDetails);
|
|
Preferences::RegisterCallbackAndCall(LoggingModePrefChangedCallback,
|
|
kPrefLoggingEnabled);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
IndexedDatabaseManager::Destroy()
|
|
{
|
|
// Setting the closed flag prevents the service from being recreated.
|
|
// Don't set it though if there's no real instance created.
|
|
if (gInitialized && gClosed.exchange(true)) {
|
|
NS_ERROR("Shutdown more than once?!");
|
|
}
|
|
|
|
Preferences::UnregisterCallback(AtomicBoolPrefChangedCallback,
|
|
kTestingPref,
|
|
&gTestingMode);
|
|
Preferences::UnregisterCallback(AtomicBoolPrefChangedCallback,
|
|
kPrefExperimental,
|
|
&gExperimentalFeaturesEnabled);
|
|
|
|
Preferences::UnregisterCallback(LoggingModePrefChangedCallback,
|
|
kPrefLoggingDetails);
|
|
Preferences::UnregisterCallback(LoggingModePrefChangedCallback,
|
|
kPrefLoggingEnabled);
|
|
|
|
delete this;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IndexedDatabaseManager::CommonPostHandleEvent(EventChainPostVisitor& aVisitor,
|
|
IDBFactory* aFactory)
|
|
{
|
|
MOZ_ASSERT(aVisitor.mDOMEvent);
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
if (aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault) {
|
|
return NS_OK;
|
|
}
|
|
|
|
Event* internalEvent = aVisitor.mDOMEvent->InternalDOMEvent();
|
|
MOZ_ASSERT(internalEvent);
|
|
|
|
if (!internalEvent->IsTrusted()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsString type;
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(internalEvent->GetType(type)));
|
|
|
|
MOZ_ASSERT(nsDependentString(kErrorEventType).EqualsLiteral("error"));
|
|
if (!type.EqualsLiteral("error")) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<EventTarget> eventTarget = internalEvent->GetTarget();
|
|
MOZ_ASSERT(eventTarget);
|
|
|
|
// Only mess with events that were originally targeted to an IDBRequest.
|
|
nsRefPtr<IDBRequest> request;
|
|
if (NS_FAILED(eventTarget->QueryInterface(kIDBRequestIID,
|
|
getter_AddRefs(request))) ||
|
|
!request) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsRefPtr<DOMError> error = request->GetErrorAfterResult();
|
|
|
|
nsString errorName;
|
|
if (error) {
|
|
error->GetName(errorName);
|
|
}
|
|
|
|
ThreadsafeAutoJSContext cx;
|
|
RootedDictionary<ErrorEventInit> init(cx);
|
|
request->GetCallerLocation(init.mFilename, &init.mLineno);
|
|
|
|
init.mMessage = errorName;
|
|
init.mCancelable = true;
|
|
init.mBubbles = true;
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
if (NS_IsMainThread()) {
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(eventTarget->GetOwnerGlobal());
|
|
if (window) {
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
|
MOZ_ASSERT(sgo);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(sgo->HandleScriptError(init, &status)))) {
|
|
status = nsEventStatus_eIgnore;
|
|
}
|
|
} else {
|
|
// We don't fire error events at any global for non-window JS on the main
|
|
// thread.
|
|
}
|
|
} else {
|
|
// Not on the main thread, must be in a worker.
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
nsRefPtr<WorkerGlobalScope> globalScope = workerPrivate->GlobalScope();
|
|
MOZ_ASSERT(globalScope);
|
|
|
|
nsRefPtr<ErrorEvent> errorEvent =
|
|
ErrorEvent::Constructor(globalScope,
|
|
nsDependentString(kErrorEventType),
|
|
init);
|
|
MOZ_ASSERT(errorEvent);
|
|
|
|
errorEvent->SetTrusted(true);
|
|
|
|
auto* target = static_cast<EventTarget*>(globalScope.get());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(
|
|
EventDispatcher::DispatchDOMEvent(target,
|
|
/* aWidgetEvent */ nullptr,
|
|
errorEvent,
|
|
/* aPresContext */ nullptr,
|
|
&status)))) {
|
|
status = nsEventStatus_eIgnore;
|
|
}
|
|
}
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsAutoCString category;
|
|
if (aFactory->IsChrome()) {
|
|
category.AssignLiteral("chrome ");
|
|
} else {
|
|
category.AssignLiteral("content ");
|
|
}
|
|
category.AppendLiteral("javascript");
|
|
|
|
// Log the error to the error console.
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
MOZ_ASSERT(consoleService);
|
|
|
|
nsCOMPtr<nsIScriptError> scriptError =
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
MOZ_ASSERT(consoleService);
|
|
|
|
if (uint64_t innerWindowID = aFactory->InnerWindowID()) {
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
|
|
scriptError->InitWithWindowID(errorName,
|
|
init.mFilename,
|
|
/* aSourceLine */ EmptyString(),
|
|
init.mLineno,
|
|
/* aColumnNumber */ 0,
|
|
nsIScriptError::errorFlag,
|
|
category,
|
|
innerWindowID)));
|
|
} else {
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
|
|
scriptError->Init(errorName,
|
|
init.mFilename,
|
|
/* aSourceLine */ EmptyString(),
|
|
init.mLineno,
|
|
/* aColumnNumber */ 0,
|
|
nsIScriptError::errorFlag,
|
|
category.get())));
|
|
}
|
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(consoleService->LogMessage(scriptError)));
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::TabContextMayAccessOrigin(const TabContext& aContext,
|
|
const nsACString& aOrigin)
|
|
{
|
|
NS_ASSERTION(!aOrigin.IsEmpty(), "Empty origin!");
|
|
|
|
// If aContext is for a browser element, it's allowed only to access other
|
|
// browser elements. But if aContext is not for a browser element, it may
|
|
// access both browser and non-browser elements.
|
|
nsAutoCString pattern;
|
|
QuotaManager::GetOriginPatternStringMaybeIgnoreBrowser(
|
|
aContext.OwnOrContainingAppId(),
|
|
aContext.IsBrowserElement(),
|
|
pattern);
|
|
|
|
return PatternMatchesOrigin(pattern, aOrigin);
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGlobal)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
|
|
"Passed object is not a global object!");
|
|
|
|
// We need to ensure that the manager has been created already here so that we
|
|
// load preferences that may control which properties are exposed.
|
|
if (NS_WARN_IF(!GetOrCreate())) {
|
|
return false;
|
|
}
|
|
|
|
if (!IDBCursorBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBCursorWithValueBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBDatabaseBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBFactoryBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBIndexBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBKeyRangeBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBMutableFileBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBObjectStoreBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBOpenDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBTransactionBinding::GetConstructorObject(aCx, aGlobal) ||
|
|
!IDBVersionChangeEventBinding::GetConstructorObject(aCx, aGlobal))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
nsRefPtr<IDBFactory> factory;
|
|
if (NS_FAILED(IDBFactory::CreateForMainThreadJS(aCx,
|
|
aGlobal,
|
|
getter_AddRefs(factory)))) {
|
|
return false;
|
|
}
|
|
|
|
MOZ_ASSERT(factory, "This should never fail for chrome!");
|
|
|
|
JS::Rooted<JS::Value> indexedDB(aCx);
|
|
js::AssertSameCompartment(aCx, aGlobal);
|
|
if (!GetOrCreateDOMReflector(aCx, factory, &indexedDB)) {
|
|
return false;
|
|
}
|
|
|
|
return JS_DefineProperty(aCx, aGlobal, IDB_STR, indexedDB, JSPROP_ENUMERATE);
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::IsClosed()
|
|
{
|
|
return gClosed;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::IsMainProcess()
|
|
{
|
|
NS_ASSERTION(gDBManager,
|
|
"IsMainProcess() called before indexedDB has been initialized!");
|
|
NS_ASSERTION((XRE_GetProcessType() == GeckoProcessType_Default) ==
|
|
sIsMainProcess, "XRE_GetProcessType changed its tune!");
|
|
return sIsMainProcess;
|
|
}
|
|
|
|
//static
|
|
bool
|
|
IndexedDatabaseManager::InLowDiskSpaceMode()
|
|
{
|
|
NS_ASSERTION(gDBManager,
|
|
"InLowDiskSpaceMode() called before indexedDB has been "
|
|
"initialized!");
|
|
return sLowDiskSpaceMode;
|
|
}
|
|
|
|
// static
|
|
IndexedDatabaseManager::LoggingMode
|
|
IndexedDatabaseManager::GetLoggingMode()
|
|
{
|
|
MOZ_ASSERT(gDBManager,
|
|
"GetLoggingMode called before IndexedDatabaseManager has been "
|
|
"initialized!");
|
|
|
|
return sLoggingMode;
|
|
}
|
|
|
|
// static
|
|
PRLogModuleInfo*
|
|
IndexedDatabaseManager::GetLoggingModule()
|
|
{
|
|
MOZ_ASSERT(gDBManager,
|
|
"GetLoggingModule called before IndexedDatabaseManager has been "
|
|
"initialized!");
|
|
|
|
return sLoggingModule;
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::InTestingMode()
|
|
{
|
|
MOZ_ASSERT(gDBManager,
|
|
"InTestingMode() called before indexedDB has been initialized!");
|
|
|
|
return gTestingMode;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::FullSynchronous()
|
|
{
|
|
MOZ_ASSERT(gDBManager,
|
|
"FullSynchronous() called before indexedDB has been initialized!");
|
|
|
|
return sFullSynchronousMode;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IndexedDatabaseManager::ExperimentalFeaturesEnabled()
|
|
{
|
|
if (NS_IsMainThread()) {
|
|
if (NS_WARN_IF(!GetOrCreate())) {
|
|
return false;
|
|
}
|
|
} else {
|
|
MOZ_ASSERT(Get(),
|
|
"ExperimentalFeaturesEnabled() called off the main thread "
|
|
"before indexedDB has been initialized!");
|
|
}
|
|
|
|
return gExperimentalFeaturesEnabled;
|
|
}
|
|
|
|
already_AddRefed<FileManager>
|
|
IndexedDatabaseManager::GetFileManager(PersistenceType aPersistenceType,
|
|
const nsACString& aOrigin,
|
|
const nsAString& aDatabaseName)
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
FileManagerInfo* info;
|
|
if (!mFileManagerInfos.Get(aOrigin, &info)) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsRefPtr<FileManager> fileManager =
|
|
info->GetFileManager(aPersistenceType, aDatabaseName);
|
|
|
|
return fileManager.forget();
|
|
}
|
|
|
|
void
|
|
IndexedDatabaseManager::AddFileManager(FileManager* aFileManager)
|
|
{
|
|
AssertIsOnIOThread();
|
|
NS_ASSERTION(aFileManager, "Null file manager!");
|
|
|
|
FileManagerInfo* info;
|
|
if (!mFileManagerInfos.Get(aFileManager->Origin(), &info)) {
|
|
info = new FileManagerInfo();
|
|
mFileManagerInfos.Put(aFileManager->Origin(), info);
|
|
}
|
|
|
|
info->AddFileManager(aFileManager);
|
|
}
|
|
|
|
void
|
|
IndexedDatabaseManager::InvalidateAllFileManagers()
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
class MOZ_STACK_CLASS Helper final
|
|
{
|
|
public:
|
|
static PLDHashOperator
|
|
Enumerate(const nsACString& aKey,
|
|
FileManagerInfo* aValue,
|
|
void* aUserArg)
|
|
{
|
|
AssertIsOnIOThread();
|
|
MOZ_ASSERT(!aKey.IsEmpty());
|
|
MOZ_ASSERT(aValue);
|
|
|
|
aValue->InvalidateAllFileManagers();
|
|
return PL_DHASH_NEXT;
|
|
}
|
|
};
|
|
|
|
mFileManagerInfos.EnumerateRead(Helper::Enumerate, nullptr);
|
|
mFileManagerInfos.Clear();
|
|
}
|
|
|
|
void
|
|
IndexedDatabaseManager::InvalidateFileManagers(
|
|
PersistenceType aPersistenceType,
|
|
const nsACString& aOrigin)
|
|
{
|
|
AssertIsOnIOThread();
|
|
MOZ_ASSERT(!aOrigin.IsEmpty());
|
|
|
|
FileManagerInfo* info;
|
|
if (!mFileManagerInfos.Get(aOrigin, &info)) {
|
|
return;
|
|
}
|
|
|
|
info->InvalidateAndRemoveFileManagers(aPersistenceType);
|
|
|
|
if (!info->HasFileManagers()) {
|
|
mFileManagerInfos.Remove(aOrigin);
|
|
}
|
|
}
|
|
|
|
void
|
|
IndexedDatabaseManager::InvalidateFileManager(PersistenceType aPersistenceType,
|
|
const nsACString& aOrigin,
|
|
const nsAString& aDatabaseName)
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
FileManagerInfo* info;
|
|
if (!mFileManagerInfos.Get(aOrigin, &info)) {
|
|
return;
|
|
}
|
|
|
|
info->InvalidateAndRemoveFileManager(aPersistenceType, aDatabaseName);
|
|
|
|
if (!info->HasFileManagers()) {
|
|
mFileManagerInfos.Remove(aOrigin);
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
IndexedDatabaseManager::AsyncDeleteFile(FileManager* aFileManager,
|
|
int64_t aFileId)
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ENSURE_ARG_POINTER(aFileManager);
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
// See if we're currently clearing the storages for this origin. If so then
|
|
// we pretend that we've already deleted everything.
|
|
if (quotaManager->IsClearOriginPending(
|
|
aFileManager->Origin(),
|
|
Nullable<PersistenceType>(aFileManager->Type()))) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsRefPtr<AsyncDeleteFileRunnable> runnable =
|
|
new AsyncDeleteFileRunnable(aFileManager, aFileId);
|
|
|
|
nsresult rv =
|
|
quotaManager->IOThread()->Dispatch(runnable, NS_DISPATCH_NORMAL);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
IndexedDatabaseManager::BlockAndGetFileReferences(
|
|
PersistenceType aPersistenceType,
|
|
const nsACString& aOrigin,
|
|
const nsAString& aDatabaseName,
|
|
int64_t aFileId,
|
|
int32_t* aRefCnt,
|
|
int32_t* aDBRefCnt,
|
|
int32_t* aSliceRefCnt,
|
|
bool* aResult)
|
|
{
|
|
if (NS_WARN_IF(!InTestingMode())) {
|
|
return NS_ERROR_UNEXPECTED;
|
|
}
|
|
|
|
if (IsMainProcess()) {
|
|
nsRefPtr<GetFileReferencesHelper> helper =
|
|
new GetFileReferencesHelper(aPersistenceType, aOrigin, aDatabaseName,
|
|
aFileId);
|
|
|
|
nsresult rv =
|
|
helper->DispatchAndReturnFileReferences(aRefCnt, aDBRefCnt,
|
|
aSliceRefCnt, aResult);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
} else {
|
|
ContentChild* contentChild = ContentChild::GetSingleton();
|
|
if (NS_WARN_IF(!contentChild)) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!contentChild->SendGetFileReferences(aPersistenceType,
|
|
nsCString(aOrigin),
|
|
nsString(aDatabaseName),
|
|
aFileId,
|
|
aRefCnt,
|
|
aDBRefCnt,
|
|
aSliceRefCnt,
|
|
aResult)) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
void
|
|
IndexedDatabaseManager::LoggingModePrefChangedCallback(
|
|
const char* /* aPrefName */,
|
|
void* /* aClosure */)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!Preferences::GetBool(kPrefLoggingEnabled)) {
|
|
sLoggingMode = Logging_Disabled;
|
|
return;
|
|
}
|
|
|
|
bool useProfiler =
|
|
#if defined(DEBUG) || defined(MOZ_ENABLE_PROFILER_SPS)
|
|
Preferences::GetBool(kPrefLoggingProfiler);
|
|
#if !defined(MOZ_ENABLE_PROFILER_SPS)
|
|
if (useProfiler) {
|
|
NS_WARNING("IndexedDB cannot create profiler marks because this build does "
|
|
"not have profiler extensions enabled!");
|
|
useProfiler = false;
|
|
}
|
|
#endif
|
|
#else
|
|
false;
|
|
#endif
|
|
|
|
const bool logDetails = Preferences::GetBool(kPrefLoggingDetails);
|
|
|
|
if (useProfiler) {
|
|
sLoggingMode = logDetails ?
|
|
Logging_DetailedProfilerMarks :
|
|
Logging_ConciseProfilerMarks;
|
|
} else {
|
|
sLoggingMode = logDetails ? Logging_Detailed : Logging_Concise;
|
|
}
|
|
}
|
|
|
|
NS_IMPL_ADDREF(IndexedDatabaseManager)
|
|
NS_IMPL_RELEASE_WITH_DESTROY(IndexedDatabaseManager, Destroy())
|
|
NS_IMPL_QUERY_INTERFACE(IndexedDatabaseManager, nsIObserver)
|
|
|
|
NS_IMETHODIMP
|
|
IndexedDatabaseManager::Observe(nsISupports* aSubject, const char* aTopic,
|
|
const char16_t* aData)
|
|
{
|
|
NS_ASSERTION(IsMainProcess(), "Wrong process!");
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
if (!strcmp(aTopic, DISKSPACEWATCHER_OBSERVER_TOPIC)) {
|
|
NS_ASSERTION(aData, "No data?!");
|
|
|
|
const nsDependentString data(aData);
|
|
|
|
if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FULL)) {
|
|
sLowDiskSpaceMode = true;
|
|
}
|
|
else if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FREE)) {
|
|
sLowDiskSpaceMode = false;
|
|
}
|
|
else {
|
|
NS_NOTREACHED("Unknown data value!");
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_NOTREACHED("Unknown topic!");
|
|
return NS_ERROR_UNEXPECTED;
|
|
}
|
|
|
|
already_AddRefed<FileManager>
|
|
FileManagerInfo::GetFileManager(PersistenceType aPersistenceType,
|
|
const nsAString& aName) const
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
const nsTArray<nsRefPtr<FileManager> >& managers =
|
|
GetImmutableArray(aPersistenceType);
|
|
|
|
for (uint32_t i = 0; i < managers.Length(); i++) {
|
|
const nsRefPtr<FileManager>& fileManager = managers[i];
|
|
|
|
if (fileManager->DatabaseName() == aName) {
|
|
nsRefPtr<FileManager> result = fileManager;
|
|
return result.forget();
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void
|
|
FileManagerInfo::AddFileManager(FileManager* aFileManager)
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
nsTArray<nsRefPtr<FileManager> >& managers = GetArray(aFileManager->Type());
|
|
|
|
NS_ASSERTION(!managers.Contains(aFileManager), "Adding more than once?!");
|
|
|
|
managers.AppendElement(aFileManager);
|
|
}
|
|
|
|
void
|
|
FileManagerInfo::InvalidateAllFileManagers() const
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < mPersistentStorageFileManagers.Length(); i++) {
|
|
mPersistentStorageFileManagers[i]->Invalidate();
|
|
}
|
|
|
|
for (i = 0; i < mTemporaryStorageFileManagers.Length(); i++) {
|
|
mTemporaryStorageFileManagers[i]->Invalidate();
|
|
}
|
|
|
|
for (i = 0; i < mDefaultStorageFileManagers.Length(); i++) {
|
|
mDefaultStorageFileManagers[i]->Invalidate();
|
|
}
|
|
}
|
|
|
|
void
|
|
FileManagerInfo::InvalidateAndRemoveFileManagers(
|
|
PersistenceType aPersistenceType)
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
nsTArray<nsRefPtr<FileManager > >& managers = GetArray(aPersistenceType);
|
|
|
|
for (uint32_t i = 0; i < managers.Length(); i++) {
|
|
managers[i]->Invalidate();
|
|
}
|
|
|
|
managers.Clear();
|
|
}
|
|
|
|
void
|
|
FileManagerInfo::InvalidateAndRemoveFileManager(
|
|
PersistenceType aPersistenceType,
|
|
const nsAString& aName)
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
nsTArray<nsRefPtr<FileManager > >& managers = GetArray(aPersistenceType);
|
|
|
|
for (uint32_t i = 0; i < managers.Length(); i++) {
|
|
nsRefPtr<FileManager>& fileManager = managers[i];
|
|
if (fileManager->DatabaseName() == aName) {
|
|
fileManager->Invalidate();
|
|
managers.RemoveElementAt(i);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
nsTArray<nsRefPtr<FileManager> >&
|
|
FileManagerInfo::GetArray(PersistenceType aPersistenceType)
|
|
{
|
|
switch (aPersistenceType) {
|
|
case PERSISTENCE_TYPE_PERSISTENT:
|
|
return mPersistentStorageFileManagers;
|
|
case PERSISTENCE_TYPE_TEMPORARY:
|
|
return mTemporaryStorageFileManagers;
|
|
case PERSISTENCE_TYPE_DEFAULT:
|
|
return mDefaultStorageFileManagers;
|
|
|
|
case PERSISTENCE_TYPE_INVALID:
|
|
default:
|
|
MOZ_CRASH("Bad storage type value!");
|
|
}
|
|
}
|
|
|
|
AsyncDeleteFileRunnable::AsyncDeleteFileRunnable(FileManager* aFileManager,
|
|
int64_t aFileId)
|
|
: mFileManager(aFileManager), mFileId(aFileId)
|
|
{
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(AsyncDeleteFileRunnable,
|
|
nsIRunnable)
|
|
|
|
NS_IMETHODIMP
|
|
AsyncDeleteFileRunnable::Run()
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
nsCOMPtr<nsIFile> directory = mFileManager->GetDirectory();
|
|
NS_ENSURE_TRUE(directory, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIFile> file = mFileManager->GetFileForId(directory, mFileId);
|
|
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
|
|
|
nsresult rv;
|
|
int64_t fileSize;
|
|
|
|
if (mFileManager->EnforcingQuota()) {
|
|
rv = file->GetFileSize(&fileSize);
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
}
|
|
|
|
rv = file->Remove(false);
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
if (mFileManager->EnforcingQuota()) {
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
quotaManager->DecreaseUsageForOrigin(mFileManager->Type(),
|
|
mFileManager->Group(),
|
|
mFileManager->Origin(), fileSize);
|
|
}
|
|
|
|
directory = mFileManager->GetJournalDirectory();
|
|
NS_ENSURE_TRUE(directory, NS_ERROR_FAILURE);
|
|
|
|
file = mFileManager->GetFileForId(directory, mFileId);
|
|
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
|
|
|
rv = file->Remove(false);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
GetFileReferencesHelper::DispatchAndReturnFileReferences(int32_t* aMemRefCnt,
|
|
int32_t* aDBRefCnt,
|
|
int32_t* aSliceRefCnt,
|
|
bool* aResult)
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
nsresult rv =
|
|
quotaManager->IOThread()->Dispatch(this, NS_DISPATCH_NORMAL);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mozilla::MutexAutoLock autolock(mMutex);
|
|
while (mWaiting) {
|
|
mCondVar.Wait();
|
|
}
|
|
|
|
*aMemRefCnt = mMemRefCnt;
|
|
*aDBRefCnt = mDBRefCnt;
|
|
*aSliceRefCnt = mSliceRefCnt;
|
|
*aResult = mResult;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(GetFileReferencesHelper,
|
|
nsIRunnable)
|
|
|
|
NS_IMETHODIMP
|
|
GetFileReferencesHelper::Run()
|
|
{
|
|
AssertIsOnIOThread();
|
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
NS_ASSERTION(mgr, "This should never fail!");
|
|
|
|
nsRefPtr<FileManager> fileManager =
|
|
mgr->GetFileManager(mPersistenceType, mOrigin, mDatabaseName);
|
|
|
|
if (fileManager) {
|
|
nsRefPtr<FileInfo> fileInfo = fileManager->GetFileInfo(mFileId);
|
|
|
|
if (fileInfo) {
|
|
fileInfo->GetReferences(&mMemRefCnt, &mDBRefCnt, &mSliceRefCnt);
|
|
|
|
if (mMemRefCnt != -1) {
|
|
// We added an extra temp ref, so account for that accordingly.
|
|
mMemRefCnt--;
|
|
}
|
|
|
|
mResult = true;
|
|
}
|
|
}
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
NS_ASSERTION(mWaiting, "Huh?!");
|
|
|
|
mWaiting = false;
|
|
mCondVar.Notify();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace indexedDB
|
|
} // namespace dom
|
|
} // namespace mozilla
|