Bug 458812 - Remove support for importing from old mork-based formhistory.dat. r=vladimir
authorJustin Dolske <dolske@mozilla.com>
Sun, 13 Dec 2009 17:04:41 -0800
changeset 35688 faf866398f1760da768b9a45b600e84378275823
parent 35687 19c480485f4f0eb7e87fc12757857604ff7217c9
child 35689 ec5877cfb2178a0c1ce3ce79e58831c1fe376b53
push id10681
push userjdolske@mozilla.com
push dateMon, 14 Dec 2009 01:05:05 +0000
treeherdermozilla-central@ec5877cfb217 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladimir
bugs458812
milestone1.9.3a1pre
Bug 458812 - Remove support for importing from old mork-based formhistory.dat. r=vladimir
toolkit/components/autocomplete/src/Makefile.in
toolkit/components/build/nsToolkitCompsCID.h
toolkit/components/satchel/public/nsIFormHistory.idl
toolkit/components/satchel/src/Makefile.in
toolkit/components/satchel/src/nsFormFillController.cpp
toolkit/components/satchel/src/nsStorageFormHistory.cpp
toolkit/components/satchel/src/nsStorageFormHistory.h
toolkit/components/satchel/test/unit/head_satchel.js
toolkit/components/satchel/test/unit/test_bug_329741.js
--- a/toolkit/components/autocomplete/src/Makefile.in
+++ b/toolkit/components/autocomplete/src/Makefile.in
@@ -56,13 +56,9 @@ CPPSRCS = nsAutoCompleteController.cpp \
           nsAutoCompleteSimpleResult.cpp \
           $(NULL)
 
 EXTRA_DSO_LDOPTS += \
 	$(MOZ_UNICHARUTIL_LIBS) \
 	$(MOZ_COMPONENT_LIBS) \
 	$(NULL)
 
-ifdef MOZ_MORKREADER
-EXTRA_DSO_LDOPTS += $(DEPTH)/db/morkreader/$(LIB_PREFIX)morkreader_s.$(LIB_SUFFIX)
-endif
-
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/components/build/nsToolkitCompsCID.h
+++ b/toolkit/components/build/nsToolkitCompsCID.h
@@ -58,19 +58,16 @@
   "@mozilla.org/autocomplete/mdb-result;1"
 
 #define NS_DOWNLOADMANAGER_CONTRACTID \
   "@mozilla.org/download-manager;1"
 
 #define NS_FORMHISTORY_CONTRACTID \
   "@mozilla.org/satchel/form-history;1"
 
-#define NS_FORMHISTORYIMPORTER_CONTRACTID \
-  "@mozilla.org/satchel/form-history-importer;1"
-
 #define NS_FORMFILLCONTROLLER_CONTRACTID \
   "@mozilla.org/satchel/form-fill-controller;1"
 
 #define NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID \
   "@mozilla.org/autocomplete/search;1?name=form-history"
 
 #define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \
   "@mozilla.org/rdf/datasource;1?name=history"
@@ -144,20 +141,16 @@
 // {895DB6C7-DBDF-40ea-9F64-B175033243DC}
 #define NS_FORMFILLCONTROLLER_CID \
 { 0x895db6c7, 0xdbdf, 0x40ea, { 0x9f, 0x64, 0xb1, 0x75, 0x3, 0x32, 0x43, 0xdc } }
 
 // {A2059C0E-5A58-4c55-AB7C-26F0557546EF}
 #define NS_FORMHISTORY_CID \
 { 0xa2059c0e, 0x5a58, 0x4c55, { 0xab, 0x7c, 0x26, 0xf0, 0x55, 0x75, 0x46, 0xef } }
 
-// {db340cc2-7f50-4ea3-8427-f529daf6dc87}
-#define NS_FORMHISTORYIMPORTER_CID \
-{ 0xdb340cc2, 0x7f50, 0x4ea3, { 0x84, 0x27, 0xf5, 0x29, 0xda, 0xf6, 0xdc, 0x87 } }
-
 // {59648a91-5a60-4122-8ff2-54b839c84aed}
 #define NS_GLOBALHISTORY_CID \
 { 0x59648a91, 0x5a60, 0x4122, { 0x8f, 0xf2, 0x54, 0xb8, 0x39, 0xc8, 0x4a, 0xed} }
 
 // {59648a91-5a60-4122-8ff2-54b839c84aed}
 #define NS_PARENTALCONTROLSSERVICE_CID \
 { 0x580530e5, 0x118c, 0x4bc7, { 0xab, 0x88, 0xbc, 0x2c, 0xd2, 0xb9, 0x72, 0x23 } }
 
--- a/toolkit/components/satchel/public/nsIFormHistory.idl
+++ b/toolkit/components/satchel/public/nsIFormHistory.idl
@@ -98,26 +98,8 @@ interface nsIFormHistory2 : nsISupports
    */
   void removeEntriesByTimeframe(in long long aBeginTime, in long long aEndTime);
 
   /**
    * Returns the underlying DB connection the form history module is using.
    */
   readonly attribute mozIStorageConnection DBConnection;
 };
-
-/**
- * nsIFormHistoryImporter is an interface for importing a Mork formhistory.dat
- * file into the new form history storage.
- */
-
-[scriptable, uuid(9e811188-6a5b-4d96-a92d-1bac66a41898)]
-interface nsIFormHistoryImporter : nsISupports
-{
-  /**
-   * Import the given Mork form history file.
-   *  @param file     The Mork form history file to import
-   *  @param history  A reference to the nsIFormHistory.  This is
-   *                  supplied since the importer is invoked during
-   *                  form history initialization.
-   */
-  void importFormHistory(in nsIFile file, in nsIFormHistory2 formHistory);
-};
--- a/toolkit/components/satchel/src/Makefile.in
+++ b/toolkit/components/satchel/src/Makefile.in
@@ -68,12 +68,8 @@ EXTRA_DSO_LIBS	= gkgfx
 include $(topsrcdir)/config/rules.mk
 
 EXTRA_DSO_LDOPTS += \
 	$(LIBS_DIR) \
 	$(EXTRA_DSO_LIBS) \
 	$(MOZ_UNICHARUTIL_LIBS) \
 	$(MOZ_COMPONENT_LIBS) \
 	$(NULL)
-
-ifdef MOZ_MORKREADER
-EXTRA_DSO_LDOPTS += $(DEPTH)/db/morkreader/$(LIB_PREFIX)morkreader_s.$(LIB_SUFFIX)
-endif
--- a/toolkit/components/satchel/src/nsFormFillController.cpp
+++ b/toolkit/components/satchel/src/nsFormFillController.cpp
@@ -1208,19 +1208,16 @@ nsFormFillController::IsEventTrusted(nsI
   PRBool isTrusted;
   rv = nsevent->GetIsTrusted(&isTrusted);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
   return isTrusted;
 }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFormHistory, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormFillController)
-#ifdef MOZ_MORKREADER
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormHistoryImporter)
-#endif
 
 static const nsModuleComponentInfo components[] =
 {
   { "HTML Form History",
     NS_FORMHISTORY_CID, 
     NS_FORMHISTORY_CONTRACTID,
     nsFormHistoryConstructor },
 
@@ -1228,19 +1225,12 @@ static const nsModuleComponentInfo compo
     NS_FORMFILLCONTROLLER_CID, 
     "@mozilla.org/satchel/form-fill-controller;1",
     nsFormFillControllerConstructor },
 
   { "HTML Form History AutoComplete",
     NS_FORMFILLCONTROLLER_CID, 
     NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID,
     nsFormFillControllerConstructor },
-
-#ifdef MOZ_MORKREADER
-  { "Form History Importer",
-    NS_FORMHISTORYIMPORTER_CID,
-    NS_FORMHISTORYIMPORTER_CONTRACTID,
-    nsFormHistoryImporterConstructor },
-#endif
 };
 
 NS_IMPL_NSGETMODULE(satchel, components)
 
--- a/toolkit/components/satchel/src/nsStorageFormHistory.cpp
+++ b/toolkit/components/satchel/src/nsStorageFormHistory.cpp
@@ -119,32 +119,16 @@ nsFormHistory::Init()
     /* If the DB is corrupt, nuke it and try again with a new DB. */
     rv = dbCleanup();
     NS_ENSURE_SUCCESS(rv, rv);
     rv = OpenDatabase(&doImport);
     doImport = PR_FALSE;
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
-#ifdef MOZ_MORKREADER
-  if (doImport) {
-    // Locate the old formhistory.dat file and import it.
-    nsCOMPtr<nsIFile> historyFile;
-    rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
-                                getter_AddRefs(historyFile));
-    if (NS_SUCCEEDED(rv)) {
-      historyFile->Append(NS_LITERAL_STRING("formhistory.dat"));
-
-      nsCOMPtr<nsIFormHistoryImporter> importer = new nsFormHistoryImporter();
-      NS_ENSURE_TRUE(importer, NS_ERROR_OUT_OF_MEMORY);
-      importer->ImportFormHistory(historyFile, this);
-    }
-  }
-#endif
-
   nsCOMPtr<nsIObserverService> service = do_GetService("@mozilla.org/observer-service;1");
   if (service) {
     service->AddObserver(this, NS_EARLYFORMSUBMIT_SUBJECT, PR_TRUE);
     service->AddObserver(this, "idle-daily", PR_TRUE);
     service->AddObserver(this, "formhistory-expire-now", PR_TRUE);
   }
 
   return NS_OK;
@@ -805,192 +789,8 @@ nsFormHistory::dbAreExpectedColumnsPrese
 {
   // If the statement succeeds, all the columns are there.
   nsCOMPtr<mozIStorageStatement> stmt;
   nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
                   "SELECT fieldname, value, timesUsed, firstUsed, lastUsed "
                   "FROM moz_formhistory"), getter_AddRefs(stmt));
   return NS_SUCCEEDED(rv) ? PR_TRUE : PR_FALSE;
 }
-
-
-#ifdef MOZ_MORKREADER
-
-// Columns for form history rows
-enum {
-  kNameColumn,
-  kValueColumn,
-  kColumnCount // keep me last
-};
-
-static const char * const gColumnNames[] = {
-  "Name", "Value"
-};
-
-struct FormHistoryImportClosure
-{
-  FormHistoryImportClosure(nsMorkReader *aReader, nsIFormHistory2 *aFormHistory)
-    : reader(aReader), formHistory(aFormHistory), byteOrderColumn(-1),
-      swapBytes(PR_FALSE)
-  {
-    for (PRUint32 i = 0; i < kColumnCount; ++i) {
-      columnIndexes[i] = -1;
-    }
-  }
-
-  // Back pointers to the reader and history we're operating on
-  const nsMorkReader *reader;
-  nsIFormHistory2 *formHistory;
-
-  // Indexes of the columns that we care about
-  PRInt32 columnIndexes[kColumnCount];
-  PRInt32 byteOrderColumn;
-
-  // Whether we need to swap bytes (file format is other-endian)
-  PRPackedBool swapBytes;
-};
-
-// Reverses the high and low bytes in a PRUnichar buffer.
-// This is used if the file format has a different endianness from the
-// current architecture.
-static void SwapBytes(PRUnichar* aBuffer)
-{
-  for (PRUnichar *b = aBuffer; *b; b++)
-  {
-    PRUnichar c = *b;
-    *b = (0xff & (c >> 8)) | (c << 8);
-  }
-}
-
-// Enumerator callback to add an entry to the FormHistory
-/* static */ PLDHashOperator
-nsFormHistoryImporter::AddToFormHistoryCB(const nsCSubstring &aRowID,
-                                          const nsTArray<nsCString> *aValues,
-                                          void *aData)
-{
-  FormHistoryImportClosure *data = static_cast<FormHistoryImportClosure*>
-                                              (aData);
-  const nsMorkReader *reader = data->reader;
-  nsCString values[kColumnCount];
-  const PRUnichar* valueStrings[kColumnCount];
-  PRUint32 valueLengths[kColumnCount];
-  const PRInt32 *columnIndexes = data->columnIndexes;
-  PRInt32 i;
-
-  // Values are in UTF16.
-
-  for (i = 0; i < kColumnCount; ++i) {
-    if (columnIndexes[i] == -1) {
-      // We didn't find this column in the map
-      continue;
-    }
-
-    values[i] = (*aValues)[columnIndexes[i]];
-    reader->NormalizeValue(values[i]);
-
-    PRUint32 length;
-    const char *bytes;
-    if (values[i].IsEmpty()) {
-      bytes = "\0";
-      length = 0;
-    } else {
-      length = values[i].Length() / 2;
-
-      // add an extra null byte onto the end, so that the buffer ends
-      // with a complete unicode null character.
-      values[i].Append('\0');
-
-      // Swap the bytes in the unicode characters if necessary.
-      if (data->swapBytes) {
-        SwapBytes(reinterpret_cast<PRUnichar*>(values[i].BeginWriting()));
-      }
-      bytes = values[i].get();
-    }
-    valueStrings[i] = reinterpret_cast<const PRUnichar*>(bytes);
-    valueLengths[i] = length;
-  }
-
-  data->formHistory->AddEntry(nsDependentString(valueStrings[kNameColumn],
-                                                valueLengths[kNameColumn]),
-                              nsDependentString(valueStrings[kValueColumn],
-                                                valueLengths[kValueColumn]));
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_ISUPPORTS1(nsFormHistoryImporter, nsIFormHistoryImporter)
-
-NS_IMETHODIMP
-nsFormHistoryImporter::ImportFormHistory(nsIFile *aFile,
-                                         nsIFormHistory2 *aFormHistory)
-{
-  // Check that the file exists before we try to open it
-  PRBool exists;
-  aFile->Exists(&exists);
-  if (!exists) {
-    return NS_OK;
-  }
-  
-  nsMorkReader reader;
-  nsresult rv = reader.Init();
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = reader.Read(aFile);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Gather up the column ids so we don't need to find them on each row
-  FormHistoryImportClosure data(&reader, aFormHistory);
-  const nsTArray<nsMorkReader::MorkColumn> columns = reader.GetColumns();
-  for (PRUint32 i = 0; i < columns.Length(); ++i) {
-    const nsCSubstring &name = columns[i].name;
-    for (PRUint32 j = 0; j < kColumnCount; ++j) {
-      if (name.Equals(gColumnNames[j])) {
-        data.columnIndexes[j] = i;
-        break;
-      }
-    }
-    if (name.EqualsLiteral("ByteOrder")) {
-      data.byteOrderColumn = i;
-    }
-  }
-
-  // Determine the byte order from the table's meta-row.
-  const nsTArray<nsCString> *metaRow = reader.GetMetaRow();
-  if (metaRow && data.byteOrderColumn != -1) {
-    const nsCString &byteOrder = (*metaRow)[data.byteOrderColumn];
-    // Note whether the file uses a non-native byte ordering.
-    // If it does, we'll have to swap bytes for PRUnichar values.
-    // "BBBB" and "llll" are the only recognized values, anything
-    // else is garbage and the file will be treated as native-endian
-    // (no swapping).
-    nsCAutoString byteOrderValue(byteOrder);
-    reader.NormalizeValue(byteOrderValue);
-#ifdef IS_LITTLE_ENDIAN
-    data.swapBytes = byteOrderValue.EqualsLiteral("BBBB");
-#else
-    data.swapBytes = byteOrderValue.EqualsLiteral("llll");
-#endif
-  }
-#if defined(XP_MACOSX) && defined(IS_LITTLE_ENDIAN)
-  // The meta row and its ByteOrder field was introduced in 1.8.0.2.
-  // If it's not present, treat the formhistory db as using native byte
-  // ordering (as was done prior to 1.8.0.2).
-  // Exception: the ByteOrder field was always present since the initial
-  // x86 Mac release, so if we're on one of those, and the file doesn't
-  // have a ByteOrder field, it most likely came from a ppc Mac and needs
-  // its bytes swapped.  nsFormHistory in 1.8.0.2 swapped the bytes, this
-  // importer should behave the same way.
-  else {
-    data.swapBytes = PR_TRUE;
-  }
-#endif
-
-  // Add the rows to form history
-  nsCOMPtr<nsIFormHistoryPrivate> fhPrivate = do_QueryInterface(aFormHistory);
-  NS_ENSURE_TRUE(fhPrivate, NS_ERROR_FAILURE);
-
-  mozIStorageConnection *conn = fhPrivate->GetStorageConnection();
-  NS_ENSURE_TRUE(conn, NS_ERROR_NOT_INITIALIZED);
-  mozStorageTransaction transaction(conn, PR_FALSE);
-
-  reader.EnumerateRows(AddToFormHistoryCB, &data);
-  return transaction.Commit();
-}
-#endif
--- a/toolkit/components/satchel/src/nsStorageFormHistory.h
+++ b/toolkit/components/satchel/src/nsStorageFormHistory.h
@@ -48,19 +48,16 @@
 #include "nsWeakReference.h"
 
 #include "mozIStorageService.h"
 #include "mozIStorageConnection.h"
 #include "mozIStorageStatement.h"
 
 #include "nsServiceManagerUtils.h"
 #include "nsToolkitCompsCID.h"
-#ifdef MOZ_MORKREADER
-#include "nsMorkReader.h"
-#endif
 
 class nsIAutoCompleteSimpleResult;
 class nsIAutoCompleteResult;
 class nsFormHistory;
 template <class E> class nsTArray;
 
 #define NS_IFORMHISTORYPRIVATE_IID \
 {0xc4a47315, 0xaeb5, 0x4039, {0x9f, 0x34, 0x45, 0x11, 0xb3, 0xa7, 0x58, 0xdd}}
@@ -126,25 +123,9 @@ public:
   nsCOMPtr<mozIStorageService> mStorageService;
   nsCOMPtr<mozIStorageStatement> mDBFindEntry;
   nsCOMPtr<mozIStorageStatement> mDBFindEntryByName;
   nsCOMPtr<mozIStorageStatement> mDBSelectEntries;
   nsCOMPtr<mozIStorageStatement> mDBInsertNameValue;
   nsCOMPtr<mozIStorageStatement> mDBUpdateEntry;
 };
 
-#ifdef MOZ_MORKREADER
-class nsFormHistoryImporter : public nsIFormHistoryImporter
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIFORMHISTORYIMPORTER
-
-private:
-  // Enumerator callback to add a single row to the FormHistory.
-  static PLDHashOperator
-  AddToFormHistoryCB(const nsCSubstring &aRowID,
-                     const nsTArray<nsCString> *aValues,
-                     void *aData);
-};
-#endif
-
 #endif // __nsFormHistory__
--- a/toolkit/components/satchel/test/unit/head_satchel.js
+++ b/toolkit/components/satchel/test/unit/head_satchel.js
@@ -50,16 +50,8 @@ function getDBVersion(dbfile) {
     var ss = Cc["@mozilla.org/storage/service;1"].
              getService(Ci.mozIStorageService);
     var dbConnection = ss.openDatabase(dbfile);
     var version = dbConnection.schemaVersion;
     dbConnection.close();
 
     return version;
 }
-
-function cleanUpFormHist() {
-  var formhistFile = dirSvc.get("ProfD", Ci.nsIFile);
-  formhistFile.append("formhistory.dat");
-  if (formhistFile.exists())
-    formhistFile.remove(false);
-}
-cleanUpFormHist();
--- a/toolkit/components/satchel/test/unit/test_bug_329741.js
+++ b/toolkit/components/satchel/test/unit/test_bug_329741.js
@@ -30,25 +30,33 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Test to make sure we drop formhistory.dat when clearing form logins
+// Test to make sure we drop formhistory.dat when clearing form history
 
 
 
 function run_test()
 {
   var file = do_get_file("formhistory.dat");
   var formhistFile = dirSvc.get("ProfD", Ci.nsIFile);
+
+  // Cleanup from any previous test.
+  if (formhistFile.exists())
+      formhistFile.remove(false);
+  do_check_false(formhistFile.exists());
+
+  // Copy a formhistory.dat into place
   file.copyTo(formhistFile, "formhistory.dat");
   formhistFile.append("formhistory.dat");
   do_check_true(formhistFile.exists());
 
+  // Clear form history, test that file was deleted.
   var formHistory = Cc["@mozilla.org/satchel/form-history;1"].
                     getService(Ci.nsIFormHistory2);
   formHistory.removeAllEntries();
   do_check_false(formhistFile.exists());
 }