зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm
The lone remaining startup cache-related uses of nsAutoArrayPtr are both in TestStartupCache.cpp, for use with nsIStartupCache::GetBuffer. The uses can't use StartupCache::GetBuffer because StartupCache::GetBuffer isn't visible outside of libxul, and TestStartupCache is a normal C++ unit test. The Right Thing is to convert TestStartupCache to a gtest so we can see libxul internal symbols and then delete nsIStartupCache entirely. That's a bit complicated, as TestStartupCache doesn't fit nicely into gtest's framework. The simpler solution is to add a UniquePtr overload in the interface that hides the XPCOM outparam management details.
This commit is contained in:
Родитель
060b90466d
Коммит
2e83574eb4
|
@ -9,6 +9,10 @@
|
||||||
#include "nsIObserver.idl"
|
#include "nsIObserver.idl"
|
||||||
#include "nsIObjectOutputStream.idl"
|
#include "nsIObjectOutputStream.idl"
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
%}
|
||||||
|
|
||||||
[uuid(25957820-90a1-428c-8739-b0845d3cc534)]
|
[uuid(25957820-90a1-428c-8739-b0845d3cc534)]
|
||||||
interface nsIStartupCache : nsISupports
|
interface nsIStartupCache : nsISupports
|
||||||
{
|
{
|
||||||
|
@ -19,6 +23,18 @@ interface nsIStartupCache : nsISupports
|
||||||
* in that file. */
|
* in that file. */
|
||||||
|
|
||||||
uint32_t getBuffer(in string aID, out charPtr aBuffer);
|
uint32_t getBuffer(in string aID, out charPtr aBuffer);
|
||||||
|
%{C++
|
||||||
|
/* A more convenient interface for using from C++. */
|
||||||
|
nsresult GetBuffer(const char* id, mozilla::UniquePtr<char[]>* outbuf, uint32_t* length)
|
||||||
|
{
|
||||||
|
char* buf;
|
||||||
|
nsresult rv = GetBuffer(id, &buf, length);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
outbuf->reset(buf);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
void putBuffer(in string aID, in string aBuffer,
|
void putBuffer(in string aID, in string aBuffer,
|
||||||
in uint32_t aLength);
|
in uint32_t aLength);
|
||||||
|
|
||||||
|
|
|
@ -92,26 +92,23 @@ TestStartupWriteRead() {
|
||||||
|
|
||||||
const char* buf = "Market opportunities for BeardBook";
|
const char* buf = "Market opportunities for BeardBook";
|
||||||
const char* id = "id";
|
const char* id = "id";
|
||||||
char* outbufPtr = nullptr;
|
UniquePtr<char[]> outbuf;
|
||||||
nsAutoArrayPtr<char> outbuf;
|
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
||||||
rv = sc->PutBuffer(id, buf, strlen(buf) + 1);
|
rv = sc->PutBuffer(id, buf, strlen(buf) + 1);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = sc->GetBuffer(id, &outbufPtr, &len);
|
rv = sc->GetBuffer(id, &outbuf, &len);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
outbuf = outbufPtr;
|
NS_ENSURE_STR_MATCH(buf, outbuf.get(), "pre-write read");
|
||||||
NS_ENSURE_STR_MATCH(buf, outbuf, "pre-write read");
|
|
||||||
|
|
||||||
rv = sc->ResetStartupWriteTimer();
|
rv = sc->ResetStartupWriteTimer();
|
||||||
rv = WaitForStartupTimer();
|
rv = WaitForStartupTimer();
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = sc->GetBuffer(id, &outbufPtr, &len);
|
rv = sc->GetBuffer(id, &outbuf, &len);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
outbuf = outbufPtr;
|
NS_ENSURE_STR_MATCH(buf, outbuf.get(), "simple write/read");
|
||||||
NS_ENSURE_STR_MATCH(buf, outbuf, "simple write/read");
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче