Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit a4623c1

Browse files
committed
Bug 1314378 part B - port TestStartupCache to gtest, r=froydnj
MozReview-Commit-ID: LTz4slzIkjH --HG-- extra : rebase_source : 004f3809de2a527f7577e9935221304bb9e6edc2
1 parent 6fc90f2 commit a4623c1

8 files changed

Lines changed: 121 additions & 382 deletions

File tree

startupcache/StartupCache.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ StartupCache::Init()
153153
// This allows to override the startup cache filename
154154
// which is useful from xpcshell, when there is no ProfLDS directory to keep cache in.
155155
char *env = PR_GetEnv("MOZ_STARTUP_CACHE");
156-
if (env) {
156+
if (env && *env) {
157157
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false, getter_AddRefs(mFile));
158158
} else {
159159
nsCOMPtr<nsIFile> file;
@@ -595,6 +595,13 @@ StartupCache::ResetStartupWriteTimer()
595595
return NS_OK;
596596
}
597597

598+
bool
599+
StartupCache::StartupWriteComplete()
600+
{
601+
WaitOnWriteThread();
602+
return mStartupWriteInitiated && mTable.Count() == 0;
603+
}
604+
598605
// StartupCacheDebugOutputStream implementation
599606
#ifdef DEBUG
600607
NS_IMPL_ISUPPORTS(StartupCacheDebugOutputStream, nsIObjectOutputStream,
@@ -737,13 +744,6 @@ StartupCacheWrapper::InvalidateCache()
737744
return NS_OK;
738745
}
739746

740-
nsresult
741-
StartupCacheWrapper::IgnoreDiskCache()
742-
{
743-
StartupCache::IgnoreDiskCache();
744-
return NS_OK;
745-
}
746-
747747
nsresult
748748
StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
749749
nsIObjectOutputStream** outStream)
@@ -755,25 +755,6 @@ StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
755755
return sc->GetDebugObjectOutputStream(stream, outStream);
756756
}
757757

758-
nsresult
759-
StartupCacheWrapper::StartupWriteComplete(bool *complete)
760-
{
761-
StartupCache* sc = StartupCache::GetSingleton();
762-
if (!sc) {
763-
return NS_ERROR_NOT_INITIALIZED;
764-
}
765-
sc->WaitOnWriteThread();
766-
*complete = sc->mStartupWriteInitiated && sc->mTable.Count() == 0;
767-
return NS_OK;
768-
}
769-
770-
nsresult
771-
StartupCacheWrapper::ResetStartupWriteTimer()
772-
{
773-
StartupCache* sc = StartupCache::GetSingleton();
774-
return sc ? sc->ResetStartupWriteTimer() : NS_ERROR_NOT_INITIALIZED;
775-
}
776-
777758
nsresult
778759
StartupCacheWrapper::GetObserver(nsIObserver** obv) {
779760
StartupCache* sc = StartupCache::GetSingleton();

startupcache/StartupCache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,16 @@ friend class StartupCacheWrapper;
138138

139139
size_t SizeOfMapping();
140140

141+
// FOR TESTING ONLY
142+
nsresult ResetStartupWriteTimer();
143+
bool StartupWriteComplete();
141144
private:
142145
StartupCache();
143146
virtual ~StartupCache();
144147

145148
nsresult LoadArchive();
146149
nsresult Init();
147150
void WriteToDisk();
148-
nsresult ResetStartupWriteTimer();
149151
void WaitOnWriteThread();
150152

151153
static nsresult InitSingleton();

startupcache/StartupCacheUtils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
namespace mozilla {
1919
namespace scache {
2020

21-
NS_EXPORT nsresult
22-
NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
21+
nsresult
22+
NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
2323
nsIObjectInputStream** stream)
2424
{
2525
nsCOMPtr<nsIStringInputStream> stringStream =
@@ -37,7 +37,7 @@ NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
3737
return NS_OK;
3838
}
3939

40-
NS_EXPORT nsresult
40+
nsresult
4141
NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
4242
nsIStorageStream** stream,
4343
bool wantDebugStream)
@@ -74,9 +74,9 @@ NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
7474
return NS_OK;
7575
}
7676

77-
NS_EXPORT nsresult
78-
NewBufferFromStorageStream(nsIStorageStream *storageStream,
79-
UniquePtr<char[]>* buffer, uint32_t* len)
77+
nsresult
78+
NewBufferFromStorageStream(nsIStorageStream *storageStream,
79+
UniquePtr<char[]>* buffer, uint32_t* len)
8080
{
8181
nsresult rv;
8282
nsCOMPtr<nsIInputStream> inputStream;
@@ -170,7 +170,7 @@ canonicalizeBase(nsAutoCString &spec,
170170
* jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
171171
* jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
172172
*/
173-
NS_EXPORT nsresult
173+
nsresult
174174
PathifyURI(nsIURI *in, nsACString &out)
175175
{
176176
bool equals;

startupcache/StartupCacheUtils.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
#ifndef nsStartupCacheUtils_h_
66
#define nsStartupCacheUtils_h_
77

8+
#include "nsString.h"
89
#include "nsIStorageStream.h"
910
#include "nsIObjectInputStream.h"
1011
#include "nsIObjectOutputStream.h"
1112
#include "mozilla/UniquePtr.h"
1213

14+
class nsIURI;
15+
1316
namespace mozilla {
1417
namespace scache {
1518

16-
NS_EXPORT nsresult
19+
nsresult
1720
NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
1821
nsIObjectInputStream** stream);
1922

@@ -23,19 +26,19 @@ NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
2326
// non-singleton objects are written out multiple times during a serialization.
2427
// This could cause them to be deserialized incorrectly (as multiple copies
2528
// instead of references).
26-
NS_EXPORT nsresult
29+
nsresult
2730
NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
2831
nsIStorageStream** stream,
2932
bool wantDebugStream);
3033

3134
// Creates a buffer for storing the stream into the cache. The buffer is
3235
// allocated with 'new []'. After calling this function, the caller would
3336
// typically call nsIStartupCache::PutBuffer with the returned buffer.
34-
NS_EXPORT nsresult
37+
nsresult
3538
NewBufferFromStorageStream(nsIStorageStream *storageStream,
3639
UniquePtr<char[]>* buffer, uint32_t* len);
3740

38-
NS_EXPORT nsresult
41+
nsresult
3942
PathifyURI(nsIURI *in, nsACString &out);
4043
} // namespace scache
4144
} // namespace mozilla

startupcache/nsIStartupCache.idl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,13 @@ interface nsIStartupCache : nsISupports
4040

4141
void invalidateCache();
4242

43-
void ignoreDiskCache();
4443

4544
/** In debug builds, wraps this object output stream with a stream that will
4645
* detect and prevent the write of a multiply-referenced non-singleton object
4746
* during serialization. In non-debug, returns an add-ref'd pointer to
4847
* original stream, unwrapped. */
4948
nsIObjectOutputStream getDebugObjectOutputStream(in nsIObjectOutputStream aStream);
5049

51-
/* Allows clients to check whether the one-time writeout after startup
52-
* has finished yet, and also to set this variable as needed (so test
53-
* code can fire mulitple startup writes if needed).
54-
*/
55-
boolean startupWriteComplete();
56-
void resetStartupWriteTimer();
57-
5850
/* Allows clients to simulate the behavior of ObserverService. */
5951
readonly attribute nsIObserver observer;
6052
};

0 commit comments

Comments
 (0)