diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 01155e2e0c2..79f66cdee82 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -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 diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h index 456b40eae14..83d50559a7b 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h @@ -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(); diff --git a/mozilla/xpfe/components/history/src/Makefile.in b/mozilla/xpfe/components/history/src/Makefile.in index c62d3f66b8c..7ce5868c087 100644 --- a/mozilla/xpfe/components/history/src/Makefile.in +++ b/mozilla/xpfe/components/history/src/Makefile.in @@ -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) diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index a2054d1f6c2..19764f31780 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -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; }