本文整理汇总了C++中StartupCache::GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ StartupCache::GetBuffer方法的具体用法?C++ StartupCache::GetBuffer怎么用?C++ StartupCache::GetBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StartupCache
的用法示例。
在下文中一共展示了StartupCache::GetBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spec
// We have data if we're in the middle of writing it or we already
// have it in the cache.
nsresult
nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists)
{
if (mOutputStreamTable.Get(uri, nsnull)) {
*exists = true;
return NS_OK;
}
nsCAutoString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) {
*exists = false;
return NS_OK;
}
nsAutoArrayPtr<char> buf;
PRUint32 len;
if (gStartupCache)
rv = gStartupCache->GetBuffer(spec.get(), getter_Transfers(buf),
&len);
else {
// We don't have everything we need to call BeginCaching and set up
// gStartupCache right now, but we just need to check the cache for
// this URI.
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) {
*exists = false;
return NS_OK;
}
rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
}
*exists = NS_SUCCEEDED(rv);
return NS_OK;
}
示例2: spec
// We have data if we're in the middle of writing it or we already
// have it in the cache.
nsresult
nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists)
{
if (mOutputStreamTable.Get(uri, nullptr)) {
*exists = true;
return NS_OK;
}
nsAutoCString spec(kXULCachePrefix);
nsresult rv = PathifyURI(uri, spec);
if (NS_FAILED(rv)) {
*exists = false;
return NS_OK;
}
UniquePtr<char[]> buf;
uint32_t len;
StartupCache* sc = StartupCache::GetSingleton();
if (sc) {
rv = sc->GetBuffer(spec.get(), &buf, &len);
} else {
*exists = false;
return NS_OK;
}
*exists = NS_SUCCEEDED(rv);
return NS_OK;
}
示例3:
nsresult
StartupCacheWrapper::GetBuffer(const char* id, char** outbuf, uint32_t* length)
{
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) {
return NS_ERROR_NOT_INITIALIZED;
}
return sc->GetBuffer(id, outbuf, length);
}
示例4:
nsresult
StartupCacheWrapper::GetBuffer(const char* id, char** outbuf, uint32_t* length)
{
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) {
return NS_ERROR_NOT_INITIALIZED;
}
UniquePtr<char[]> buf;
nsresult rv = sc->GetBuffer(id, &buf, length);
*outbuf = buf.release();
return rv;
}
示例5: NewObjectInputStreamFromBuffer
nsresult
nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
{
nsresult rv;
nsCAutoString path;
aURI->GetPath(path);
if (!StringEndsWith(path, NS_LITERAL_CSTRING(".xul")))
return NS_ERROR_NOT_AVAILABLE;
// Test gStartupCache to decide whether this is the first nsXULDocument
// participating in the serialization. If gStartupCache is non-null, this document
// must not be first, but it can join the process. Examples of
// multiple master documents participating include hiddenWindow.xul and
// navigator.xul on the Mac, and multiple-app-component (e.g., mailnews
// and browser) startup due to command-line arguments.
//
if (gStartupCache) {
mCacheURITable.Put(aURI, 1);
return NS_OK;
}
// Use a local to refer to the service till we're sure we succeeded, then
// commit to gStartupCache.
StartupCache* startupCache = StartupCache::GetSingleton();
if (!startupCache)
return NS_ERROR_FAILURE;
gDisableXULDiskCache =
Preferences::GetBool(kDisableXULCachePref, gDisableXULDiskCache);
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());
//.........这里部分代码省略.........
示例6: NewObjectInputStreamFromBuffer
nsresult
nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
{
nsresult rv, tmp;
nsAutoCString path;
aURI->GetPath(path);
if (!StringEndsWith(path, NS_LITERAL_CSTRING(".xul")))
return NS_ERROR_NOT_AVAILABLE;
StartupCache* startupCache = StartupCache::GetSingleton();
if (!startupCache)
return NS_ERROR_FAILURE;
if (gDisableXULCache)
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;
nsAutoCString 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....
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)) {
//.........这里部分代码省略.........