Back out changeset 0b3af3fef0fd (bug 580790) due to burnage on a CLOSED TREE

This commit is contained in:
Shawn Wilsher 2010-08-06 10:45:16 -07:00
parent 81a95c1bf9
commit 410da73954
3 changed files with 14 additions and 46 deletions

View File

@ -48,6 +48,8 @@
#include "nsHashSets.h" #include "nsHashSets.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsAutoLock.h" #include "nsAutoLock.h"
@ -77,6 +79,8 @@ PRLogModuleInfo* gStorageLog = nsnull;
namespace mozilla { namespace mozilla {
namespace storage { namespace storage {
#define PREF_TS_SYNCHRONOUS "toolkit.storage.synchronous"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//// Variant Specialization Functions (variantToSQLiteT) //// Variant Specialization Functions (variantToSQLiteT)
@ -433,8 +437,13 @@ Connection::initialize(nsIFile *aDatabaseFile)
return convertResultCode(srv); return convertResultCode(srv);
} }
// Set the synchronous PRAGMA, according to the preference. // Set the synchronous PRAGMA, according to the pref
switch (Service::getSynchronousPref()) { nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
PRInt32 synchronous = 1; // Default to NORMAL if pref not set
if (pref)
(void)pref->GetIntPref(PREF_TS_SYNCHRONOUS, &synchronous);
switch (synchronous) {
case 2: case 2:
(void)ExecuteSimpleSQL(NS_LITERAL_CSTRING( (void)ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"PRAGMA synchronous = FULL;")); "PRAGMA synchronous = FULL;"));

View File

@ -42,7 +42,7 @@
#include "mozStorageService.h" #include "mozStorageService.h"
#include "mozStorageConnection.h" #include "mozStorageConnection.h"
#include "pratom.h" #include "prinit.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCollationCID.h" #include "nsCollationCID.h"
#include "nsEmbedCID.h" #include "nsEmbedCID.h"
@ -53,8 +53,6 @@
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "sqlite3.h" #include "sqlite3.h"
@ -63,12 +61,6 @@
#include "mozilla/FunctionTimer.h" #include "mozilla/FunctionTimer.h"
////////////////////////////////////////////////////////////////////////////////
//// Defines
#define PREF_TS_SYNCHRONOUS "toolkit.storage.synchronous"
#define PREF_TS_SYNCHRONOUS_DEFAULT 1
namespace mozilla { namespace mozilla {
namespace storage { namespace storage {
@ -112,11 +104,9 @@ class ServiceMainThreadInitializer : public nsRunnable
{ {
public: public:
ServiceMainThreadInitializer(nsIObserver *aObserver, ServiceMainThreadInitializer(nsIObserver *aObserver,
nsIXPConnect **aXPConnectPtr, nsIXPConnect **aXPConnectPtr)
PRInt32 *aSynchronousPrefValPtr)
: mObserver(aObserver) : mObserver(aObserver)
, mXPConnectPtr(aXPConnectPtr) , mXPConnectPtr(aXPConnectPtr)
, mSynchronousPrefValPtr(aSynchronousPrefValPtr)
{ {
} }
@ -142,15 +132,6 @@ public:
// used on the main thread. // used on the main thread.
(void)CallGetService(nsIXPConnect::GetCID(), mXPConnectPtr); (void)CallGetService(nsIXPConnect::GetCID(), mXPConnectPtr);
// 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.
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
PRInt32 synchronous = PREF_TS_SYNCHRONOUS_DEFAULT;
if (pref)
(void)pref->GetIntPref(PREF_TS_SYNCHRONOUS, &synchronous);
::PR_AtomicSet(mSynchronousPrefValPtr, synchronous);
// Register our SQLite memory reporters. Registration can only happen on // Register our SQLite memory reporters. Registration can only happen on
// the main thread (otherwise you'll get cryptic crashes). // the main thread (otherwise you'll get cryptic crashes).
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(StorageSQLitePageCacheMemoryUsed)); NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(StorageSQLitePageCacheMemoryUsed));
@ -162,7 +143,6 @@ public:
private: private:
nsIObserver *mObserver; nsIObserver *mObserver;
nsIXPConnect **mXPConnectPtr; nsIXPConnect **mXPConnectPtr;
PRInt32 *mSynchronousPrefValPtr;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -212,7 +192,6 @@ Service::getSingleton()
nsIXPConnect *Service::sXPConnect = nsnull; nsIXPConnect *Service::sXPConnect = nsnull;
// static
already_AddRefed<nsIXPConnect> already_AddRefed<nsIXPConnect>
Service::getXPConnect() Service::getXPConnect()
{ {
@ -230,15 +209,6 @@ Service::getXPConnect()
return xpc.forget(); return xpc.forget();
} }
PRInt32 Service::sSynchronousPref;
// static
PRInt32
Service::getSynchronousPref()
{
return sSynchronousPref;
}
Service::Service() Service::Service()
: mMutex("Service::mMutex") : mMutex("Service::mMutex")
{ {
@ -287,13 +257,9 @@ Service::initialize()
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
return convertResultCode(rc); return convertResultCode(rc);
// Set the default value for the toolkit.storage.synchronous pref. It will be
// updated with the user preference on the main thread.
sSynchronousPref = PREF_TS_SYNCHRONOUS_DEFAULT;
// Run the things that need to run on the main thread there. // Run the things that need to run on the main thread there.
nsCOMPtr<nsIRunnable> event = nsCOMPtr<nsIRunnable> event =
new ServiceMainThreadInitializer(this, &sXPConnect, &sSynchronousPref); new ServiceMainThreadInitializer(this, &sXPConnect);
if (event && ::NS_IsMainThread()) { if (event && ::NS_IsMainThread()) {
(void)event->Run(); (void)event->Run();
} }

View File

@ -94,11 +94,6 @@ public:
*/ */
static already_AddRefed<nsIXPConnect> getXPConnect(); static already_AddRefed<nsIXPConnect> getXPConnect();
/**
* Obtains the cached data for the toolkit.storage.synchronous preference.
*/
static PRInt32 getSynchronousPref();
private: private:
Service(); Service();
virtual ~Service(); virtual ~Service();
@ -138,8 +133,6 @@ private:
static Service *gService; static Service *gService;
static nsIXPConnect *sXPConnect; static nsIXPConnect *sXPConnect;
static PRInt32 sSynchronousPref;
}; };
} // namespace storage } // namespace storage