Bug 918223 - Make sure to save persdict.dat. r=ehsan, a=akeybl
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 19 Sep 2013 22:27:03 +0300
changeset 160388 5a81435e6cc7ba54a1d648c981ef7e63bc485a65
parent 160387 c01876298cb0d5565bd502c2655c66b973530e96
child 160389 e9e0d1bf1425f75629752c84b76ba5c1c29ecb55
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, akeybl
bugs918223
milestone26.0a2
Bug 918223 - Make sure to save persdict.dat. r=ehsan, a=akeybl
extensions/spellcheck/src/mozPersonalDictionary.cpp
--- a/extensions/spellcheck/src/mozPersonalDictionary.cpp
+++ b/extensions/spellcheck/src/mozPersonalDictionary.cpp
@@ -53,24 +53,25 @@ mozPersonalDictionary::mozPersonalDictio
 }
 
 mozPersonalDictionary::~mozPersonalDictionary()
 {
 }
 
 nsresult mozPersonalDictionary::Init()
 {
-  nsresult rv;
-  nsCOMPtr<nsIObserverService> svc = 
-           do_GetService("@mozilla.org/observer-service;1", &rv);
-   
-  if (NS_SUCCEEDED(rv) && svc) 
-    rv = svc->AddObserver(this, "profile-do-change", true); // we want to reload the dictionary if the profile switches
+  nsCOMPtr<nsIObserverService> svc =
+    do_GetService("@mozilla.org/observer-service;1");
 
-  if (NS_FAILED(rv)) return rv;
+  NS_ENSURE_STATE(svc);
+  // we want to reload the dictionary if the profile switches
+  nsresult rv = svc->AddObserver(this, "profile-do-change", true);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = svc->AddObserver(this, "profile-before-change", true);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   Load();
   
   return NS_OK;
 }
 
 /* void Load (); */
 NS_IMETHODIMP mozPersonalDictionary::Load()
@@ -251,13 +252,15 @@ NS_IMETHODIMP mozPersonalDictionary::Get
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */
 NS_IMETHODIMP mozPersonalDictionary::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
 {
   if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
     Load();  // load automatically clears out the existing dictionary table
+  } else if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
+    Save();
   }
 
   return NS_OK;
 }