Part of bug 35559 - dynamic profile switching

r=valeski@netscape.com, sr=waterson@netscape.com


git-svn-id: svn://10.0.0.236/trunk@84857 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ccarlen%netscape.com
2001-01-12 15:04:58 +00:00
parent b3bd20131b
commit 14e6d43434
4 changed files with 61 additions and 6 deletions

View File

@@ -37,7 +37,8 @@
#include "nsFileStream.h"
#include "nsIComponentManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsIProfile.h"
#include "nsIProfileChangeStatus.h"
#include "nsIObserverService.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFService.h"
@@ -1683,6 +1684,14 @@ nsBookmarksService::Init()
}
}
// Register as an observer of profile changes
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ASSERTION(observerService, "Could not get observer service.");
if (observerService) {
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
}
// read in bookmarks AFTER trying to get string bundle
rv = ReadBookmarks();
if (NS_FAILED(rv)) return(rv);
@@ -2477,6 +2486,27 @@ nsBookmarksService::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
return(NS_OK);
}
// nsIObserver methods
NS_IMETHODIMP nsBookmarksService::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC))
{
// The profile has not changed yet.
rv = Flush();
}
else if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC))
{
// The profile has aleady changed.
rv = ReadBookmarks();
}
return rv;
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(nsBookmarksService);
@@ -2507,13 +2537,15 @@ nsBookmarksService::Release()
NS_IMPL_QUERY_INTERFACE6(nsBookmarksService,
NS_IMPL_QUERY_INTERFACE8(nsBookmarksService,
nsIBookmarksService,
nsIRDFDataSource,
nsIRDFRemoteDataSource,
nsIRDFObserver,
nsIStreamListener,
nsIStreamObserver)
nsIStreamObserver,
nsIObserver,
nsISupportsWeakReference)
////////////////////////////////////////////////////////////////////////
// nsIBookmarksService

View File

@@ -34,6 +34,8 @@
#include "nsIBookmarksService.h"
#include "nsString.h"
#include "nsIFileSpec.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#ifdef DEBUG
#ifdef XP_MAC
@@ -45,7 +47,9 @@ class nsBookmarksService : public nsIBookmarksService,
public nsIRDFDataSource,
public nsIRDFRemoteDataSource,
public nsIStreamListener,
public nsIRDFObserver
public nsIRDFObserver,
public nsIObserver,
public nsSupportsWeakReference
{
protected:
nsIRDFDataSource* mInner;
@@ -100,6 +104,9 @@ nsresult GetBookmarkToPing(nsIRDFResource **theBookmark);
// nsIStreamListener methods:
NS_DECL_NSISTREAMLISTENER
// nsIObserver methods:
NS_DECL_NSIOBSERVER
public:
nsBookmarksService();
virtual ~nsBookmarksService();

View File

@@ -28,7 +28,7 @@ include $(DEPTH)/config/autoconf.mk
MODULE = appcomps
LIBRARY_NAME = history_s
REQUIRES = xpcom rdf mork pref js
REQUIRES = xpcom rdf mork pref js profile
CPPSRCS = nsGlobalHistory.cpp \
$(NULL)

View File

@@ -58,6 +58,8 @@
#include "nsIMdbFactoryFactory.h"
#include "nsIPref.h"
#include "nsIProfileChangeStatus.h"
#include "nsIObserverService.h"
PRInt32 nsGlobalHistory::gRefCnt;
nsIRDFService* nsGlobalHistory::gRDFService;
@@ -1636,6 +1638,14 @@ nsGlobalHistory::Init()
// register this as a named data source with the RDF service
rv = gRDFService->RegisterDataSource(this, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// register to observe profile changes
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ASSERTION(observerService, "failed to get observer service");
if (observerService) {
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
}
rv = OpenDB();
NS_ENSURE_SUCCESS(rv, rv);
@@ -2084,12 +2094,13 @@ nsGlobalHistory::Observe(nsISupports *aSubject, const PRUnichar *aTopic,
{
nsresult rv;
nsLiteralString aTopicString(aTopic);
// topics we observe
NS_NAMED_LITERAL_STRING(prefChangedTopic, "nsPref:changed");
// pref changing - update member vars
if (prefChangedTopic.Equals(aTopic)) {
if (aTopicString.Equals(prefChangedTopic)) {
// expiration date
nsCAutoString pref; pref.AssignWithConversion(aSomeData);
@@ -2100,6 +2111,11 @@ nsGlobalHistory::Observe(nsISupports *aSubject, const PRUnichar *aTopic,
}
}
else if (aTopicString.Equals(PROFILE_BEFORE_CHANGE_TOPIC))
rv = CloseDB();
else if (aTopicString.Equals(PROFILE_DO_CHANGE_TOPIC))
rv = OpenDB();
return NS_OK;
}