Bug 1524687: Part 4 - Convert Places module to static registration. r=mak
☠☠ backed out by 3b1b94e39795 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Thu, 24 Jan 2019 15:46:19 -0800
changeset 458964 c58caf41bb94
parent 458963 df95a56dae04
child 458965 191afe83da2e
push id111908
push usermaglione.k@gmail.com
push dateThu, 14 Feb 2019 02:29:45 +0000
treeherdermozilla-inbound@625f71135038 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1524687
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1524687: Part 4 - Convert Places module to static registration. r=mak Differential Revision: https://phabricator.services.mozilla.com/D18399
extensions/cookie/test/unit/test_permmanager_migrate_4-7_no_history.js
toolkit/components/places/FaviconHelpers.cpp
toolkit/components/places/components.conf
toolkit/components/places/moz.build
toolkit/components/places/nsAnnotationService.h
toolkit/components/places/nsFaviconService.cpp
toolkit/components/places/nsFaviconService.h
toolkit/components/places/nsPlacesModule.cpp
--- a/extensions/cookie/test/unit/test_permmanager_migrate_4-7_no_history.js
+++ b/extensions/cookie/test/unit/test_permmanager_migrate_4-7_no_history.js
@@ -18,22 +18,21 @@ var factory = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIFactory])
 };
 
 var newClassID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
 
 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 var oldClassID = registrar.contractIDToCID(CONTRACT_ID);
 var oldFactory = Components.manager.getClassObject(Cc[CONTRACT_ID], Ci.nsIFactory);
-registrar.unregisterFactory(oldClassID, oldFactory);
 registrar.registerFactory(newClassID, "", CONTRACT_ID, factory);
 
 function cleanupFactory() {
   registrar.unregisterFactory(newClassID, factory);
-  registrar.registerFactory(oldClassID, "", CONTRACT_ID, oldFactory);
+  registrar.registerFactory(oldClassID, "", CONTRACT_ID, null);
 }
 
 function GetPermissionsFile(profile)
 {
   let file = profile.clone();
   file.append(PERMISSIONS_FILE_NAME);
   return file;
 }
--- a/toolkit/components/places/FaviconHelpers.cpp
+++ b/toolkit/components/places/FaviconHelpers.cpp
@@ -1236,17 +1236,17 @@ nsresult FetchAndConvertUnsupportedPaylo
   NS_ENSURE_STATE(dataSurface);
 
   // Read the current size and set an appropriate final width.
   int32_t width = dataSurface->GetSize().width;
   int32_t height = dataSurface->GetSize().height;
   // For non-square images, pick the largest side.
   int32_t originalSize = std::max(width, height);
   int32_t size = originalSize;
-  for (uint16_t supportedSize : sFaviconSizes) {
+  for (uint16_t supportedSize : gFaviconSizes) {
     if (supportedSize <= originalSize) {
       size = supportedSize;
       break;
     }
   }
   *aWidth = size;
 
   // If the original payload is png and the size is the same, no reason to
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/components.conf
@@ -0,0 +1,55 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Classes = [
+    {
+        'cid': '{0937a705-91a6-417a-8292-b22eb10da86c}',
+        'contract_ids': ['@mozilla.org/browser/history;1'],
+        'singleton': True,
+        'type': 'mozilla::places::History',
+        'headers': ['mozilla/places/History.h'],
+        'constructor': 'mozilla::places::History::GetSingleton',
+    },
+    {
+        'cid': '{e8b8bdb7-c96c-4d82-9c6f-2b3c585ec7ea}',
+        'contract_ids': ['@mozilla.org/network/protocol;1?name=moz-anno'],
+        'type': 'nsAnnoProtocolHandler',
+        'headers': ['/toolkit/components/places/nsAnnoProtocolHandler.h'],
+    },
+    {
+        'cid': '{5e8d4751-1852-434b-a992-2c6d2a25fa46}',
+        'contract_ids': ['@mozilla.org/browser/annotation-service;1'],
+        'singleton': True,
+        'type': 'nsAnnotationService',
+        'headers': ['/toolkit/components/places/nsAnnotationService.h'],
+        'constructor': 'nsAnnotationService::GetSingleton',
+    },
+    {
+        'cid': '{984e3259-9266-49cf-b605-60b022a00756}',
+        'contract_ids': ['@mozilla.org/browser/favicon-service;1'],
+        'singleton': True,
+        'type': 'nsFaviconService',
+        'headers': ['/toolkit/components/places/nsFaviconService.h'],
+        'constructor': 'nsFaviconService::GetSingleton',
+    },
+    {
+        'cid': '{9de95a0c-39a4-4d64-9a53-17940dd7cabb}',
+        'contract_ids': ['@mozilla.org/browser/nav-bookmarks-service;1'],
+        'singleton': True,
+        'type': 'nsNavBookmarks',
+        'headers': ['/toolkit/components/places/nsNavBookmarks.h'],
+        'constructor': 'nsNavBookmarks::GetSingleton',
+    },
+    {
+        'cid': '{88cecbb7-6c63-4b3b-8cd4-84f3b8228c69}',
+        'contract_ids': ['@mozilla.org/browser/nav-history-service;1'],
+        'singleton': True,
+        'type': 'nsNavHistory',
+        'headers': ['/toolkit/components/places/nsNavHistory.h'],
+        'constructor': 'nsNavHistory::GetSingleton',
+        'categories': {'vacuum-participant': 'Places'},
+    },
+]
--- a/toolkit/components/places/moz.build
+++ b/toolkit/components/places/moz.build
@@ -39,17 +39,16 @@ if CONFIG['MOZ_PLACES']:
         'History.cpp',
         'nsAnnoProtocolHandler.cpp',
         'nsAnnotationService.cpp',
         'nsFaviconService.cpp',
         'nsNavBookmarks.cpp',
         'nsNavHistory.cpp',
         'nsNavHistoryQuery.cpp',
         'nsNavHistoryResult.cpp',
-        'nsPlacesModule.cpp',
         'PlaceInfo.cpp',
         'Shutdown.cpp',
         'SQLFunctions.cpp',
         'VisitInfo.cpp',
     ]
 
     LOCAL_INCLUDES += [
         '../build',
@@ -79,16 +78,20 @@ if CONFIG['MOZ_PLACES']:
         'nsPlacesExpiration.js',
         'nsTaggingService.js',
         'PageIconProtocolHandler.js',
         'PlacesCategoriesStarter.js',
         'toolkitplaces.manifest',
         'UnifiedComplete.js',
     ]
 
+    XPCOM_MANIFESTS += [
+        'components.conf',
+    ]
+
     FINAL_LIBRARY = 'xul'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 with Files('**'):
     BUG_COMPONENT = ('Toolkit', 'Places')
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
--- a/toolkit/components/places/nsAnnotationService.h
+++ b/toolkit/components/places/nsAnnotationService.h
@@ -11,18 +11,28 @@
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWeakReference.h"
 #include "Database.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 
+namespace mozilla {
+namespace places {
+
+struct BookmarkData;
+
+}  // namespace places
+}  // namespace mozilla
+
 class nsAnnotationService final : public nsIAnnotationService,
                                   public nsSupportsWeakReference {
+  using BookmarkData = mozilla::places::BookmarkData;
+
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIANNOTATIONSERVICE
 
   nsAnnotationService();
 
   /**
    * Obtains the service's object.
--- a/toolkit/components/places/nsFaviconService.cpp
+++ b/toolkit/components/places/nsFaviconService.cpp
@@ -38,16 +38,18 @@
 // When replaceFaviconData is called, we store the icons in an in-memory cache
 // instead of in storage. Icons in the cache are expired according to this
 // interval.
 #define UNASSOCIATED_ICON_EXPIRY_INTERVAL 60000
 
 using namespace mozilla;
 using namespace mozilla::places;
 
+const uint16_t gFaviconSizes[7] = {192, 144, 96, 64, 48, 32, 16};
+
 /**
  * Used to notify a topic to system observers on async execute completion.
  * Will throw on error.
  */
 class ExpireFaviconsStatementCallbackNotifier : public AsyncStatementCallback {
  public:
   ExpireFaviconsStatementCallbackNotifier();
   NS_IMETHOD HandleCompletion(uint16_t aReason) override;
@@ -72,19 +74,19 @@ nsresult GetFramesInfoForContainer(imgIC
     if (NS_SUCCEEDED(rv) && nativeSizes.Length() > 1) {
       for (uint32_t i = 0; i < nativeSizes.Length(); ++i) {
         nsIntSize nativeSize = nativeSizes[i];
         // Only retain square frames.
         if (nativeSize.width != nativeSize.height) {
           continue;
         }
         // Check if it's one of the sizes we care about.
-        auto end = std::end(sFaviconSizes);
-        uint16_t* matchingSize =
-            std::find(std::begin(sFaviconSizes), end, nativeSize.width);
+        auto end = std::end(gFaviconSizes);
+        const uint16_t* matchingSize =
+            std::find(std::begin(gFaviconSizes), end, nativeSize.width);
         if (matchingSize != end) {
           // We must avoid duped sizes, an image could contain multiple frames
           // of the same size, but we can only store one. We could use an
           // hashtable, but considered the average low number of frames, we'll
           // just do a linear search.
           bool dupe = false;
           for (const auto& frameInfo : aFramesInfo) {
             if (frameInfo.width == *matchingSize) {
@@ -722,17 +724,17 @@ nsresult nsFaviconService::OptimizeIconS
   nsTArray<FrameData> framesInfo;
   rv = GetFramesInfoForContainer(container, framesInfo);
   NS_ENSURE_SUCCESS(rv, rv);
 
   for (const auto& frameInfo : framesInfo) {
     IconPayload newPayload;
     newPayload.mimeType = NS_LITERAL_CSTRING(PNG_MIME_TYPE);
     newPayload.width = frameInfo.width;
-    for (uint16_t size : sFaviconSizes) {
+    for (uint16_t size : gFaviconSizes) {
       // The icon could be smaller than 16, that is our minimum.
       // Icons smaller than 16px are kept as-is.
       if (frameInfo.width >= 16) {
         if (size > frameInfo.width) {
           continue;
         }
         newPayload.width = size;
       }
--- a/toolkit/components/places/nsFaviconService.h
+++ b/toolkit/components/places/nsFaviconService.h
@@ -22,17 +22,17 @@
 #include "mozilla/storage.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Move.h"
 
 #include "FaviconHelpers.h"
 
 // The target dimension in pixels for favicons we store, in reverse order.
 // When adding/removing sizes from here, make sure to update the vector size.
-static uint16_t sFaviconSizes[7] = {192, 144, 96, 64, 48, 32, 16};
+extern const uint16_t gFaviconSizes[7];
 
 // forward class definitions
 class mozIStorageStatementCallback;
 
 class UnassociatedIconHashKey : public nsURIHashKey {
  public:
   explicit UnassociatedIconHashKey(const nsIURI* aURI) : nsURIHashKey(aURI) {}
   UnassociatedIconHashKey(UnassociatedIconHashKey&& aOther)
deleted file mode 100644
--- a/toolkit/components/places/nsPlacesModule.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/ModuleUtils.h"
-#include "nsIClassInfoImpl.h"
-
-#include "nsAnnoProtocolHandler.h"
-#include "nsAnnotationService.h"
-#include "nsNavHistory.h"
-#include "nsNavBookmarks.h"
-#include "nsFaviconService.h"
-#include "History.h"
-#include "nsDocShellCID.h"
-
-using namespace mozilla::places;
-
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsNavHistory,
-                                         nsNavHistory::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsAnnotationService,
-                                         nsAnnotationService::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsNavBookmarks,
-                                         nsNavBookmarks::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsFaviconService,
-                                         nsFaviconService::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(History, History::GetSingleton)
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsAnnoProtocolHandler)
-NS_DEFINE_NAMED_CID(NS_NAVHISTORYSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_ANNOTATIONSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_ANNOPROTOCOLHANDLER_CID);
-NS_DEFINE_NAMED_CID(NS_NAVBOOKMARKSSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_FAVICONSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_HISTORYSERVICE_CID);
-
-const mozilla::Module::CIDEntry kPlacesCIDs[] = {
-    {&kNS_NAVHISTORYSERVICE_CID, false, nullptr, nsNavHistoryConstructor},
-    {&kNS_ANNOTATIONSERVICE_CID, false, nullptr,
-     nsAnnotationServiceConstructor},
-    {&kNS_ANNOPROTOCOLHANDLER_CID, false, nullptr,
-     nsAnnoProtocolHandlerConstructor},
-    {&kNS_NAVBOOKMARKSSERVICE_CID, false, nullptr, nsNavBookmarksConstructor},
-    {&kNS_FAVICONSERVICE_CID, false, nullptr, nsFaviconServiceConstructor},
-    {&kNS_HISTORYSERVICE_CID, false, nullptr, HistoryConstructor},
-    {nullptr}};
-
-const mozilla::Module::ContractIDEntry kPlacesContracts[] = {
-    {NS_NAVHISTORYSERVICE_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID},
-    {NS_ANNOTATIONSERVICE_CONTRACTID, &kNS_ANNOTATIONSERVICE_CID},
-    {NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-anno",
-     &kNS_ANNOPROTOCOLHANDLER_CID},
-    {NS_NAVBOOKMARKSSERVICE_CONTRACTID, &kNS_NAVBOOKMARKSSERVICE_CID},
-    {NS_FAVICONSERVICE_CONTRACTID, &kNS_FAVICONSERVICE_CID},
-    {NS_IHISTORY_CONTRACTID, &kNS_HISTORYSERVICE_CID},
-    {nullptr}};
-
-const mozilla::Module::CategoryEntry kPlacesCategories[] = {
-    {"vacuum-participant", "Places", NS_NAVHISTORYSERVICE_CONTRACTID},
-    {nullptr}};
-
-const mozilla::Module kPlacesModule = {mozilla::Module::kVersion, kPlacesCIDs,
-                                       kPlacesContracts, kPlacesCategories};
-
-NSMODULE_DEFN(nsPlacesModule) = &kPlacesModule;