зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1557904. Stop using [array] in appcache interfaces. r=mayhemer
Differential Revision: https://phabricator.services.mozilla.com/D34308 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
637456901b
Коммит
ec33fbcdf2
|
@ -78,9 +78,7 @@ nsDOMOfflineResourceList::nsDOMOfflineResourceList(
|
|||
mDocumentURI(aDocumentURI),
|
||||
mLoadingPrincipal(aLoadingPrincipal),
|
||||
mExposeCacheUpdateStatus(true),
|
||||
mStatus(OfflineResourceList_Binding::IDLE),
|
||||
mCachedKeys(nullptr),
|
||||
mCachedKeysCount(0) {}
|
||||
mStatus(OfflineResourceList_Binding::IDLE) {}
|
||||
|
||||
nsDOMOfflineResourceList::~nsDOMOfflineResourceList() { ClearCachedKeys(); }
|
||||
|
||||
|
@ -183,20 +181,16 @@ already_AddRefed<DOMStringList> nsDOMOfflineResourceList::GetMozItems(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t length;
|
||||
char** keys;
|
||||
aRv = appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC, &length,
|
||||
&keys);
|
||||
nsTArray<nsCString> keys;
|
||||
aRv = appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC, keys);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
items->Add(NS_ConvertUTF8toUTF16(keys[i]));
|
||||
for (auto& key : keys) {
|
||||
items->Add(NS_ConvertUTF8toUTF16(key));
|
||||
}
|
||||
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(length, keys);
|
||||
|
||||
return items.forget();
|
||||
}
|
||||
|
||||
|
@ -261,7 +255,7 @@ uint32_t nsDOMOfflineResourceList::GetMozLength(ErrorResult& aRv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
return mCachedKeysCount;
|
||||
return mCachedKeys->Length();
|
||||
}
|
||||
|
||||
void nsDOMOfflineResourceList::MozItem(uint32_t aIndex, nsAString& aURI,
|
||||
|
@ -293,13 +287,13 @@ void nsDOMOfflineResourceList::IndexedGetter(uint32_t aIndex, bool& aFound,
|
|||
return;
|
||||
}
|
||||
|
||||
if (aIndex >= mCachedKeysCount) {
|
||||
if (aIndex >= mCachedKeys->Length()) {
|
||||
aFound = false;
|
||||
return;
|
||||
}
|
||||
|
||||
aFound = true;
|
||||
CopyUTF8toUTF16(mozilla::MakeStringSpan(mCachedKeys[aIndex]), aURI);
|
||||
CopyUTF8toUTF16(mCachedKeys->ElementAt(aIndex), aURI);
|
||||
}
|
||||
|
||||
void nsDOMOfflineResourceList::MozAdd(const nsAString& aURI, ErrorResult& aRv) {
|
||||
|
@ -850,14 +844,14 @@ nsresult nsDOMOfflineResourceList::CacheKeys() {
|
|||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
return appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC,
|
||||
&mCachedKeysCount, &mCachedKeys);
|
||||
mCachedKeys.emplace();
|
||||
nsresult rv =
|
||||
appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC, *mCachedKeys);
|
||||
if (NS_FAILED(rv)) {
|
||||
mCachedKeys.reset();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void nsDOMOfflineResourceList::ClearCachedKeys() {
|
||||
if (mCachedKeys) {
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mCachedKeysCount, mCachedKeys);
|
||||
mCachedKeys = nullptr;
|
||||
mCachedKeysCount = 0;
|
||||
}
|
||||
}
|
||||
void nsDOMOfflineResourceList::ClearCachedKeys() { mCachedKeys.reset(); }
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsPIDOMWindow.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -122,8 +123,7 @@ class nsDOMOfflineResourceList final : public mozilla::DOMEventTargetHelper,
|
|||
uint16_t mStatus;
|
||||
|
||||
// The set of dynamic keys for this application cache object.
|
||||
char** mCachedKeys;
|
||||
uint32_t mCachedKeysCount;
|
||||
mozilla::Maybe<nsTArray<nsCString>> mCachedKeys;
|
||||
|
||||
nsCOMArray<mozilla::dom::Event> mPendingEvents;
|
||||
};
|
||||
|
|
|
@ -181,9 +181,7 @@ interface nsIApplicationCache : nsISupports
|
|||
* Returns any entries in the application cache whose type matches
|
||||
* one or more of the bits in typeBits.
|
||||
*/
|
||||
void gatherEntries(in uint32_t typeBits,
|
||||
out unsigned long count,
|
||||
[array, size_is(count)] out string keys);
|
||||
Array<ACString> gatherEntries(in uint32_t typeBits);
|
||||
|
||||
/**
|
||||
* Add a set of namespace entries to the application cache.
|
||||
|
|
|
@ -98,13 +98,11 @@ interface nsIApplicationCacheService : nsISupports
|
|||
/**
|
||||
* Get the list of application cache groups.
|
||||
*/
|
||||
void getGroups([optional] out unsigned long count,
|
||||
[array, size_is(count), retval] out string groupIDs);
|
||||
Array<ACString> getGroups();
|
||||
|
||||
/**
|
||||
* Get the list of application cache groups in the order of
|
||||
* activating time.
|
||||
*/
|
||||
void getGroupsTimeOrdered([optional] out unsigned long count,
|
||||
[array, size_is(count), retval] out string groupIDs);
|
||||
Array<ACString> getGroupsTimeOrdered();
|
||||
};
|
||||
|
|
|
@ -170,23 +170,23 @@ nsApplicationCacheService::EvictMatchingOriginAttributes(
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetGroups(uint32_t* count, char*** keys) {
|
||||
nsApplicationCacheService::GetGroups(nsTArray<nsCString>& keys) {
|
||||
if (!mCacheService) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
RefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetGroups(count, keys);
|
||||
return device->GetGroups(keys);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetGroupsTimeOrdered(uint32_t* count, char*** keys) {
|
||||
nsApplicationCacheService::GetGroupsTimeOrdered(nsTArray<nsCString>& keys) {
|
||||
if (!mCacheService) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
RefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetGroupsTimeOrdered(count, keys);
|
||||
return device->GetGroupsTimeOrdered(keys);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -750,12 +750,12 @@ nsApplicationCache::GetTypes(const nsACString& key, uint32_t* typeBits) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCache::GatherEntries(uint32_t typeBits, uint32_t* count,
|
||||
char*** keys) {
|
||||
nsApplicationCache::GatherEntries(uint32_t typeBits,
|
||||
nsTArray<nsCString>& keys) {
|
||||
NS_ENSURE_TRUE(mValid, NS_ERROR_NOT_AVAILABLE);
|
||||
NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
return mDevice->GatherEntries(mClientID, typeBits, count, keys);
|
||||
return mDevice->GatherEntries(mClientID, typeBits, keys);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1989,8 +1989,8 @@ nsresult nsOfflineCacheDevice::GetTypes(const nsCString& clientID,
|
|||
}
|
||||
|
||||
nsresult nsOfflineCacheDevice::GatherEntries(const nsCString& clientID,
|
||||
uint32_t typeBits, uint32_t* count,
|
||||
char*** keys) {
|
||||
uint32_t typeBits,
|
||||
nsTArray<nsCString>& keys) {
|
||||
NS_ENSURE_TRUE(Initialized(), NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
LOG(("nsOfflineCacheDevice::GatherEntries [cid=%s, typeBits=%X]\n",
|
||||
|
@ -2003,7 +2003,7 @@ nsresult nsOfflineCacheDevice::GatherEntries(const nsCString& clientID,
|
|||
rv = statement->BindInt32ByIndex(1, typeBits);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return RunSimpleQuery(mStatement_GatherEntries, 0, count, keys);
|
||||
return RunSimpleQuery(mStatement_GatherEntries, 0, keys);
|
||||
}
|
||||
|
||||
nsresult nsOfflineCacheDevice::AddNamespace(const nsCString& clientID,
|
||||
|
@ -2070,21 +2070,20 @@ nsresult nsOfflineCacheDevice::GetUsage(const nsACString& clientID,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsOfflineCacheDevice::GetGroups(uint32_t* count, char*** keys) {
|
||||
nsresult nsOfflineCacheDevice::GetGroups(nsTArray<nsCString>& keys) {
|
||||
NS_ENSURE_TRUE(Initialized(), NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
LOG(("nsOfflineCacheDevice::GetGroups"));
|
||||
|
||||
return RunSimpleQuery(mStatement_EnumerateGroups, 0, count, keys);
|
||||
return RunSimpleQuery(mStatement_EnumerateGroups, 0, keys);
|
||||
}
|
||||
|
||||
nsresult nsOfflineCacheDevice::GetGroupsTimeOrdered(uint32_t* count,
|
||||
char*** keys) {
|
||||
nsresult nsOfflineCacheDevice::GetGroupsTimeOrdered(nsTArray<nsCString>& keys) {
|
||||
NS_ENSURE_TRUE(Initialized(), NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
LOG(("nsOfflineCacheDevice::GetGroupsTimeOrder"));
|
||||
|
||||
return RunSimpleQuery(mStatement_EnumerateGroupsTimeOrder, 0, count, keys);
|
||||
return RunSimpleQuery(mStatement_EnumerateGroupsTimeOrder, 0, keys);
|
||||
}
|
||||
|
||||
bool nsOfflineCacheDevice::IsLocked(const nsACString& key) {
|
||||
|
@ -2104,7 +2103,7 @@ void nsOfflineCacheDevice::Unlock(const nsACString& key) {
|
|||
|
||||
nsresult nsOfflineCacheDevice::RunSimpleQuery(mozIStorageStatement* statement,
|
||||
uint32_t resultIndex,
|
||||
uint32_t* count, char*** values) {
|
||||
nsTArray<nsCString>& values) {
|
||||
bool hasRows;
|
||||
nsresult rv = statement->ExecuteStep(&hasRows);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -2119,15 +2118,7 @@ nsresult nsOfflineCacheDevice::RunSimpleQuery(mozIStorageStatement* statement,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
*count = valArray.Length();
|
||||
char** ret = static_cast<char**>(moz_xmalloc(*count * sizeof(char*)));
|
||||
|
||||
for (uint32_t i = 0; i < *count; i++) {
|
||||
ret[i] = NS_xstrdup(valArray[i].get());
|
||||
}
|
||||
|
||||
*values = ret;
|
||||
|
||||
values.SwapElements(valArray);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,9 +154,9 @@ class nsOfflineCacheDevice final : public nsCacheDevice, public nsISupports {
|
|||
nsresult Evict(nsILoadContextInfo* aInfo);
|
||||
nsresult Evict(mozilla::OriginAttributesPattern const& aPattern);
|
||||
|
||||
nsresult GetGroups(uint32_t* count, char*** keys);
|
||||
nsresult GetGroups(nsTArray<nsCString>& keys);
|
||||
|
||||
nsresult GetGroupsTimeOrdered(uint32_t* count, char*** keys);
|
||||
nsresult GetGroupsTimeOrdered(nsTArray<nsCString>& keys);
|
||||
|
||||
bool IsLocked(const nsACString& key);
|
||||
void Lock(const nsACString& key);
|
||||
|
@ -211,14 +211,14 @@ class nsOfflineCacheDevice final : public nsCacheDevice, public nsISupports {
|
|||
const nsACString& key,
|
||||
nsIApplicationCacheNamespace** out);
|
||||
nsresult GatherEntries(const nsCString& clientID, uint32_t typeBits,
|
||||
uint32_t* count, char*** values);
|
||||
nsTArray<nsCString>& keys);
|
||||
nsresult AddNamespace(const nsCString& clientID,
|
||||
nsIApplicationCacheNamespace* ns);
|
||||
|
||||
nsresult GetUsage(const nsACString& clientID, uint32_t* usage);
|
||||
|
||||
nsresult RunSimpleQuery(mozIStorageStatement* statment, uint32_t resultIndex,
|
||||
uint32_t* count, char*** values);
|
||||
nsTArray<nsCString>& values);
|
||||
|
||||
nsCOMPtr<mozIStorageConnection> mDB;
|
||||
RefPtr<nsOfflineCacheEvictionFunction> mEvictionFunction;
|
||||
|
|
|
@ -72,17 +72,6 @@ extern LazyLogModule gOfflineCacheUpdateLog;
|
|||
#define LOG_ENABLED() \
|
||||
MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
|
||||
|
||||
class AutoFreeArray {
|
||||
public:
|
||||
AutoFreeArray(uint32_t count, char** values)
|
||||
: mCount(count), mValues(values){};
|
||||
~AutoFreeArray() { NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mCount, mValues); }
|
||||
|
||||
private:
|
||||
uint32_t mCount;
|
||||
char** mValues;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
nsresult DropReferenceFromURL(nsCOMPtr<nsIURI>& aURI) {
|
||||
|
@ -1719,26 +1708,22 @@ nsresult nsOfflineCacheUpdate::AddExistingItems(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t count = 0;
|
||||
char** keys = nullptr;
|
||||
nsresult rv = mPreviousApplicationCache->GatherEntries(aType, &count, &keys);
|
||||
nsTArray<nsCString> keys;
|
||||
nsresult rv = mPreviousApplicationCache->GatherEntries(aType, keys);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
AutoFreeArray autoFree(count, keys);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
for (auto& key : keys) {
|
||||
if (namespaceFilter) {
|
||||
bool found = false;
|
||||
for (uint32_t j = 0; j < namespaceFilter->Length() && !found; j++) {
|
||||
found = StringBeginsWith(nsDependentCString(keys[i]),
|
||||
namespaceFilter->ElementAt(j));
|
||||
found = StringBeginsWith(key, namespaceFilter->ElementAt(j));
|
||||
}
|
||||
|
||||
if (!found) continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), keys[i]))) {
|
||||
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), key))) {
|
||||
rv = AddURI(uri, aType);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -2039,19 +2024,16 @@ void nsOfflineCacheUpdate::AsyncFinishWithError() {
|
|||
}
|
||||
|
||||
static nsresult EvictOneOfCacheGroups(nsIApplicationCacheService* cacheService,
|
||||
uint32_t count,
|
||||
const char* const* groups) {
|
||||
const nsTArray<nsCString>& groups) {
|
||||
nsresult rv;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
for (auto& group : groups) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), groups[i]);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), group);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsDependentCString group_name(groups[i]);
|
||||
nsCOMPtr<nsIApplicationCache> cache;
|
||||
rv = cacheService->GetActiveCache(group_name, getter_AddRefs(cache));
|
||||
rv = cacheService->GetActiveCache(group, getter_AddRefs(cache));
|
||||
// Maybe someone in another thread or process have deleted it.
|
||||
if (NS_FAILED(rv) || !cache) continue;
|
||||
|
||||
|
@ -2076,15 +2058,11 @@ nsresult nsOfflineCacheUpdate::EvictOneNonPinned() {
|
|||
do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t count;
|
||||
char** groups;
|
||||
rv = cacheService->GetGroupsTimeOrdered(&count, &groups);
|
||||
nsTArray<nsCString> groups;
|
||||
rv = cacheService->GetGroupsTimeOrdered(groups);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = EvictOneOfCacheGroups(cacheService, count, groups);
|
||||
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, groups);
|
||||
return rv;
|
||||
return EvictOneOfCacheGroups(cacheService, groups);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче