Bug 1096093 - Add infrastructure for LookAndFeel metric caching, and allowing the parent process to send down cache to content process. r=jimm.
☠☠ backed out by d13a8cde5695 ☠ ☠
authorMike Conley <mconley@mozilla.com>
Wed, 22 Apr 2015 10:58:15 -0400
changeset 270593 5f9c7cd773a5826d2621601e4f4ee3581d656764
parent 270592 53e0f191ddeeda88446c4b6cacbfbd7120320438
child 270594 8ed8157d26a240c471685aba39065528c20a8a71
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1096093
milestone40.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 1096093 - Add infrastructure for LookAndFeel metric caching, and allowing the parent process to send down cache to content process. r=jimm.
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
widget/LookAndFeel.h
widget/WidgetMessageUtils.h
widget/moz.build
widget/nsXPLookAndFeel.cpp
widget/nsXPLookAndFeel.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -18,16 +18,17 @@
 #include "CrashReporterChild.h"
 #include "GeckoProfiler.h"
 #include "TabChild.h"
 
 #include "mozilla/Attributes.h"
 #ifdef ACCESSIBILITY
 #include "mozilla/a11y/DocAccessibleChild.h"
 #endif
+#include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ProcessHangMonitorIPC.h"
 #include "mozilla/docshell/OfflineCacheUpdateChild.h"
 #include "mozilla/dom/ContentBridgeChild.h"
 #include "mozilla/dom/ContentBridgeParent.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/DOMStorageIPC.h"
@@ -48,16 +49,17 @@
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "mozilla/layers/CompositorChild.h"
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "mozilla/layers/PCompositorChild.h"
 #include "mozilla/layers/SharedBufferManagerChild.h"
 #include "mozilla/net/NeckoChild.h"
 #include "mozilla/plugins/PluginInstanceParent.h"
 #include "mozilla/plugins/PluginModuleParent.h"
+#include "mozilla/widget/WidgetMessageUtils.h"
 
 #if defined(MOZ_CONTENT_SANDBOX)
 #if defined(XP_WIN)
 #define TARGET_SANDBOX_EXPORTS
 #include "mozilla/sandboxTarget.h"
 #elif defined(XP_LINUX)
 #include "mozilla/Sandbox.h"
 #include "mozilla/SandboxInfo.h"
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -71,16 +71,17 @@
 #include "mozilla/ipc/FileDescriptorUtils.h"
 #include "mozilla/ipc/PFileDescriptorSetParent.h"
 #include "mozilla/ipc/TestShellParent.h"
 #include "mozilla/ipc/InputStreamUtils.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layers/ImageBridgeParent.h"
 #include "mozilla/layers/SharedBufferManagerParent.h"
+#include "mozilla/LookAndFeel.h"
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/plugins/PluginBridge.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ProcessHangMonitor.h"
 #include "mozilla/ProcessHangMonitorIPC.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
@@ -2882,16 +2883,17 @@ ContentParent::RecvAddNewProcess(const u
         mozilla::unused << content->SendPreferenceUpdate(sNuwaPrefUpdates->ElementAt(i));
     }
 
     // Update offline settings.
     bool isOffline, isLangRTL;
     InfallibleTArray<nsString> unusedDictionaries;
     ClipboardCapabilities clipboardCaps;
     DomainPolicyClone domainPolicy;
+
     RecvGetXPCOMProcessAttributes(&isOffline, &isLangRTL, &unusedDictionaries,
                                   &clipboardCaps, &domainPolicy);
     mozilla::unused << content->SendSetOffline(isOffline);
     MOZ_ASSERT(!clipboardCaps.supportsSelectionClipboard() &&
                !clipboardCaps.supportsFindClipboard(),
                "Unexpected values");
 
     PreallocatedProcessManager::PublishSpareProcess(content);
@@ -4033,16 +4035,23 @@ ContentParent::RecvGetSystemMemory(const
 #endif
 
     unused << SendSystemMemoryAvailable(aGetterId, memoryTotal);
 
     return true;
 }
 
 bool
+ContentParent::RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache)
+{
+    aLookAndFeelIntCache = LookAndFeel::GetIntCache();
+    return true;
+}
+
+bool
 ContentParent::RecvIsSecureURI(const uint32_t& type,
                                const URIParams& uri,
                                const uint32_t& flags,
                                bool* isSecureURI)
 {
     nsCOMPtr<nsISiteSecurityService> sss(do_GetService(NS_SSSERVICE_CONTRACTID));
     if (!sss) {
         return false;
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -538,18 +538,17 @@ private:
 
     virtual bool RecvGetProcessAttributes(ContentParentId* aCpId,
                                           bool* aIsForApp,
                                           bool* aIsForBrowser) override;
     virtual bool RecvGetXPCOMProcessAttributes(bool* aIsOffline,
                                                bool* aIsLangRTL,
                                                InfallibleTArray<nsString>* dictionaries,
                                                ClipboardCapabilities* clipboardCaps,
-                                               DomainPolicyClone* domainPolicy)
-        override;
+                                               DomainPolicyClone* domainPolicy) override;
 
     virtual bool DeallocPJavaScriptParent(mozilla::jsipc::PJavaScriptParent*) override;
 
     virtual bool DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent*) override;
     virtual PBrowserParent* AllocPBrowserParent(const TabId& aTabId,
                                                 const IPCTabContext& aContext,
                                                 const uint32_t& aChromeFlags,
                                                 const ContentParentId& aCpId,
@@ -751,16 +750,18 @@ private:
                                                 const bool& aWithVideo) override;
 
     virtual bool RecvAudioChannelChangedNotification() override;
 
     virtual bool RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel,
                                                      const bool& aHidden) override;
     virtual bool RecvGetSystemMemory(const uint64_t& getterId) override;
 
+    virtual bool RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache) override;
+
     virtual bool RecvDataStoreGetStores(
                        const nsString& aName,
                        const nsString& aOwner,
                        const IPC::Principal& aPrincipal,
                        InfallibleTArray<DataStoreSetting>* aValue) override;
 
     virtual bool RecvSpeakerManagerGetSpeakerStatus(bool* aValue) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -82,16 +82,17 @@ using mozilla::dom::asmjscache::WritePar
 using mozilla::dom::AudioChannel from "mozilla/dom/AudioChannelBinding.h";
 using mozilla::dom::AudioChannelState from "AudioChannelCommon.h";
 using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h";
 using mozilla::dom::quota::PersistenceType from "mozilla/dom/quota/PersistenceType.h";
 using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h";
 using gfxIntSize from "nsSize.h";
 using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
 using mozilla::dom::ContentParentId from "mozilla/dom/ipc/IdType.h";
+using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h";
 
 union ChromeRegistryItem
 {
     ChromePackage;
     OverrideMapping;
     ResourceMapping;
 };
 
@@ -685,16 +686,18 @@ parent:
     sync GetRandomValues(uint32_t length)
         returns (uint8_t[] randomValues);
 
     async GetSystemMemory(uint64_t getterId);
 
     sync IsSecureURI(uint32_t type, URIParams uri, uint32_t flags)
         returns (bool isSecureURI);
 
+    sync GetLookAndFeelCache(LookAndFeelInt[] lookAndFeelIntCache);
+
     PHal();
 
     PIcc(uint32_t serviceId);
 
     PMobileConnection(uint32_t clientId);
 
     PNecko();
 
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -10,16 +10,22 @@
 #error "This header is only usable from within libxul (MOZILLA_INTERNAL_API)."
 #endif
 
 #include "nsDebug.h"
 #include "nsColor.h"
 
 struct gfxFontStyle;
 
+struct LookAndFeelInt
+{
+  int32_t id;
+  int32_t value;
+};
+
 namespace mozilla {
 
 class LookAndFeel
 {
 public:
   // When modifying this list, also modify nsXPLookAndFeel::sColorPrefs
   // in widget/xpwidgts/nsXPLookAndFeel.cpp.
   enum ColorID {
@@ -578,16 +584,23 @@ public:
    */
   static uint32_t GetPasswordMaskDelay();
 
   /**
    * When system look and feel is changed, Refresh() must be called.  Then,
    * cached data would be released.
    */
   static void Refresh();
+
+  /**
+   * If the implementation is caching values, these accessors allow the
+   * cache to be exported and imported.
+   */
+  static nsTArray<LookAndFeelInt> GetIntCache();
+  static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
 };
 
 } // namespace mozilla
 
 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
 // constant to specify that the foreground color should not be changed
 // (ie. a colored text keeps its colors  when selected).
 // Of course if other plaforms work like the Mac, they can use it too.
new file mode 100644
--- /dev/null
+++ b/widget/WidgetMessageUtils.h
@@ -0,0 +1,39 @@
+/* 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/. */
+
+#ifndef mozilla_WidgetMessageUtils_h
+#define mozilla_WidgetMessageUtils_h
+
+#include "ipc/IPCMessageUtils.h"
+#include "mozilla/LookAndFeel.h"
+
+namespace IPC {
+
+template<>
+struct ParamTraits<LookAndFeelInt>
+{
+  typedef LookAndFeelInt paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    WriteParam(aMsg, aParam.id);
+    WriteParam(aMsg, aParam.value);
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+  {
+    int32_t id, value;
+    if (ReadParam(aMsg, aIter, &id) &&
+        ReadParam(aMsg, aIter, &value)) {
+      aResult->id = id;
+      aResult->value = value;
+      return true;
+    }
+    return false;
+  }
+};
+
+} // namespace IPC
+
+#endif // WidgetMessageUtils_h
\ No newline at end of file
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -128,16 +128,17 @@ EXPORTS.mozilla += [
     'TextRange.h',
     'TouchEvents.h',
     'VsyncDispatcher.h',
     'WidgetUtils.h',
 ]
 
 EXPORTS.mozilla.widget += [
     'PuppetBidiKeyboard.h',
+    'WidgetMessageUtils.h',
 ]
 
 UNIFIED_SOURCES += [
     'ContentHelper.cpp',
     'GfxDriverInfo.cpp',
     'GfxInfoBase.cpp',
     'GfxInfoCollector.cpp',
     'GfxInfoWebGL.cpp',
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -8,16 +8,17 @@
 #include "nscore.h"
 
 #include "nsXPLookAndFeel.h"
 #include "nsLookAndFeel.h"
 #include "nsCRT.h"
 #include "nsFont.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/gfx/2D.h"
+#include "mozilla/widget/WidgetMessageUtils.h"
 
 #include "gfxPlatform.h"
 #include "qcms.h"
 
 #ifdef DEBUG
 #include "nsSize.h"
 #endif
 
@@ -448,16 +449,25 @@ nsXPLookAndFeel::Init()
   for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
     InitColorFromPref(i);
   }
 
   bool val;
   if (NS_SUCCEEDED(Preferences::GetBool("ui.use_native_colors", &val))) {
     sUseNativeColors = val;
   }
+
+  if (XRE_GetProcessType() == GeckoProcessType_Content) {
+    mozilla::dom::ContentChild* cc =
+      mozilla::dom::ContentChild::GetSingleton();
+
+    nsTArray<LookAndFeelInt> lookAndFeelIntCache;
+    cc->SendGetLookAndFeelCache(lookAndFeelIntCache);
+    LookAndFeel::SetIntCache(lookAndFeelIntCache);
+  }
 }
 
 nsXPLookAndFeel::~nsXPLookAndFeel()
 {
   NS_ASSERTION(sInstance == this,
                "This destroying instance isn't the singleton instance");
   sInstance = nullptr;
 }
@@ -698,16 +708,22 @@ nsXPLookAndFeel::RefreshImpl()
   // Wipe out our color cache.
   uint32_t i;
   for (i = 0; i < eColorID_LAST_COLOR; i++)
     sCachedColors[i] = 0;
   for (i = 0; i < COLOR_CACHE_SIZE; i++)
     sCachedColorBits[i] = 0;
 }
 
+nsTArray<LookAndFeelInt>
+nsXPLookAndFeel::GetIntCacheImpl()
+{
+  return nsTArray<LookAndFeelInt>();
+}
+
 namespace mozilla {
 
 // static
 nsresult
 LookAndFeel::GetColor(ColorID aID, nscolor* aResult)
 {
   return nsLookAndFeel::GetInstance()->GetColorImpl(aID, *aResult);
 }
@@ -758,9 +774,23 @@ LookAndFeel::GetPasswordMaskDelay()
 
 // static
 void
 LookAndFeel::Refresh()
 {
   nsLookAndFeel::GetInstance()->RefreshImpl();
 }
 
+// static
+nsTArray<LookAndFeelInt>
+LookAndFeel::GetIntCache()
+{
+  return nsLookAndFeel::GetInstance()->GetIntCacheImpl();
+}
+
+// static
+void
+LookAndFeel::SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache)
+{
+  return nsLookAndFeel::GetInstance()->SetIntCacheImpl(aLookAndFeelIntCache);
+}
+
 } // namespace mozilla
--- a/widget/nsXPLookAndFeel.h
+++ b/widget/nsXPLookAndFeel.h
@@ -2,16 +2,17 @@
 /* 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/. */
 
 #ifndef __nsXPLookAndFeel
 #define __nsXPLookAndFeel
 
 #include "mozilla/LookAndFeel.h"
+#include "nsTArray.h"
 
 class nsLookAndFeel;
 
 struct nsLookAndFeelIntPref
 {
   const char* name;
   mozilla::LookAndFeel::IntID id;
   bool isSet;
@@ -74,16 +75,19 @@ public:
     return false;
   }
 
   virtual uint32_t GetPasswordMaskDelayImpl()
   {
     return 600;
   }
 
+  virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
+  virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
+
 protected:
   nsXPLookAndFeel();
 
   static void IntPrefChanged(nsLookAndFeelIntPref *data);
   static void FloatPrefChanged(nsLookAndFeelFloatPref *data);
   static void ColorPrefChanged(unsigned int index, const char *prefName);
   void InitFromPref(nsLookAndFeelIntPref* aPref);
   void InitFromPref(nsLookAndFeelFloatPref* aPref);