本文整理汇总了C++中StartupCache::PutBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ StartupCache::PutBuffer方法的具体用法?C++ StartupCache::PutBuffer怎么用?C++ StartupCache::PutBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StartupCache
的用法示例。
在下文中一共展示了StartupCache::PutBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spec
nsresult
nsXULPrototypeCache::FinishOutputStream(nsIURI* uri)
{
nsresult rv;
StartupCache* sc = StartupCache::GetSingleton();
if (!sc)
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIStorageStream> storageStream;
bool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
if (!found)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIOutputStream> outputStream
= do_QueryInterface(storageStream);
outputStream->Close();
UniquePtr<char[]> buf;
uint32_t len;
rv = NewBufferFromStorageStream(storageStream, &buf, &len);
NS_ENSURE_SUCCESS(rv, rv);
if (!mStartupCacheURITable.GetEntry(uri)) {
nsAutoCString spec(kXULCachePrefix);
rv = PathifyURI(uri, spec);
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
rv = sc->PutBuffer(spec.get(), buf.get(), len);
if (NS_SUCCEEDED(rv)) {
mOutputStreamTable.Remove(uri);
mStartupCacheURITable.PutEntry(uri);
}
}
return rv;
}
示例2:
nsresult
StartupCacheWrapper::PutBuffer(const char* id, const char* inbuf, uint32_t length)
{
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) {
return NS_ERROR_NOT_INITIALIZED;
}
return sc->PutBuffer(id, inbuf, length);
}
示例3: NewObjectInputStreamFromBuffer
//.........这里部分代码省略.........
Preferences::RegisterCallback(CachePrefChangedCallback,
kDisableXULCachePref);
if (gDisableXULDiskCache)
return NS_ERROR_NOT_AVAILABLE;
// Get the chrome directory to validate against the one stored in the
// cache file, or to store there if we're generating a new file.
nsCOMPtr<nsIFile> chromeDir;
rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(chromeDir));
if (NS_FAILED(rv))
return rv;
nsCAutoString chromePath;
rv = chromeDir->GetNativePath(chromePath);
if (NS_FAILED(rv))
return rv;
// XXXbe we assume the first package's locale is the same as the locale of
// all subsequent packages of cached chrome URIs....
nsCAutoString package;
rv = aURI->GetHost(package);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIXULChromeRegistry> chromeReg
= do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
nsCAutoString locale;
rv = chromeReg->GetSelectedLocale(package, locale);
if (NS_FAILED(rv))
return rv;
nsCAutoString fileChromePath, fileLocale;
nsAutoArrayPtr<char> buf;
PRUint32 len, amtRead;
nsCOMPtr<nsIObjectInputStream> objectInput;
rv = startupCache->GetBuffer(kXULCacheInfoKey, getter_Transfers(buf),
&len);
if (NS_SUCCEEDED(rv))
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
if (NS_SUCCEEDED(rv)) {
buf.forget();
rv = objectInput->ReadCString(fileLocale);
rv |= objectInput->ReadCString(fileChromePath);
if (NS_FAILED(rv) ||
(!fileChromePath.Equals(chromePath) ||
!fileLocale.Equals(locale))) {
// Our cache won't be valid in this case, we'll need to rewrite.
// XXX This blows away work that other consumers (like
// mozJSComponentLoader) have done, need more fine-grained control.
startupCache->InvalidateCache();
rv = NS_ERROR_UNEXPECTED;
}
} else if (rv != NS_ERROR_NOT_AVAILABLE)
// NS_ERROR_NOT_AVAILABLE is normal, usually if there's no cachefile.
return rv;
if (NS_FAILED(rv)) {
// Either the cache entry was invalid or it didn't exist, so write it now.
nsCOMPtr<nsIObjectOutputStream> objectOutput;
nsCOMPtr<nsIInputStream> inputStream;
nsCOMPtr<nsIStorageStream> storageStream;
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
if (NS_SUCCEEDED(rv)) {
rv = objectOutput->WriteStringZ(locale.get());
rv |= objectOutput->WriteStringZ(chromePath.get());
rv |= objectOutput->Close();
rv |= storageStream->NewInputStream(0, getter_AddRefs(inputStream));
}
if (NS_SUCCEEDED(rv))
rv = inputStream->Available(&len);
if (NS_SUCCEEDED(rv)) {
buf = new char[len];
rv = inputStream->Read(buf, len, &amtRead);
if (NS_SUCCEEDED(rv) && len == amtRead)
rv = startupCache->PutBuffer(kXULCacheInfoKey, buf, len);
else {
rv = NS_ERROR_UNEXPECTED;
}
}
// Failed again, just bail.
if (NS_FAILED(rv)) {
startupCache->InvalidateCache();
return NS_ERROR_FAILURE;
}
}
// Success! Insert this URI into the mCacheURITable
// and commit locals to globals.
mCacheURITable.Put(aURI, 1);
gStartupCache = startupCache;
return NS_OK;
}
示例4: NewObjectInputStreamFromBuffer
//.........这里部分代码省略.........
// XXXbe we assume the first package's locale is the same as the locale of
// all subsequent packages of cached chrome URIs....
nsAutoCString package;
rv = aURI->GetHost(package);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIXULChromeRegistry> chromeReg
= do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
nsAutoCString locale;
rv = chromeReg->GetSelectedLocale(package, locale);
if (NS_FAILED(rv))
return rv;
nsAutoCString fileChromePath, fileLocale;
UniquePtr<char[]> buf;
uint32_t len, amtRead;
nsCOMPtr<nsIObjectInputStream> objectInput;
rv = startupCache->GetBuffer(kXULCacheInfoKey, &buf, &len);
if (NS_SUCCEEDED(rv))
rv = NewObjectInputStreamFromBuffer(Move(buf), len,
getter_AddRefs(objectInput));
if (NS_SUCCEEDED(rv)) {
rv = objectInput->ReadCString(fileLocale);
tmp = objectInput->ReadCString(fileChromePath);
if (NS_FAILED(tmp)) {
rv = tmp;
}
if (NS_FAILED(rv) ||
(!fileChromePath.Equals(chromePath) ||
!fileLocale.Equals(locale))) {
// Our cache won't be valid in this case, we'll need to rewrite.
// XXX This blows away work that other consumers (like
// mozJSComponentLoader) have done, need more fine-grained control.
startupCache->InvalidateCache();
mStartupCacheURITable.Clear();
rv = NS_ERROR_UNEXPECTED;
}
} else if (rv != NS_ERROR_NOT_AVAILABLE)
// NS_ERROR_NOT_AVAILABLE is normal, usually if there's no cachefile.
return rv;
if (NS_FAILED(rv)) {
// Either the cache entry was invalid or it didn't exist, so write it now.
nsCOMPtr<nsIObjectOutputStream> objectOutput;
nsCOMPtr<nsIInputStream> inputStream;
nsCOMPtr<nsIStorageStream> storageStream;
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
getter_AddRefs(storageStream),
false);
if (NS_SUCCEEDED(rv)) {
rv = objectOutput->WriteStringZ(locale.get());
tmp = objectOutput->WriteStringZ(chromePath.get());
if (NS_FAILED(tmp)) {
rv = tmp;
}
tmp = objectOutput->Close();
if (NS_FAILED(tmp)) {
rv = tmp;
}
tmp = storageStream->NewInputStream(0, getter_AddRefs(inputStream));
if (NS_FAILED(tmp)) {
rv = tmp;
}
}
if (NS_SUCCEEDED(rv)) {
uint64_t len64;
rv = inputStream->Available(&len64);
if (NS_SUCCEEDED(rv)) {
if (len64 <= UINT32_MAX)
len = (uint32_t)len64;
else
rv = NS_ERROR_FILE_TOO_BIG;
}
}
if (NS_SUCCEEDED(rv)) {
buf = MakeUnique<char[]>(len);
rv = inputStream->Read(buf.get(), len, &amtRead);
if (NS_SUCCEEDED(rv) && len == amtRead)
rv = startupCache->PutBuffer(kXULCacheInfoKey, buf.get(), len);
else {
rv = NS_ERROR_UNEXPECTED;
}
}
// Failed again, just bail.
if (NS_FAILED(rv)) {
startupCache->InvalidateCache();
mStartupCacheURITable.Clear();
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}