зеркало из https://github.com/mozilla/pjs.git
Bug 746697 - Create nsApplicationCacheService to wrap nsOfflineCacheDevice. r=honzab
This commit is contained in:
Родитель
391648877f
Коммит
1f236c5437
|
@ -60,6 +60,7 @@
|
|||
#include "nsCacheService.h"
|
||||
#include "nsDiskCacheDeviceSQL.h"
|
||||
#include "nsApplicationCache.h"
|
||||
#include "nsApplicationCacheService.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsNetStrings.h"
|
||||
#include "nsDNSPrefetch.h"
|
||||
|
@ -215,7 +216,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNestedAboutURI)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAboutCacheEntry)
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsOfflineCacheDevice, nsOfflineCacheDevice::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsApplicationCacheService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsApplicationCacheNamespace)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsApplicationCache)
|
||||
|
||||
|
@ -902,7 +903,7 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
|
|||
{ &kNS_SOCKS4SOCKETPROVIDER_CID, false, NULL, nsSOCKSSocketProvider::CreateV4 },
|
||||
{ &kNS_UDPSOCKETPROVIDER_CID, false, NULL, nsUDPSocketProviderConstructor },
|
||||
{ &kNS_CACHESERVICE_CID, false, NULL, nsCacheService::Create },
|
||||
{ &kNS_APPLICATIONCACHESERVICE_CID, false, NULL, nsOfflineCacheDeviceConstructor },
|
||||
{ &kNS_APPLICATIONCACHESERVICE_CID, false, NULL, nsApplicationCacheServiceConstructor },
|
||||
{ &kNS_APPLICATIONCACHENAMESPACE_CID, false, NULL, nsApplicationCacheNamespaceConstructor },
|
||||
{ &kNS_APPLICATIONCACHE_CID, false, NULL, nsApplicationCacheConstructor },
|
||||
#ifdef NECKO_COOKIES
|
||||
|
|
|
@ -80,6 +80,7 @@ CPPSRCS = \
|
|||
nsDiskCacheMap.cpp \
|
||||
nsDiskCacheStreams.cpp \
|
||||
nsDeleteDir.cpp \
|
||||
nsApplicationCacheService.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/* 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 "nsDiskCache.h"
|
||||
#include "nsDiskCacheDeviceSQL.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsApplicationCacheService.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsApplicationCacheService, nsIApplicationCacheService)
|
||||
|
||||
nsApplicationCacheService::nsApplicationCacheService()
|
||||
{
|
||||
nsCOMPtr<nsICacheService> serv = do_GetService(kCacheServiceCID);
|
||||
mCacheService = nsCacheService::GlobalInstance();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::CreateApplicationCache(const nsACString &group,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->CreateApplicationCache(group, out);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetApplicationCache(const nsACString &clientID,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetApplicationCache(clientID, out);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetActiveCache(const nsACString &group,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetActiveCache(group, out);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::DeactivateGroup(const nsACString &group)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->DeactivateGroup(group);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::ChooseApplicationCache(const nsACString &key,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->ChooseApplicationCache(key, out);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::CacheOpportunistically(nsIApplicationCache* cache,
|
||||
const nsACString &key)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->CacheOpportunistically(cache, key);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetGroups(PRUint32 *count,
|
||||
char ***keys)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetGroups(count, keys);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsApplicationCacheService::GetGroupsTimeOrdered(PRUint32 *count,
|
||||
char ***keys)
|
||||
{
|
||||
if (!mCacheService)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsRefPtr<nsOfflineCacheDevice> device;
|
||||
nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return device->GetGroupsTimeOrdered(count, keys);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* 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 _nsApplicationCacheService_h_
|
||||
#define _nsApplicationCacheService_h_
|
||||
|
||||
class nsApplicationCacheService : public nsIApplicationCacheService
|
||||
{
|
||||
public:
|
||||
nsApplicationCacheService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAPPLICATIONCACHESERVICE
|
||||
private:
|
||||
nsRefPtr<nsCacheService> mCacheService;
|
||||
};
|
||||
|
||||
#endif // _nsApplicationCacheService_h_
|
|
@ -1589,6 +1589,18 @@ nsCacheService::CreateDiskDevice()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheService::GetOfflineDevice(nsOfflineCacheDevice **aDevice)
|
||||
{
|
||||
if (!mOfflineDevice) {
|
||||
nsresult rv = CreateOfflineDevice();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
NS_ADDREF(*aDevice = mOfflineDevice);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheService::CreateOfflineDevice()
|
||||
{
|
||||
|
|
|
@ -143,6 +143,12 @@ public:
|
|||
|
||||
static bool IsStorageEnabledForPolicy_Locked(nsCacheStoragePolicy policy);
|
||||
|
||||
/**
|
||||
* Methods called by nsApplicationCacheService
|
||||
*/
|
||||
|
||||
nsresult GetOfflineDevice(nsOfflineCacheDevice ** aDevice);
|
||||
|
||||
// This method may be called to release an object while the cache service
|
||||
// lock is being held. If a non-null target is specified and the target
|
||||
// does not correspond to the current thread, then the release will be
|
||||
|
|
|
@ -73,7 +73,6 @@
|
|||
using namespace mozilla;
|
||||
|
||||
static const char OFFLINE_CACHE_DEVICE_ID[] = { "offline" };
|
||||
static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
|
||||
|
||||
#define LOG(args) CACHE_LOG_DEBUG(args)
|
||||
|
||||
|
@ -821,7 +820,7 @@ private:
|
|||
* nsOfflineCacheDevice
|
||||
*/
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsOfflineCacheDevice, nsIApplicationCacheService)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS0(nsOfflineCacheDevice)
|
||||
|
||||
nsOfflineCacheDevice::nsOfflineCacheDevice()
|
||||
: mDB(nsnull)
|
||||
|
@ -985,23 +984,6 @@ nsOfflineCacheDevice::DeleteData(nsCacheEntry *entry)
|
|||
* nsCacheDevice implementation
|
||||
*/
|
||||
|
||||
/* static */
|
||||
nsOfflineCacheDevice *
|
||||
nsOfflineCacheDevice::GetInstance()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICacheService> serv = do_GetService(kCacheServiceCID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsICacheService *iservice = static_cast<nsICacheService*>(serv.get());
|
||||
nsCacheService *cacheService = static_cast<nsCacheService*>(iservice);
|
||||
rv = cacheService->CreateOfflineDevice();
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
NS_IF_ADDREF(cacheService->mOfflineDevice);
|
||||
return cacheService->mOfflineDevice;
|
||||
}
|
||||
|
||||
// This struct is local to nsOfflineCacheDevice::Init, but ISO C++98 doesn't
|
||||
// allow a template (mozilla::ArrayLength) to be instantiated based on a local
|
||||
// type. Boo-urns!
|
||||
|
@ -2055,7 +2037,7 @@ nsOfflineCacheDevice::GetUsage(const nsACString &clientID,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::GetGroups(PRUint32 *count,
|
||||
char ***keys)
|
||||
{
|
||||
|
@ -2065,7 +2047,7 @@ nsOfflineCacheDevice::GetGroups(PRUint32 *count,
|
|||
return RunSimpleQuery(mStatement_EnumerateGroups, 0, count, keys);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::GetGroupsTimeOrdered(PRUint32 *count,
|
||||
char ***keys)
|
||||
{
|
||||
|
@ -2113,7 +2095,7 @@ nsOfflineCacheDevice::RunSimpleQuery(mozIStorageStatement * statement,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::CreateApplicationCache(const nsACString &group,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
|
@ -2151,7 +2133,7 @@ nsOfflineCacheDevice::CreateApplicationCache(const nsACString &group,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::GetApplicationCache(const nsACString &clientID,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
|
@ -2186,7 +2168,7 @@ nsOfflineCacheDevice::GetApplicationCache(const nsACString &clientID,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::GetActiveCache(const nsACString &group,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
|
@ -2199,7 +2181,7 @@ nsOfflineCacheDevice::GetActiveCache(const nsACString &group,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::DeactivateGroup(const nsACString &group)
|
||||
{
|
||||
nsCString *active = nsnull;
|
||||
|
@ -2248,7 +2230,7 @@ nsOfflineCacheDevice::CanUseCache(nsIURI *keyURI, const nsCString &clientID)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::ChooseApplicationCache(const nsACString &key,
|
||||
nsIApplicationCache **out)
|
||||
{
|
||||
|
@ -2321,7 +2303,7 @@ nsOfflineCacheDevice::ChooseApplicationCache(const nsACString &key,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsOfflineCacheDevice::CacheOpportunistically(nsIApplicationCache* cache,
|
||||
const nsACString &key)
|
||||
{
|
||||
|
|
|
@ -89,20 +89,17 @@ private:
|
|||
};
|
||||
|
||||
class nsOfflineCacheDevice : public nsCacheDevice
|
||||
, public nsIApplicationCacheService
|
||||
, public nsISupports
|
||||
{
|
||||
public:
|
||||
nsOfflineCacheDevice();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAPPLICATIONCACHESERVICE
|
||||
|
||||
/**
|
||||
* nsCacheDevice methods
|
||||
*/
|
||||
|
||||
static nsOfflineCacheDevice *GetInstance();
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
|
@ -174,6 +171,28 @@ public:
|
|||
nsresult GetGroupForCache(const nsCSubstring &clientID,
|
||||
nsCString &out);
|
||||
|
||||
nsresult CreateApplicationCache(const nsACString &group,
|
||||
nsIApplicationCache **out);
|
||||
|
||||
nsresult GetApplicationCache(const nsACString &clientID,
|
||||
nsIApplicationCache **out);
|
||||
|
||||
nsresult GetActiveCache(const nsACString &group,
|
||||
nsIApplicationCache **out);
|
||||
|
||||
nsresult DeactivateGroup(const nsACString &group);
|
||||
|
||||
nsresult ChooseApplicationCache(const nsACString &key,
|
||||
nsIApplicationCache **out);
|
||||
|
||||
nsresult CacheOpportunistically(nsIApplicationCache* cache,
|
||||
const nsACString &key);
|
||||
|
||||
nsresult GetGroups(PRUint32 *count,char ***keys);
|
||||
|
||||
nsresult GetGroupsTimeOrdered(PRUint32 *count,
|
||||
char ***keys);
|
||||
|
||||
/**
|
||||
* Preference accessors
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче