Skip to content

Commit

Permalink
Bug 1414441 - Stop caching an XPConnect pointer in storage/. r=mak
Browse files Browse the repository at this point in the history
Services.h has a built in cache now

MozReview-Commit-ID: 362qIrzf13F
  • Loading branch information
amccreight committed Nov 3, 2017
1 parent b4f522c commit d226944
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
37 changes: 0 additions & 37 deletions storage/mozStorageService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,6 @@ Service::getSingleton()
return service.forget();
}

nsIXPConnect *Service::sXPConnect = nullptr;

// static
already_AddRefed<nsIXPConnect>
Service::getXPConnect()
{
NS_PRECONDITION(NS_IsMainThread(),
"Must only get XPConnect on the main thread!");
NS_PRECONDITION(gService,
"Can not get XPConnect without an instance of our service!");

// If we've been shutdown, sXPConnect will be null. To prevent leaks, we do
// not cache the service after this point.
nsCOMPtr<nsIXPConnect> xpc(sXPConnect);
if (!xpc)
xpc = do_GetService(nsIXPConnect::GetCID());
NS_ASSERTION(xpc, "Could not get XPConnect!");
return xpc.forget();
}

int32_t Service::sSynchronousPref;

// static
Expand Down Expand Up @@ -279,8 +259,6 @@ Service::~Service()
if (rc != SQLITE_OK)
NS_WARNING("Failed to unregister sqlite vfs wrapper.");

shutdown(); // To release sXPConnect.

gService = nullptr;
delete mSqliteVFS;
mSqliteVFS = nullptr;
Expand Down Expand Up @@ -395,18 +373,11 @@ Service::minimizeMemory()
}
}

void
Service::shutdown()
{
NS_IF_RELEASE(sXPConnect);
}

sqlite3_vfs *ConstructTelemetryVFS();
const char *GetVFSName();

static const char* sObserverTopics[] = {
"memory-pressure",
"xpcom-shutdown",
"xpcom-shutdown-threads"
};

Expand All @@ -428,8 +399,6 @@ Service::initialize()
NS_WARNING("Failed to register telemetry VFS");
}

// Register for xpcom-shutdown so we can cleanup after ourselves. The
// observer service can only be used on the main thread.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);

Expand All @@ -440,10 +409,6 @@ Service::initialize()
}
}

// We cache XPConnect for our language helpers. XPConnect can only be
// used on the main thread.
(void)CallGetService(nsIXPConnect::GetCID(), &sXPConnect);

// We need to obtain the toolkit.storage.synchronous preferences on the main
// thread because the preference service can only be accessed there. This
// is cached in the service for all future Open[Unshared]Database calls.
Expand Down Expand Up @@ -804,8 +769,6 @@ Service::Observe(nsISupports *, const char *aTopic, const char16_t *)
{
if (strcmp(aTopic, "memory-pressure") == 0) {
minimizeMemory();
} else if (strcmp(aTopic, "xpcom-shutdown") == 0) {
shutdown();
} else if (strcmp(aTopic, "xpcom-shutdown-threads") == 0) {
// The Service is kept alive by our strong observer references and
// references held by Connection instances. Since we're about to remove the
Expand Down
14 changes: 0 additions & 14 deletions storage/mozStorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "mozIStorageService.h"

class nsIMemoryReporter;
class nsIXPConnect;
struct sqlite3_vfs;

namespace mozilla {
Expand Down Expand Up @@ -59,12 +58,6 @@ class Service : public mozIStorageService
NS_DECL_NSIOBSERVER
NS_DECL_NSIMEMORYREPORTER

/**
* Obtains an already AddRefed pointer to XPConnect. This is used by
* language helpers.
*/
static already_AddRefed<nsIXPConnect> getXPConnect();

/**
* Obtains the cached data for the toolkit.storage.synchronous preference.
*/
Expand Down Expand Up @@ -156,11 +149,6 @@ class Service : public mozIStorageService
*/
void minimizeMemory();

/**
* Shuts down the storage service, freeing all of the acquired resources.
*/
void shutdown();

/**
* Lazily creates and returns a collation created from the application's
* locale that all statements of all Connections of this Service may use.
Expand All @@ -185,8 +173,6 @@ class Service : public mozIStorageService

static Service *gService;

static nsIXPConnect *sXPConnect;

static int32_t sSynchronousPref;
static int32_t sDefaultPageSize;
};
Expand Down
4 changes: 3 additions & 1 deletion storage/mozStorageStatementJSHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "xpc_make_class.h"

#include "mozilla/Services.h"

namespace mozilla {
namespace storage {

Expand All @@ -33,7 +35,7 @@ stepFunc(JSContext *aCtx,
uint32_t,
JS::Value *_vp)
{
nsCOMPtr<nsIXPConnect> xpc(Service::getXPConnect());
nsCOMPtr<nsIXPConnect> xpc(mozilla::services::GetXPConnect());
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
JSObject *obj = JS_THIS_OBJECT(aCtx, _vp);
if (!obj) {
Expand Down

0 comments on commit d226944

Please sign in to comment.