Bug 1410142 - use NS_NewLocalFile in dom/; r=baku

The interface is nicer, and it is probably slightly faster.
This commit is contained in:
Nathan Froyd 2017-10-23 14:22:14 -04:00
Родитель 63505fc609
Коммит 4f852fdd0c
2 изменённых файлов: 70 добавлений и 170 удалений

Просмотреть файл

@ -4925,12 +4925,9 @@ GetFileForPath(const nsAString& aPath)
{
MOZ_ASSERT(!aPath.IsEmpty());
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
if (NS_WARN_IF(!file)) {
return nullptr;
}
if (NS_WARN_IF(NS_FAILED(file->InitWithPath(aPath)))) {
nsCOMPtr<nsIFile> file;
if (NS_WARN_IF(NS_FAILED(NS_NewLocalFile(aPath, false,
getter_AddRefs(file))))) {
return nullptr;
}
@ -11255,13 +11252,8 @@ DatabaseConnection::GetFileSize(const nsAString& aPath, int64_t* aResult)
MOZ_ASSERT(!aPath.IsEmpty());
MOZ_ASSERT(aResult);
nsresult rv;
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = file->InitWithPath(aPath);
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewLocalFile(aPath, false, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

Просмотреть файл

@ -3584,16 +3584,11 @@ QuotaManager::CollectOriginsForEviction(
nsresult
QuotaManager::Init(const nsAString& aBasePath)
{
nsresult rv;
mBasePath = aBasePath;
nsCOMPtr<nsIFile> baseDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = baseDir->InitWithPath(aBasePath);
nsCOMPtr<nsIFile> baseDir;
nsresult rv = NS_NewLocalFile(aBasePath, false, getter_AddRefs(baseDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -3947,11 +3942,8 @@ QuotaManager::GetQuotaObject(PersistenceType aPersistenceType,
*aFileSizeOut = 0;
}
nsresult rv;
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = file->InitWithPath(aPath);
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewLocalFile(aPath, false, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, nullptr);
return GetQuotaObject(aPersistenceType, aGroup, aOrigin, file, aFileSizeOut);
@ -4006,12 +3998,9 @@ QuotaManager::GetDirectoryForOrigin(PersistenceType aPersistenceType,
const nsACString& aASCIIOrigin,
nsIFile** aDirectory) const
{
nsresult rv;
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = directory->InitWithPath(GetStoragePath(aPersistenceType));
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(GetStoragePath(aPersistenceType), false,
getter_AddRefs(directory));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString originSanitized(aASCIIOrigin);
@ -4217,15 +4206,9 @@ QuotaManager::InitializeRepository(PersistenceType aPersistenceType)
MOZ_ASSERT(aPersistenceType == PERSISTENCE_TYPE_TEMPORARY ||
aPersistenceType == PERSISTENCE_TYPE_DEFAULT);
nsresult rv;
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = directory->InitWithPath(GetStoragePath(aPersistenceType));
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(GetStoragePath(aPersistenceType), false,
getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4396,13 +4379,10 @@ QuotaManager::MaybeUpgradeIndexedDBDirectory()
{
AssertIsOnIOThread();
nsresult rv;
nsCOMPtr<nsIFile> indexedDBDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = indexedDBDir->InitWithPath(mIndexedDBPath);
nsCOMPtr<nsIFile> indexedDBDir;
nsresult rv = NS_NewLocalFile(mIndexedDBPath, false,
getter_AddRefs(indexedDBDir));
NS_ENSURE_SUCCESS(rv, rv);
bool exists;
@ -4423,11 +4403,9 @@ QuotaManager::MaybeUpgradeIndexedDBDirectory()
return NS_OK;
}
nsCOMPtr<nsIFile> persistentStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = persistentStorageDir->InitWithPath(mStoragePath);
nsCOMPtr<nsIFile> persistentStorageDir;
rv = NS_NewLocalFile(mStoragePath, false,
getter_AddRefs(persistentStorageDir));
NS_ENSURE_SUCCESS(rv, rv);
rv = persistentStorageDir->Append(NS_LITERAL_STRING(PERSISTENT_DIRECTORY_NAME));
@ -4462,15 +4440,10 @@ QuotaManager::MaybeUpgradePersistentStorageDirectory()
{
AssertIsOnIOThread();
nsresult rv;
nsCOMPtr<nsIFile> persistentStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = persistentStorageDir->InitWithPath(mStoragePath);
nsCOMPtr<nsIFile> persistentStorageDir;
nsresult rv = NS_NewLocalFile(mStoragePath, false,
getter_AddRefs(persistentStorageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4502,13 +4475,9 @@ QuotaManager::MaybeUpgradePersistentStorageDirectory()
return NS_OK;
}
nsCOMPtr<nsIFile> defaultStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = defaultStorageDir->InitWithPath(mDefaultStoragePath);
nsCOMPtr<nsIFile> defaultStorageDir;
rv = NS_NewLocalFile(mDefaultStoragePath, false,
getter_AddRefs(defaultStorageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4534,13 +4503,9 @@ QuotaManager::MaybeUpgradePersistentStorageDirectory()
}
// Upgrade metadata files for origin directories in temporary storage.
nsCOMPtr<nsIFile> temporaryStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = temporaryStorageDir->InitWithPath(mTemporaryStoragePath);
nsCOMPtr<nsIFile> temporaryStorageDir;
rv = NS_NewLocalFile(mTemporaryStoragePath, false,
getter_AddRefs(temporaryStorageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4585,15 +4550,9 @@ QuotaManager::MaybeRemoveOldDirectories()
{
AssertIsOnIOThread();
nsresult rv;
nsCOMPtr<nsIFile> indexedDBDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = indexedDBDir->InitWithPath(mIndexedDBPath);
nsCOMPtr<nsIFile> indexedDBDir;
nsresult rv = NS_NewLocalFile(mIndexedDBPath, false,
getter_AddRefs(indexedDBDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4613,13 +4572,9 @@ QuotaManager::MaybeRemoveOldDirectories()
}
}
nsCOMPtr<nsIFile> persistentStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = persistentStorageDir->InitWithPath(mStoragePath);
nsCOMPtr<nsIFile> persistentStorageDir;
rv = NS_NewLocalFile(mStoragePath, false,
getter_AddRefs(persistentStorageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4668,13 +4623,9 @@ QuotaManager::UpgradeStorageFrom0_0To1_0(mozIStorageConnection* aConnection)
}
for (const PersistenceType persistenceType : kAllPersistenceTypes) {
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = directory->InitWithPath(GetStoragePath(persistenceType));
nsCOMPtr<nsIFile> directory;
rv = NS_NewLocalFile(GetStoragePath(persistenceType), false,
getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4785,13 +4736,9 @@ QuotaManager::UpgradeStorageFrom1_0To2_0(mozIStorageConnection* aConnection)
nsresult rv;
for (const PersistenceType persistenceType : kAllPersistenceTypes) {
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = directory->InitWithPath(GetStoragePath(persistenceType));
nsCOMPtr<nsIFile> directory;
rv = NS_NewLocalFile(GetStoragePath(persistenceType), false,
getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4848,13 +4795,9 @@ QuotaManager::UpgradeStorageFrom2_0To2_1(mozIStorageConnection* aConnection)
nsresult rv;
for (const PersistenceType persistenceType : kAllPersistenceTypes) {
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = directory->InitWithPath(GetStoragePath(persistenceType));
nsCOMPtr<nsIFile> directory;
rv = NS_NewLocalFile(GetStoragePath(persistenceType), false,
getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4919,15 +4862,9 @@ QuotaManager::EnsureStorageIsInitialized()
return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIFile> storageFile =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = storageFile->InitWithPath(mBasePath);
nsCOMPtr<nsIFile> storageFile;
nsresult rv = NS_NewLocalFile(mBasePath, false, getter_AddRefs(storageFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4993,13 +4930,8 @@ QuotaManager::EnsureStorageIsInitialized()
if (storageVersion < kStorageVersion) {
const bool newDatabase = !storageVersion;
nsCOMPtr<nsIFile> storageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = storageDir->InitWithPath(mStoragePath);
nsCOMPtr<nsIFile> storageDir;
rv = NS_NewLocalFile(mStoragePath, false, getter_AddRefs(storageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -5011,13 +4943,9 @@ QuotaManager::EnsureStorageIsInitialized()
}
if (!exists) {
nsCOMPtr<nsIFile> indexedDBDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = indexedDBDir->InitWithPath(mIndexedDBPath);
nsCOMPtr<nsIFile> indexedDBDir;
rv = NS_NewLocalFile(mIndexedDBPath, false,
getter_AddRefs(indexedDBDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -5241,6 +5169,10 @@ QuotaManager::EnsureOriginIsInitializedInternal(
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mTemporaryStorageInitialized = true;
CheckTemporaryStorageLimits();
}
bool created;
@ -6945,15 +6877,10 @@ GetUsageOp::TraverseRepository(QuotaManager* aQuotaManager,
AssertIsOnIOThread();
MOZ_ASSERT(aQuotaManager);
nsresult rv;
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = directory->InitWithPath(aQuotaManager->GetStoragePath(aPersistenceType));
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(aPersistenceType),
false, getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -7387,15 +7314,10 @@ ResetOrClearOp::DeleteFiles(QuotaManager* aQuotaManager)
AssertIsOnIOThread();
MOZ_ASSERT(aQuotaManager);
nsresult rv;
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
rv = directory->InitWithPath(aQuotaManager->GetStoragePath());
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(), false,
getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
@ -7408,13 +7330,9 @@ ResetOrClearOp::DeleteFiles(QuotaManager* aQuotaManager)
MOZ_ASSERT(false, "Failed to remove storage directory!");
}
nsCOMPtr<nsIFile> storageFile =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
rv = storageFile->InitWithPath(aQuotaManager->GetBasePath());
nsCOMPtr<nsIFile> storageFile;
rv = NS_NewLocalFile(aQuotaManager->GetBasePath(), false,
getter_AddRefs(storageFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
@ -7469,15 +7387,10 @@ ClearRequestBase::DeleteFiles(QuotaManager* aQuotaManager,
AssertIsOnIOThread();
MOZ_ASSERT(aQuotaManager);
nsresult rv;
nsCOMPtr<nsIFile> directory =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
rv = directory->InitWithPath(aQuotaManager->GetStoragePath(aPersistenceType));
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(aPersistenceType),
false, getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
@ -8881,19 +8794,14 @@ CreateOrUpgradeDirectoryMetadataHelper::ProcessOriginDirectory(
// Move internal origins to new persistent storage.
if (QuotaManager::IsOriginInternal(aOriginProps.mSpec)) {
if (!mPermanentStorageDir) {
mPermanentStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
const nsString& permanentStoragePath =
quotaManager->GetStoragePath(PERSISTENCE_TYPE_PERSISTENT);
rv = mPermanentStorageDir->InitWithPath(permanentStoragePath);
rv = NS_NewLocalFile(permanentStoragePath, false,
getter_AddRefs(mPermanentStorageDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}