Bug 664898 - Cleanup startup cache api, r=taras

This commit is contained in:
Michael Wu 2011-07-20 00:39:09 -07:00
Родитель 6683dc2e18
Коммит c62529f8bd
8 изменённых файлов: 48 добавлений и 49 удалений

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

@ -457,7 +457,7 @@ nsresult
nsXULPrototypeCache::GetInputStream(nsIURI* uri, nsIObjectInputStream** stream)
{
nsCAutoString spec(kXULCachePrefix);
nsresult rv = NS_PathifyURI(uri, spec);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
@ -471,7 +471,7 @@ nsXULPrototypeCache::GetInputStream(nsIURI* uri, nsIObjectInputStream** stream)
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
NS_ENSURE_SUCCESS(rv, rv);
buf.forget();
@ -501,9 +501,9 @@ nsXULPrototypeCache::GetOutputStream(nsIURI* uri, nsIObjectOutputStream** stream
= do_QueryInterface(storageStream);
objectOutput->SetOutputStream(outputStream);
} else {
rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
NS_ENSURE_SUCCESS(rv, rv);
mOutputStreamTable.Put(uri, storageStream);
}
@ -528,12 +528,12 @@ nsXULPrototypeCache::FinishOutputStream(nsIURI* uri)
nsAutoArrayPtr<char> buf;
PRUint32 len;
rv = NS_NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
&len);
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
&len);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString spec(kXULCachePrefix);
rv = NS_PathifyURI(uri, spec);
rv = PathifyURI(uri, spec);
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
rv = gStartupCache->PutBuffer(spec.get(), buf, len);
@ -553,7 +553,7 @@ nsXULPrototypeCache::HasData(nsIURI* uri, PRBool* exists)
return NS_OK;
}
nsCAutoString spec(kXULCachePrefix);
nsresult rv = NS_PathifyURI(uri, spec);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) {
*exists = PR_FALSE;
return NS_OK;
@ -668,7 +668,7 @@ nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
rv = startupCache->GetBuffer(kXULCacheInfoKey, getter_Transfers(buf),
&len);
if (NS_SUCCEEDED(rv))
rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
if (NS_SUCCEEDED(rv)) {
buf.forget();
@ -692,9 +692,9 @@ nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
nsCOMPtr<nsIObjectOutputStream> objectOutput;
nsCOMPtr<nsIInputStream> inputStream;
nsCOMPtr<nsIStorageStream> storageStream;
rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
if (NS_SUCCEEDED(rv)) {
rv = objectOutput->WriteStringZ(locale.get());
rv |= objectOutput->WriteStringZ(chromePath.get());

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

@ -96,6 +96,8 @@
#include "mozilla/FunctionTimer.h"
using namespace mozilla::scache;
static const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1";
static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect;1";
static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1";
@ -855,7 +857,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
StartupCache* cache = StartupCache::GetSingleton();
nsCAutoString cachePath(kJSCachePrefix);
rv = NS_PathifyURI(aURI, cachePath);
rv = PathifyURI(aURI, cachePath);
NS_ENSURE_SUCCESS(rv, rv);
if (cache) {

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

@ -56,8 +56,6 @@
#include "nsIPrincipal.h"
#include "mozilla/scache/StartupCache.h"
using namespace mozilla::scache;
#include "xpcIJSGetFactory.h"
/* 6bd13476-1dd2-11b2-bbef-f0ccb5fa64b6 (thanks, mozbot) */

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

@ -160,7 +160,7 @@ ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject *
}
nsCOMPtr<nsIObjectInputStream> ois;
rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
NS_ENSURE_SUCCESS(rv, rv);
buf.forget();
@ -174,9 +174,9 @@ WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject
nsCOMPtr<nsIObjectOutputStream> oos;
nsCOMPtr<nsIStorageStream> storageStream;
rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(oos),
getter_AddRefs(storageStream),
true);
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(oos),
getter_AddRefs(storageStream),
true);
NS_ENSURE_SUCCESS(rv, rv);
rv = WriteScriptToStream(cx, scriptObj, oos);
@ -185,8 +185,7 @@ WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject
nsAutoArrayPtr<char> buf;
PRUint32 len;
rv = NS_NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
&len);
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), &len);
NS_ENSURE_SUCCESS(rv, rv);
rv = cache->PutBuffer(PromiseFlatCString(uri).get(), buf, len);

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

@ -385,7 +385,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
JSVersion version = cx->findVersion();
nsCAutoString cachePath;
cachePath.AppendPrintf("jssubloader/%d", version);
NS_PathifyURI(uri, cachePath);
PathifyURI(uri, cachePath);
if (cache)
rv = ReadCachedScript(cache, cachePath, cx, &scriptObj);

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

@ -53,8 +53,8 @@ namespace mozilla {
namespace scache {
NS_EXPORT nsresult
NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream)
NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream)
{
nsCOMPtr<nsIStringInputStream> stringStream
= do_CreateInstance("@mozilla.org/io/string-input-stream;1");
@ -69,9 +69,9 @@ NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
}
NS_EXPORT nsresult
NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream,
PRBool wantDebugStream)
NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream,
PRBool wantDebugStream)
{
nsCOMPtr<nsIStorageStream> storageStream;
@ -106,8 +106,8 @@ NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
}
NS_EXPORT nsresult
NS_NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len)
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len)
{
nsresult rv;
nsCOMPtr<nsIInputStream> inputStream;
@ -180,7 +180,7 @@ canonicalizeBase(nsCAutoString &spec,
* jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
*/
NS_EXPORT nsresult
NS_PathifyURI(nsIURI *in, nsACString &out)
PathifyURI(nsIURI *in, nsACString &out)
{
PRBool equals;
nsresult rv;
@ -240,7 +240,7 @@ NS_PathifyURI(nsIURI *in, nsACString &out)
rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_PathifyURI(jarFileURI, out);
rv = PathifyURI(jarFileURI, out);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString path;

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

@ -46,8 +46,8 @@ namespace mozilla {
namespace scache {
NS_EXPORT nsresult
NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream);
NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream);
// We can't retrieve the wrapped stream from the objectOutputStream later,
// so we return it here. We give callers in debug builds the option
@ -56,16 +56,16 @@ NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
// This could cause them to be deserialized incorrectly (as multiple copies
// instead of references).
NS_EXPORT nsresult
NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream,
PRBool wantDebugStream);
NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream,
PRBool wantDebugStream);
NS_EXPORT nsresult
NS_NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len);
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len);
NS_EXPORT nsresult
NS_PathifyURI(nsIURI *in, nsACString &out);
PathifyURI(nsIURI *in, nsACString &out);
}
}
#endif //nsStartupCacheUtils_h_

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

@ -56,18 +56,18 @@ namespace mozilla {
namespace scache {
NS_IMPORT nsresult
NS_NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream);
NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len,
nsIObjectInputStream** stream);
// We can't retrieve the wrapped stream from the objectOutputStream later,
// so we return it here.
NS_IMPORT nsresult
NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream);
NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
nsIStorageStream** stream);
NS_IMPORT nsresult
NS_NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len);
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, PRUint32* len);
}
}
@ -188,7 +188,7 @@ TestWriteObject() {
sc->InvalidateCache();
// Create an object stream. Usually this is done with
// NS_NewObjectOutputWrappedStorageStream, but that uses
// NewObjectOutputWrappedStorageStream, but that uses
// StartupCache::GetSingleton in debug builds, and we
// don't have access to that here. Obviously.
char* id = "id";
@ -223,7 +223,7 @@ TestWriteObject() {
char* bufPtr = NULL;
nsAutoArrayPtr<char> buf;
PRUint32 len;
NS_NewBufferFromStorageStream(storageStream, &bufPtr, &len);
NewBufferFromStorageStream(storageStream, &bufPtr, &len);
buf = bufPtr;
// Since this is a post-startup write, it should be written and
@ -245,7 +245,7 @@ TestWriteObject() {
}
buf2 = buf2Ptr;
rv = NS_NewObjectInputStreamFromBuffer(buf2, len2, getter_AddRefs(objectInput));
rv = NewObjectInputStreamFromBuffer(buf2, len2, getter_AddRefs(objectInput));
if (NS_FAILED(rv)) {
fail("failed to created input stream");
return rv;