mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
Issue #1263 - Part 1: Remove DiskSpaceWatcher
This commit is contained in:
parent
fe92ae641a
commit
92b01bf08a
20 changed files with 3 additions and 537 deletions
|
|
@ -4427,18 +4427,6 @@ CreateStorageConnection(nsIFile* aDBFile,
|
|||
nsresult rv;
|
||||
bool exists;
|
||||
|
||||
if (IndexedDatabaseManager::InLowDiskSpaceMode()) {
|
||||
rv = aDBFile->Exists(&exists);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
NS_WARNING("Refusing to create database because disk space is low!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFileURL> dbFileUrl;
|
||||
rv = GetDatabaseFileURL(aDBFile,
|
||||
aPersistenceType,
|
||||
|
|
@ -19103,23 +19091,6 @@ DatabaseMaintenance::DetermineMaintenanceAction(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool lowDiskSpace = IndexedDatabaseManager::InLowDiskSpaceMode();
|
||||
|
||||
if (QuotaManager::IsRunningXPCShellTests()) {
|
||||
// If we're running XPCShell then we want to test both the low disk space
|
||||
// and normal disk space code paths so pick semi-randomly based on the
|
||||
// current time.
|
||||
lowDiskSpace = ((PR_Now() / PR_USEC_PER_MSEC) % 2) == 0;
|
||||
}
|
||||
|
||||
// If we're low on disk space then the best we can hope for is that an
|
||||
// incremental vacuum might free some space. That is a journaled operation so
|
||||
// it may not be possible even then.
|
||||
if (lowDiskSpace) {
|
||||
*aMaintenanceAction = MaintenanceAction::IncrementalVacuum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This method shouldn't make any permanent changes to the database, so make
|
||||
// sure everything gets rolled back when we leave.
|
||||
mozStorageTransaction transaction(aConnection,
|
||||
|
|
@ -24233,11 +24204,6 @@ CreateFileOp::DoDatabaseWork()
|
|||
"CreateFileOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
NS_WARNING("Refusing to create file because disk space is low!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(QuotaManager::IsShuttingDown()) || !OperationMayProceed()) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
|
|
@ -24378,10 +24344,6 @@ CreateObjectStoreOp::DoDatabaseWork(DatabaseConnection* aConnection)
|
|||
"CreateObjectStoreOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
// Make sure that we're not creating an object store with the same name as
|
||||
|
|
@ -24705,10 +24667,6 @@ RenameObjectStoreOp::DoDatabaseWork(DatabaseConnection* aConnection)
|
|||
"RenameObjectStoreOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
// Make sure that we're not renaming an object store with the same name as
|
||||
|
|
@ -24798,7 +24756,6 @@ CreateIndexOp::InsertDataFromObjectStore(DatabaseConnection* aConnection)
|
|||
{
|
||||
MOZ_ASSERT(aConnection);
|
||||
aConnection->AssertIsOnConnectionThread();
|
||||
MOZ_ASSERT(!IndexedDatabaseManager::InLowDiskSpaceMode());
|
||||
MOZ_ASSERT(mMaybeUniqueIndexTable);
|
||||
|
||||
PROFILER_LABEL("IndexedDB",
|
||||
|
|
@ -24849,7 +24806,6 @@ CreateIndexOp::InsertDataFromObjectStoreInternal(
|
|||
{
|
||||
MOZ_ASSERT(aConnection);
|
||||
aConnection->AssertIsOnConnectionThread();
|
||||
MOZ_ASSERT(!IndexedDatabaseManager::InLowDiskSpaceMode());
|
||||
MOZ_ASSERT(mMaybeUniqueIndexTable);
|
||||
|
||||
DebugOnly<void*> storageConnection = aConnection->GetStorageConnection();
|
||||
|
|
@ -24926,10 +24882,6 @@ CreateIndexOp::DoDatabaseWork(DatabaseConnection* aConnection)
|
|||
"CreateIndexOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
// Make sure that we're not creating an index with the same name and object
|
||||
|
|
@ -25806,10 +25758,6 @@ RenameIndexOp::DoDatabaseWork(DatabaseConnection* aConnection)
|
|||
"RenameIndexOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
// Make sure that we're not renaming an index with the same name as another
|
||||
|
|
@ -26294,10 +26242,6 @@ ObjectStoreAddOrPutRequestOp::DoDatabaseWork(DatabaseConnection* aConnection)
|
|||
"ObjectStoreAddOrPutRequestOp::DoDatabaseWork",
|
||||
js::ProfileEntry::Category::STORAGE);
|
||||
|
||||
if (NS_WARN_IF(IndexedDatabaseManager::InLowDiskSpaceMode())) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
||||
}
|
||||
|
||||
DatabaseConnection::AutoSavepoint autoSave;
|
||||
nsresult rv = autoSave.Start(Transaction());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@
|
|||
|
||||
#include "chrome/common/ipc_channel.h" // for IPC::Channel::kMaximumMessageSize
|
||||
#include "nsIConsoleService.h"
|
||||
#include "nsIDiskSpaceWatcher.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
|
|
@ -64,11 +62,6 @@
|
|||
|
||||
#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 {
|
||||
|
|
@ -313,8 +306,6 @@ Atomic<IndexedDatabaseManager::LoggingMode>
|
|||
IndexedDatabaseManager::sLoggingMode(
|
||||
IndexedDatabaseManager::Logging_Disabled);
|
||||
|
||||
mozilla::Atomic<bool> IndexedDatabaseManager::sLowDiskSpaceMode(false);
|
||||
|
||||
// static
|
||||
IndexedDatabaseManager*
|
||||
IndexedDatabaseManager::GetOrCreate()
|
||||
|
|
@ -329,24 +320,6 @@ IndexedDatabaseManager::GetOrCreate()
|
|||
if (!gDBManager) {
|
||||
sIsMainProcess = XRE_IsParentProcess();
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<IndexedDatabaseManager> instance(new IndexedDatabaseManager());
|
||||
|
||||
nsresult rv = instance->Init();
|
||||
|
|
@ -380,13 +353,6 @@ IndexedDatabaseManager::Init()
|
|||
// 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);
|
||||
|
||||
mDeleteTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
||||
NS_ENSURE_STATE(mDeleteTimer);
|
||||
|
||||
|
|
@ -680,16 +646,6 @@ IndexedDatabaseManager::IsMainProcess()
|
|||
return sIsMainProcess;
|
||||
}
|
||||
|
||||
//static
|
||||
bool
|
||||
IndexedDatabaseManager::InLowDiskSpaceMode()
|
||||
{
|
||||
NS_ASSERTION(gDBManager,
|
||||
"InLowDiskSpaceMode() called before indexedDB has been "
|
||||
"initialized!");
|
||||
return sLowDiskSpaceMode;
|
||||
}
|
||||
|
||||
// static
|
||||
IndexedDatabaseManager::LoggingMode
|
||||
IndexedDatabaseManager::GetLoggingMode()
|
||||
|
|
@ -1087,36 +1043,7 @@ IndexedDatabaseManager::GetLocale()
|
|||
|
||||
NS_IMPL_ADDREF(IndexedDatabaseManager)
|
||||
NS_IMPL_RELEASE_WITH_DESTROY(IndexedDatabaseManager, Destroy())
|
||||
NS_IMPL_QUERY_INTERFACE(IndexedDatabaseManager, nsIObserver, nsITimerCallback)
|
||||
|
||||
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;
|
||||
}
|
||||
NS_IMPL_QUERY_INTERFACE(IndexedDatabaseManager, nsITimerCallback)
|
||||
|
||||
NS_IMETHODIMP
|
||||
IndexedDatabaseManager::Notify(nsITimer* aTimer)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
#ifndef mozilla_dom_indexeddatabasemanager_h__
|
||||
#define mozilla_dom_indexeddatabasemanager_h__
|
||||
|
||||
#include "nsIObserver.h"
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/dom/quota/PersistenceType.h"
|
||||
|
|
@ -43,8 +41,7 @@ class FileManagerInfo;
|
|||
} // namespace indexedDB
|
||||
|
||||
class IndexedDatabaseManager final
|
||||
: public nsIObserver
|
||||
, public nsITimerCallback
|
||||
: public nsITimerCallback
|
||||
{
|
||||
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
||||
typedef mozilla::dom::quota::QuotaManager QuotaManager;
|
||||
|
|
@ -62,7 +59,6 @@ public:
|
|||
};
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
// Returns a non-owning reference.
|
||||
|
|
@ -86,16 +82,6 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
InLowDiskSpaceMode()
|
||||
#ifdef DEBUG
|
||||
;
|
||||
#else
|
||||
{
|
||||
return !!sLowDiskSpaceMode;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
InTestingMode();
|
||||
|
||||
|
|
@ -244,7 +230,6 @@ private:
|
|||
static bool sFullSynchronousMode;
|
||||
static LazyLogModule sLoggingModule;
|
||||
static Atomic<LoggingMode> sLoggingMode;
|
||||
static mozilla::Atomic<bool> sLowDiskSpaceMode;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
|||
|
|
@ -205,11 +205,6 @@ DOMStorageCache::ProcessUsageDelta(const DOMStorage* aStorage, int64_t aDelta)
|
|||
bool
|
||||
DOMStorageCache::ProcessUsageDelta(uint32_t aGetDataSetIndex, const int64_t aDelta)
|
||||
{
|
||||
// Check if we are in a low disk space situation
|
||||
if (aDelta > 0 && mManager && mManager->IsLowDiskSpace()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check limit per this origin
|
||||
Data& data = mData[aGetDataSetIndex];
|
||||
uint64_t newOriginUsage = data.mOriginQuotaUsage + aDelta;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsIDiskSpaceWatcher.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
|
@ -321,22 +320,6 @@ private:
|
|||
mozilla::Unused << mParent->SendOriginsHavingData(scopes);
|
||||
}
|
||||
|
||||
// We need to check if the device is in a low disk space situation, so
|
||||
// we can forbid in that case any write in localStorage.
|
||||
nsCOMPtr<nsIDiskSpaceWatcher> diskSpaceWatcher =
|
||||
do_GetService("@mozilla.org/toolkit/disk-space-watcher;1");
|
||||
if (!diskSpaceWatcher) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool lowDiskSpace = false;
|
||||
diskSpaceWatcher->GetIsDiskFull(&lowDiskSpace);
|
||||
|
||||
if (lowDiskSpace) {
|
||||
mozilla::Unused << mParent->SendObserve(
|
||||
nsDependentCString("low-disk-space"), EmptyString(), EmptyCString());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ NS_IMPL_ISUPPORTS(DOMStorageManager,
|
|||
DOMStorageManager::DOMStorageManager(DOMStorage::StorageType aType)
|
||||
: mCaches(8)
|
||||
, mType(aType)
|
||||
, mLowDiskSpace(false)
|
||||
{
|
||||
DOMStorageObserver* observer = DOMStorageObserver::Self();
|
||||
NS_ASSERTION(observer, "No DOMStorageObserver, cannot observe private data delete notifications!");
|
||||
|
|
@ -566,22 +565,6 @@ DOMStorageManager::Observe(const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "low-disk-space")) {
|
||||
if (mType == LocalStorage) {
|
||||
mLowDiskSpace = true;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "no-low-disk-space")) {
|
||||
if (mType == LocalStorage) {
|
||||
mLowDiskSpace = false;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DOM_STORAGE_TESTS
|
||||
if (!strcmp(aTopic, "test-reload")) {
|
||||
if (mType != LocalStorage) {
|
||||
|
|
|
|||
|
|
@ -102,12 +102,6 @@ private:
|
|||
|
||||
const DOMStorage::StorageType mType;
|
||||
|
||||
// If mLowDiskSpace is true it indicates a low device storage situation and
|
||||
// so no localStorage writes are allowed. sessionStorage writes are still
|
||||
// allowed.
|
||||
bool mLowDiskSpace;
|
||||
bool IsLowDiskSpace() const { return mLowDiskSpace; };
|
||||
|
||||
void ClearCaches(uint32_t aUnloadFlags,
|
||||
const OriginAttributesPattern& aPattern,
|
||||
const nsACString& aKeyPrefix);
|
||||
|
|
|
|||
|
|
@ -70,9 +70,6 @@ DOMStorageObserver::Init()
|
|||
obs->AddObserver(sSelf, "profile-before-change", true);
|
||||
obs->AddObserver(sSelf, "xpcom-shutdown", true);
|
||||
|
||||
// Observe low device storage notifications.
|
||||
obs->AddObserver(sSelf, "disk-space-watcher", true);
|
||||
|
||||
#ifdef DOM_STORAGE_TESTS
|
||||
// Testing
|
||||
obs->AddObserver(sSelf, "domstorage-test-flush-force", true);
|
||||
|
|
@ -313,16 +310,6 @@ DOMStorageObserver::Observe(nsISupports* aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "disk-space-watcher")) {
|
||||
if (NS_LITERAL_STRING("full").Equals(aData)) {
|
||||
Notify("low-disk-space");
|
||||
} else if (NS_LITERAL_STRING("free").Equals(aData)) {
|
||||
Notify("no-low-disk-space");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DOM_STORAGE_TESTS
|
||||
if (!strcmp(aTopic, "domstorage-test-flush-force")) {
|
||||
DOMStorageDBBridge* db = DOMStorageCache::GetDatabase();
|
||||
|
|
|
|||
16
hal/Hal.cpp
16
hal/Hal.cpp
|
|
@ -855,22 +855,6 @@ void FactoryReset(mozilla::dom::FactoryResetReason& aReason)
|
|||
PROXY_IF_SANDBOXED(FactoryReset(aReason));
|
||||
}
|
||||
|
||||
void
|
||||
StartDiskSpaceWatcher()
|
||||
{
|
||||
AssertMainProcess();
|
||||
AssertMainThread();
|
||||
PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
|
||||
}
|
||||
|
||||
void
|
||||
StopDiskSpaceWatcher()
|
||||
{
|
||||
AssertMainProcess();
|
||||
AssertMainThread();
|
||||
PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
|
||||
}
|
||||
|
||||
uint32_t
|
||||
GetTotalSystemMemory()
|
||||
{
|
||||
|
|
|
|||
14
hal/Hal.h
14
hal/Hal.h
|
|
@ -476,20 +476,6 @@ void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
|
|||
*/
|
||||
void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
|
||||
|
||||
/**
|
||||
* Start monitoring disk space for low space situations.
|
||||
*
|
||||
* This API is currently only allowed to be used from the main process.
|
||||
*/
|
||||
void StartDiskSpaceWatcher();
|
||||
|
||||
/**
|
||||
* Stop monitoring disk space for low space situations.
|
||||
*
|
||||
* This API is currently only allowed to be used from the main process.
|
||||
*/
|
||||
void StopDiskSpaceWatcher();
|
||||
|
||||
/**
|
||||
* Get total system memory of device being run on in bytes.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
/* 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/. */
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
void
|
||||
StartDiskSpaceWatcher()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
StopDiskSpaceWatcher()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace hal_impl
|
||||
} // namespace mozilla
|
||||
|
|
@ -107,7 +107,6 @@ else:
|
|||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'fallback/FallbackDiskSpaceWatcher.cpp',
|
||||
'fallback/FallbackFactoryReset.cpp',
|
||||
'fallback/FallbackProcessPriority.cpp',
|
||||
'fallback/FallbackScreenPower.cpp',
|
||||
|
|
|
|||
|
|
@ -352,18 +352,6 @@ FactoryReset(FactoryResetReason& aReason)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
StartDiskSpaceWatcher()
|
||||
{
|
||||
NS_RUNTIMEABORT("StartDiskSpaceWatcher() can't be called from sandboxed contexts.");
|
||||
}
|
||||
|
||||
void
|
||||
StopDiskSpaceWatcher()
|
||||
{
|
||||
NS_RUNTIMEABORT("StopDiskSpaceWatcher() can't be called from sandboxed contexts.");
|
||||
}
|
||||
|
||||
bool IsHeadphoneEventFromInputDev()
|
||||
{
|
||||
NS_RUNTIMEABORT("IsHeadphoneEventFromInputDev() cannot be called from sandboxed contexts.");
|
||||
|
|
|
|||
|
|
@ -1,158 +0,0 @@
|
|||
/* 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 "DiskSpaceWatcher.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/ModuleUtils.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#define NS_DISKSPACEWATCHER_CID \
|
||||
{ 0xab218518, 0xf197, 0x4fb4, { 0x8b, 0x0f, 0x8b, 0xb3, 0x4d, 0xf2, 0x4b, 0xf4 } }
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
StaticRefPtr<DiskSpaceWatcher> gDiskSpaceWatcher;
|
||||
|
||||
NS_IMPL_ISUPPORTS(DiskSpaceWatcher, nsIDiskSpaceWatcher, nsIObserver)
|
||||
|
||||
uint64_t DiskSpaceWatcher::sFreeSpace = 0;
|
||||
bool DiskSpaceWatcher::sIsDiskFull = false;
|
||||
|
||||
DiskSpaceWatcher::DiskSpaceWatcher()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!gDiskSpaceWatcher);
|
||||
}
|
||||
|
||||
DiskSpaceWatcher::~DiskSpaceWatcher()
|
||||
{
|
||||
MOZ_ASSERT(!gDiskSpaceWatcher);
|
||||
}
|
||||
|
||||
already_AddRefed<DiskSpaceWatcher>
|
||||
DiskSpaceWatcher::FactoryCreate()
|
||||
{
|
||||
if (!XRE_IsParentProcess()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!Preferences::GetBool("disk_space_watcher.enabled", false)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!gDiskSpaceWatcher) {
|
||||
gDiskSpaceWatcher = new DiskSpaceWatcher();
|
||||
ClearOnShutdown(&gDiskSpaceWatcher);
|
||||
}
|
||||
|
||||
RefPtr<DiskSpaceWatcher> service = gDiskSpaceWatcher.get();
|
||||
return service.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DiskSpaceWatcher::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!strcmp(aTopic, "profile-after-change")) {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
observerService->AddObserver(this, "profile-before-change", false);
|
||||
mozilla::hal::StartDiskSpaceWatcher();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "profile-before-change")) {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
observerService->RemoveObserver(this, "profile-before-change");
|
||||
mozilla::hal::StopDiskSpaceWatcher();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "DiskSpaceWatcher got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DiskSpaceWatcher::GetIsDiskFull(bool* aIsDiskFull)
|
||||
{
|
||||
*aIsDiskFull = sIsDiskFull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// GetFreeSpace is a macro on windows, and that messes up with the c++
|
||||
// compiler.
|
||||
#ifdef XP_WIN
|
||||
#undef GetFreeSpace
|
||||
#endif
|
||||
NS_IMETHODIMP DiskSpaceWatcher::GetFreeSpace(uint64_t* aFreeSpace)
|
||||
{
|
||||
*aFreeSpace = sFreeSpace;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
void DiskSpaceWatcher::UpdateState(bool aIsDiskFull, uint64_t aFreeSpace)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (!gDiskSpaceWatcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
|
||||
sIsDiskFull = aIsDiskFull;
|
||||
sFreeSpace = aFreeSpace;
|
||||
|
||||
if (!observerService) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char16_t stateFull[] = { 'f', 'u', 'l', 'l', 0 };
|
||||
const char16_t stateFree[] = { 'f', 'r', 'e', 'e', 0 };
|
||||
|
||||
nsCOMPtr<nsISupports> subject;
|
||||
CallQueryInterface(gDiskSpaceWatcher.get(), getter_AddRefs(subject));
|
||||
MOZ_ASSERT(subject);
|
||||
observerService->NotifyObservers(subject,
|
||||
DISKSPACEWATCHER_OBSERVER_TOPIC,
|
||||
sIsDiskFull ? stateFull : stateFree);
|
||||
return;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(DiskSpaceWatcher,
|
||||
DiskSpaceWatcher::FactoryCreate)
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_DISKSPACEWATCHER_CID);
|
||||
|
||||
static const mozilla::Module::CIDEntry kDiskSpaceWatcherCIDs[] = {
|
||||
{ &kNS_DISKSPACEWATCHER_CID, false, nullptr, DiskSpaceWatcherConstructor },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module::ContractIDEntry kDiskSpaceWatcherContracts[] = {
|
||||
{ "@mozilla.org/toolkit/disk-space-watcher;1", &kNS_DISKSPACEWATCHER_CID },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module::CategoryEntry kDiskSpaceWatcherCategories[] = {
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module kDiskSpaceWatcherModule = {
|
||||
mozilla::Module::kVersion,
|
||||
kDiskSpaceWatcherCIDs,
|
||||
kDiskSpaceWatcherContracts,
|
||||
kDiskSpaceWatcherCategories
|
||||
};
|
||||
|
||||
NSMODULE_DEFN(DiskSpaceWatcherModule) = &kDiskSpaceWatcherModule;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* 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 __DISKSPACEWATCHER_H__
|
||||
|
||||
#include "nsIDiskSpaceWatcher.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class DiskSpaceWatcher final : public nsIDiskSpaceWatcher,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDISKSPACEWATCHER
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static already_AddRefed<DiskSpaceWatcher>
|
||||
FactoryCreate();
|
||||
|
||||
static void UpdateState(bool aIsDiskFull, uint64_t aFreeSpace);
|
||||
|
||||
private:
|
||||
DiskSpaceWatcher();
|
||||
~DiskSpaceWatcher();
|
||||
|
||||
static uint64_t sFreeSpace;
|
||||
static bool sIsDiskFull;
|
||||
};
|
||||
|
||||
#endif // __DISKSPACEWATCHER_H__
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIDiskSpaceWatcher.idl',
|
||||
]
|
||||
|
||||
EXPORTS += [
|
||||
'DiskSpaceWatcher.h'
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'diskspacewatcher'
|
||||
|
||||
SOURCES = [
|
||||
'DiskSpaceWatcher.cpp',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* 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 "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
#ifdef XP_WIN
|
||||
#undef GetFreeSpace
|
||||
#endif
|
||||
%}
|
||||
|
||||
[scriptable, uuid(3aceba74-2ed5-4e99-8fe4-06e90e2b8ef0)]
|
||||
interface nsIDiskSpaceWatcher : nsISupports
|
||||
{
|
||||
readonly attribute bool isDiskFull; // True if we are low on disk space.
|
||||
readonly attribute unsigned long long freeSpace; // The free space currently available.
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define DISKSPACEWATCHER_CONTRACTID "@mozilla.org/toolkit/disk-space-watcher;1"
|
||||
|
||||
// The data for this notification will be either 'free' or 'full'.
|
||||
#define DISKSPACEWATCHER_OBSERVER_TOPIC "disk-space-watcher"
|
||||
%}
|
||||
|
|
@ -24,7 +24,6 @@ DIRS += [
|
|||
'contextualidentity',
|
||||
'cookie',
|
||||
'crashmonitor',
|
||||
'diskspacewatcher',
|
||||
'downloads',
|
||||
'exthelper',
|
||||
'filewatcher',
|
||||
|
|
|
|||
|
|
@ -375,7 +375,6 @@ private:
|
|||
|
||||
bool mDisabled;
|
||||
bool mUpdateRunning;
|
||||
bool mLowFreeSpace;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsIDiskSpaceWatcher.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
|
|
@ -246,7 +245,6 @@ NS_IMPL_ISUPPORTS(nsOfflineCacheUpdateService,
|
|||
nsOfflineCacheUpdateService::nsOfflineCacheUpdateService()
|
||||
: mDisabled(false)
|
||||
, mUpdateRunning(false)
|
||||
, mLowFreeSpace(false)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
Preferences::AddBoolVarCache(&sAllowOfflineCache,
|
||||
|
|
@ -273,19 +271,6 @@ nsOfflineCacheUpdateService::Init()
|
|||
true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get the current status of the disk in terms of free space and observe
|
||||
// low device storage notifications.
|
||||
nsCOMPtr<nsIDiskSpaceWatcher> diskSpaceWatcherService =
|
||||
do_GetService("@mozilla.org/toolkit/disk-space-watcher;1");
|
||||
if (diskSpaceWatcherService) {
|
||||
diskSpaceWatcherService->GetIsDiskFull(&mLowFreeSpace);
|
||||
} else {
|
||||
NS_WARNING("Could not get disk status from nsIDiskSpaceWatcher");
|
||||
}
|
||||
|
||||
rv = observerService->AddObserver(this, "disk-space-watcher", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
gOfflineCacheUpdateService = this;
|
||||
|
||||
return NS_OK;
|
||||
|
|
@ -407,11 +392,7 @@ nsOfflineCacheUpdateService::ProcessNextUpdate()
|
|||
|
||||
if (mUpdates.Length() > 0) {
|
||||
mUpdateRunning = true;
|
||||
// Canceling the update before Begin() call will make the update
|
||||
// asynchronously finish with an error.
|
||||
if (mLowFreeSpace) {
|
||||
mUpdates[0]->Cancel();
|
||||
}
|
||||
|
||||
return mUpdates[0]->Begin();
|
||||
}
|
||||
|
||||
|
|
@ -582,17 +563,6 @@ nsOfflineCacheUpdateService::Observe(nsISupports *aSubject,
|
|||
mDisabled = true;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "disk-space-watcher")) {
|
||||
if (NS_LITERAL_STRING("full").Equals(aData)) {
|
||||
mLowFreeSpace = true;
|
||||
for (uint32_t i = 0; i < mUpdates.Length(); i++) {
|
||||
mUpdates[i]->Cancel();
|
||||
}
|
||||
} else if (NS_LITERAL_STRING("free").Equals(aData)) {
|
||||
mLowFreeSpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue