Skip to content

Commit

Permalink
Bug 1046841 - Convert xpcom/components/ to Gecko style. r=froydnj
Browse files Browse the repository at this point in the history
poiru committed Aug 2, 2014
1 parent 8df0994 commit 0827bb1
Showing 12 changed files with 2,086 additions and 1,889 deletions.
379 changes: 218 additions & 161 deletions xpcom/components/ManifestParser.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions xpcom/components/ManifestParser.h
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@

class nsIFile;

void ParseManifest(NSLocationType type, mozilla::FileLocation &file,
char* buf, bool aChromeOnly, bool aXPTOnly=false);
void ParseManifest(NSLocationType aType, mozilla::FileLocation& aFile,
char* aBuf, bool aChromeOnly, bool aXPTOnly = false);

void LogMessage(const char* aMsg, ...);

void LogMessageWithContext(mozilla::FileLocation &aFile,
void LogMessageWithContext(mozilla::FileLocation& aFile,
uint32_t aLineNumber, const char* aMsg, ...);

#endif // ManifestParser_h
6 changes: 3 additions & 3 deletions xpcom/components/Module.h
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ struct Module

struct CIDEntry;

typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)
(const Module& module, const CIDEntry& entry);
typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)(
const Module& module, const CIDEntry& entry);

typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter,
const nsIID& aIID,
@@ -62,7 +62,7 @@ struct Module
struct ContractIDEntry
{
const char* contractid;
nsID const * cid;
nsID const* cid;
ProcessSelector processSelector;
};

2 changes: 1 addition & 1 deletion xpcom/components/ModuleLoader.h
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class ModuleLoader : public nsISupports
* to be loaded multiple times. The Module object should either be
* statically or permanently allocated; it will not be freed.
*/
virtual const Module* LoadModule(mozilla::FileLocation &aFile) = 0;
virtual const Module* LoadModule(mozilla::FileLocation& aFile) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(ModuleLoader, MOZILLA_MODULELOADER_PSEUDO_IID)

13 changes: 5 additions & 8 deletions xpcom/components/ModuleUtils.h
Original file line number Diff line number Diff line change
@@ -104,19 +104,16 @@ namespace mozilla {

class GenericModule MOZ_FINAL : public nsIModule
{
~GenericModule() {}
~GenericModule() {}

public:
explicit GenericModule(const mozilla::Module* aData)
: mData(aData)
{
}
explicit GenericModule(const mozilla::Module* aData) : mData(aData) {}

NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIMODULE
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIMODULE

private:
const mozilla::Module* mData;
const mozilla::Module* mData;
};

} // namespace mozilla
356 changes: 201 additions & 155 deletions xpcom/components/nsCategoryManager.cpp

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions xpcom/components/nsCategoryManager.h
Original file line number Diff line number Diff line change
@@ -34,9 +34,7 @@ class nsIMemoryReporter;
class CategoryLeaf : public nsDepCharHashKey
{
public:
CategoryLeaf(const char* aKey)
: nsDepCharHashKey(aKey),
value(nullptr) { }
CategoryLeaf(const char* aKey) : nsDepCharHashKey(aKey), value(nullptr) {}
const char* value;
};

@@ -50,40 +48,40 @@ class CategoryNode
{
public:
NS_METHOD GetLeaf(const char* aEntryName,
char** _retval);
char** aResult);

NS_METHOD AddLeaf(const char* aEntryName,
const char* aValue,
bool aReplace,
char** _retval,
char** aResult,
PLArenaPool* aArena);

void DeleteLeaf(const char* aEntryName);

void Clear() {
void Clear()
{
mozilla::MutexAutoLock lock(mLock);
mTable.Clear();
}

uint32_t Count() {
uint32_t Count()
{
mozilla::MutexAutoLock lock(mLock);
uint32_t tCount = mTable.Count();
return tCount;
}

NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
NS_METHOD Enumerate(nsISimpleEnumerator** aResult);

// CategoryNode is arena-allocated, with the strings
static CategoryNode* Create(PLArenaPool* aArena);
~CategoryNode();
void operator delete(void*) { }
void operator delete(void*) {}

size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);

private:
CategoryNode()
: mLock("CategoryLeaf")
{ }
CategoryNode() : mLock("CategoryLeaf") {}

void* operator new(size_t aSize, PLArenaPool* aArena);

6 changes: 3 additions & 3 deletions xpcom/components/nsCategoryManagerUtils.h
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
#include "nsICategoryManager.h"

void
NS_CreateServicesFromCategory(const char *category,
nsISupports *origin,
const char *observerTopic);
NS_CreateServicesFromCategory(const char* aCategory,
nsISupports* aOrigin,
const char* aObserverTopic);

#endif
2,413 changes: 1,249 additions & 1,164 deletions xpcom/components/nsComponentManager.cpp

Large diffs are not rendered by default.

485 changes: 249 additions & 236 deletions xpcom/components/nsComponentManager.h

Large diffs are not rendered by default.

252 changes: 128 additions & 124 deletions xpcom/components/nsNativeModuleLoader.cpp
Original file line number Diff line number Diff line change
@@ -53,188 +53,192 @@

using namespace mozilla;

static PRLogModuleInfo *
static PRLogModuleInfo*
GetNativeModuleLoaderLog()
{
static PRLogModuleInfo *sLog;
if (!sLog)
sLog = PR_NewLogModule("nsNativeModuleLoader");
return sLog;
static PRLogModuleInfo* sLog;
if (!sLog) {
sLog = PR_NewLogModule("nsNativeModuleLoader");
}
return sLog;
}

#define LOG(level, args) PR_LOG(GetNativeModuleLoaderLog(), level, args)

nsresult
nsNativeModuleLoader::Init()
{
MOZ_ASSERT(NS_IsMainThread(), "Startup not on main thread?");
LOG(PR_LOG_DEBUG, ("nsNativeModuleLoader::Init()"));
return NS_OK;
MOZ_ASSERT(NS_IsMainThread(), "Startup not on main thread?");
LOG(PR_LOG_DEBUG, ("nsNativeModuleLoader::Init()"));
return NS_OK;
}

class LoadModuleMainThreadRunnable : public nsRunnable
{
public:
LoadModuleMainThreadRunnable(nsNativeModuleLoader* aLoader,
FileLocation &aFile)
: mManager(nsComponentManagerImpl::gComponentManager)
, mLoader(aLoader)
, mFile(aFile)
, mResult(nullptr)
{ }

NS_IMETHOD Run()
{
mResult = mLoader->LoadModule(mFile);
return NS_OK;
}
LoadModuleMainThreadRunnable(nsNativeModuleLoader* aLoader,
FileLocation& aFile)
: mManager(nsComponentManagerImpl::gComponentManager)
, mLoader(aLoader)
, mFile(aFile)
, mResult(nullptr)
{
}

NS_IMETHOD Run()
{
mResult = mLoader->LoadModule(mFile);
return NS_OK;
}

nsRefPtr<nsComponentManagerImpl> mManager;
nsNativeModuleLoader* mLoader;
FileLocation mFile;
const mozilla::Module* mResult;
nsRefPtr<nsComponentManagerImpl> mManager;
nsNativeModuleLoader* mLoader;
FileLocation mFile;
const mozilla::Module* mResult;
};

const mozilla::Module*
nsNativeModuleLoader::LoadModule(FileLocation &aFile)
nsNativeModuleLoader::LoadModule(FileLocation& aFile)
{
if (aFile.IsZip()) {
NS_ERROR("Binary components cannot be loaded from JARs");
return nullptr;
}
nsCOMPtr<nsIFile> file = aFile.GetBaseFile();
nsresult rv;

if (!NS_IsMainThread()) {
// If this call is off the main thread, synchronously proxy it
// to the main thread.
nsRefPtr<LoadModuleMainThreadRunnable> r = new LoadModuleMainThreadRunnable(this, aFile);
NS_DispatchToMainThread(r, NS_DISPATCH_SYNC);
return r->mResult;
}

nsCOMPtr<nsIHashable> hashedFile(do_QueryInterface(file));
if (!hashedFile) {
NS_ERROR("nsIFile is not nsIHashable");
return nullptr;
}

nsAutoCString filePath;
file->GetNativePath(filePath);

NativeLoadData data;

if (mLibraries.Get(hashedFile, &data)) {
NS_ASSERTION(data.mModule, "Corrupt mLibraries hash");
LOG(PR_LOG_DEBUG,
("nsNativeModuleLoader::LoadModule(\"%s\") - found in cache",
filePath.get()));
return data.mModule;
}
if (aFile.IsZip()) {
NS_ERROR("Binary components cannot be loaded from JARs");
return nullptr;
}
nsCOMPtr<nsIFile> file = aFile.GetBaseFile();
nsresult rv;

if (!NS_IsMainThread()) {
// If this call is off the main thread, synchronously proxy it
// to the main thread.
nsRefPtr<LoadModuleMainThreadRunnable> r =
new LoadModuleMainThreadRunnable(this, aFile);
NS_DispatchToMainThread(r, NS_DISPATCH_SYNC);
return r->mResult;
}

nsCOMPtr<nsIHashable> hashedFile(do_QueryInterface(file));
if (!hashedFile) {
NS_ERROR("nsIFile is not nsIHashable");
return nullptr;
}

nsAutoCString filePath;
file->GetNativePath(filePath);

NativeLoadData data;

if (mLibraries.Get(hashedFile, &data)) {
NS_ASSERTION(data.mModule, "Corrupt mLibraries hash");
LOG(PR_LOG_DEBUG,
("nsNativeModuleLoader::LoadModule(\"%s\") - found in cache",
filePath.get()));
return data.mModule;
}

// We haven't loaded this module before
{
// We haven't loaded this module before
{
#ifdef HAS_DLL_BLOCKLIST
AutoSetXPCOMLoadOnMainThread guard;
AutoSetXPCOMLoadOnMainThread guard;
#endif
rv = file->Load(&data.mLibrary);
}
rv = file->Load(&data.mLibrary);
}

if (NS_FAILED(rv)) {
char errorMsg[1024] = "<unknown; can't get error from NSPR>";
if (NS_FAILED(rv)) {
char errorMsg[1024] = "<unknown; can't get error from NSPR>";

if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
PR_GetErrorText(errorMsg);
if (PR_GetErrorTextLength() < (int)sizeof(errorMsg)) {
PR_GetErrorText(errorMsg);
}

LogMessage("Failed to load native module at path '%s': (%lx) %s",
filePath.get(), rv, errorMsg);
LogMessage("Failed to load native module at path '%s': (%lx) %s",
filePath.get(), rv, errorMsg);

return nullptr;
}
return nullptr;
}

#ifdef IMPLEMENT_BREAK_AFTER_LOAD
nsAutoCString leafName;
file->GetNativeLeafName(leafName);

char *env = getenv("XPCOM_BREAK_ON_LOAD");
char *blist;
if (env && *env && (blist = strdup(env))) {
char *nextTok = blist;
while (char *token = NS_strtok(":", &nextTok)) {
if (leafName.Find(token, true) != kNotFound) {
NS_BREAK();
}
}

free(blist);
}
#endif

void *module = PR_FindSymbol(data.mLibrary, "NSModule");
if (!module) {
LogMessage("Native module at path '%s' doesn't export symbol `NSModule`.",
filePath.get());
PR_UnloadLibrary(data.mLibrary);
return nullptr;
nsAutoCString leafName;
file->GetNativeLeafName(leafName);

char* env = getenv("XPCOM_BREAK_ON_LOAD");
char* blist;
if (env && *env && (blist = strdup(env))) {
char* nextTok = blist;
while (char* token = NS_strtok(":", &nextTok)) {
if (leafName.Find(token, true) != kNotFound) {
NS_BREAK();
}
}

data.mModule = *(mozilla::Module const *const *) module;
if (mozilla::Module::kVersion != data.mModule->mVersion) {
LogMessage("Native module at path '%s' is incompatible with this version of Firefox, has version %i, expected %i.",
filePath.get(), data.mModule->mVersion,
mozilla::Module::kVersion);
PR_UnloadLibrary(data.mLibrary);
return nullptr;
}
free(blist);
}
#endif

mLibraries.Put(hashedFile, data); // infallible
return data.mModule;
void* module = PR_FindSymbol(data.mLibrary, "NSModule");
if (!module) {
LogMessage("Native module at path '%s' doesn't export symbol `NSModule`.",
filePath.get());
PR_UnloadLibrary(data.mLibrary);
return nullptr;
}

data.mModule = *(mozilla::Module const* const*)module;
if (mozilla::Module::kVersion != data.mModule->mVersion) {
LogMessage("Native module at path '%s' is incompatible with this version of Firefox, has version %i, expected %i.",
filePath.get(), data.mModule->mVersion,
mozilla::Module::kVersion);
PR_UnloadLibrary(data.mLibrary);
return nullptr;
}

mLibraries.Put(hashedFile, data); // infallible
return data.mModule;
}

PLDHashOperator
nsNativeModuleLoader::ReleaserFunc(nsIHashable* aHashedFile,
NativeLoadData& aLoadData, void*)
{
aLoadData.mModule = nullptr;
return PL_DHASH_NEXT;
aLoadData.mModule = nullptr;
return PL_DHASH_NEXT;
}

PLDHashOperator
nsNativeModuleLoader::UnloaderFunc(nsIHashable* aHashedFile,
NativeLoadData& aLoadData, void*)
{
if (PR_LOG_TEST(GetNativeModuleLoaderLog(), PR_LOG_DEBUG)) {
nsCOMPtr<nsIFile> file(do_QueryInterface(aHashedFile));
if (PR_LOG_TEST(GetNativeModuleLoaderLog(), PR_LOG_DEBUG)) {
nsCOMPtr<nsIFile> file(do_QueryInterface(aHashedFile));

nsAutoCString filePath;
file->GetNativePath(filePath);
nsAutoCString filePath;
file->GetNativePath(filePath);

LOG(PR_LOG_DEBUG,
("nsNativeModuleLoader::UnloaderFunc(\"%s\")", filePath.get()));
}
LOG(PR_LOG_DEBUG,
("nsNativeModuleLoader::UnloaderFunc(\"%s\")", filePath.get()));
}

#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::SetActivityIsLegal(false);
nsTraceRefcnt::SetActivityIsLegal(false);
#endif

#if 0
// XXXbsmedberg: do this as soon as the static-destructor crash(es)
// are fixed
PRStatus ret = PR_UnloadLibrary(aLoadData.mLibrary);
NS_ASSERTION(ret == PR_SUCCESS, "Failed to unload library");
// XXXbsmedberg: do this as soon as the static-destructor crash(es)
// are fixed
PRStatus ret = PR_UnloadLibrary(aLoadData.mLibrary);
NS_ASSERTION(ret == PR_SUCCESS, "Failed to unload library");
#endif

#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::SetActivityIsLegal(true);
nsTraceRefcnt::SetActivityIsLegal(true);
#endif

return PL_DHASH_REMOVE;
return PL_DHASH_REMOVE;
}

void
nsNativeModuleLoader::UnloadLibraries()
{
MOZ_ASSERT(NS_IsMainThread(), "Shutdown not on main thread?");
mLibraries.Enumerate(ReleaserFunc, nullptr);
mLibraries.Enumerate(UnloaderFunc, nullptr);
MOZ_ASSERT(NS_IsMainThread(), "Shutdown not on main thread?");
mLibraries.Enumerate(ReleaserFunc, nullptr);
mLibraries.Enumerate(UnloaderFunc, nullptr);
}
35 changes: 16 additions & 19 deletions xpcom/components/nsNativeModuleLoader.h
Original file line number Diff line number Diff line change
@@ -16,32 +16,29 @@ class FileLocation;

class nsNativeModuleLoader MOZ_FINAL
{
public:
const mozilla::Module* LoadModule(mozilla::FileLocation &aFile);
public:
const mozilla::Module* LoadModule(mozilla::FileLocation& aFile);

nsresult Init();
nsresult Init();

void UnloadLibraries();
void UnloadLibraries();

private:
struct NativeLoadData
{
NativeLoadData()
: mModule(nullptr)
, mLibrary(nullptr)
{ }
private:
struct NativeLoadData
{
NativeLoadData() : mModule(nullptr), mLibrary(nullptr) {}

const mozilla::Module* mModule;
PRLibrary* mLibrary;
};
const mozilla::Module* mModule;
PRLibrary* mLibrary;
};

static PLDHashOperator
ReleaserFunc(nsIHashable* aHashedFile, NativeLoadData &aLoadData, void*);
static PLDHashOperator
ReleaserFunc(nsIHashable* aHashedFile, NativeLoadData& aLoadData, void*);

static PLDHashOperator
UnloaderFunc(nsIHashable* aHashedFile, NativeLoadData &aLoadData, void*);
static PLDHashOperator
UnloaderFunc(nsIHashable* aHashedFile, NativeLoadData& aLoadData, void*);

nsDataHashtable<nsHashableHashKey, NativeLoadData> mLibraries;
nsDataHashtable<nsHashableHashKey, NativeLoadData> mLibraries;
};

#endif /* nsNativeModuleLoader_h__ */

0 comments on commit 0827bb1

Please sign in to comment.