Bug 1383816 - Adds IPC Read and Write methods for FocusTarget and NoFocusState structs and creates EmptyStructSerializer helper class; r=botond
authorJeff Hajewski <jeff.hajewski@gmail.com>
Sat, 02 Sep 2017 14:10:40 -0500
changeset 429324 ccd79eaa9cb0330791021676c39d887d9ae7c676
parent 429323 7f209f4a6bf21c3c68e080c5e6305b8f64e6462c
child 429325 57a5ce8cbf6057413f3f5d20f8bef6ebb8e84eae
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1383816
milestone57.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 1383816 - Adds IPC Read and Write methods for FocusTarget and NoFocusState structs and creates EmptyStructSerializer helper class; r=botond Since NoFocusState is am empty struct used in the |mData| variant in FocusTarget, we need to add a Reader and a Writer for IPC for NoFocusState so we can properly read and write the |mData| variant. The NoFocusState Read and Write methods do not read or write anything, since NoFocusState does not contain any data. This is done by creating a helper class EmptyStructSerliazer and inheritting from EmptyStructSerializer for the NoFocusState specialization. The |Read| and |Write| methods for FocusTarget are updated by removing the read and write code for the individual types of |mData| and instead makes use of the IPC read and write methods for Variant. MozReview-Commit-ID: 3159sp6FLek
gfx/layers/ipc/LayersMessageUtils.h
ipc/glue/IPCMessageUtils.h
--- a/gfx/layers/ipc/LayersMessageUtils.h
+++ b/gfx/layers/ipc/LayersMessageUtils.h
@@ -443,46 +443,39 @@ template <>
 struct ParamTraits<mozilla::layers::FocusTarget::FocusTargetType>
   : public ContiguousEnumSerializerInclusive<
              mozilla::layers::FocusTarget::FocusTargetType,
              mozilla::layers::FocusTarget::eNone,
              mozilla::layers::FocusTarget::sHighestFocusTargetType>
 {};
 
 template <>
+struct ParamTraits<mozilla::layers::FocusTarget::NoFocusTarget>
+  : public EmptyStructSerializer<mozilla::layers::FocusTarget::NoFocusTarget>
+{};
+
+template <>
 struct ParamTraits<mozilla::layers::FocusTarget>
 {
   typedef mozilla::layers::FocusTarget paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.mSequenceNumber);
     WriteParam(aMsg, aParam.mFocusHasKeyEventListeners);
-    WriteParam(aMsg, aParam.mType);
-    if (aParam.mType == mozilla::layers::FocusTarget::eRefLayer) {
-      WriteParam(aMsg, aParam.mData.mRefLayerId);
-    } else if (aParam.mType == mozilla::layers::FocusTarget::eScrollLayer) {
-      WriteParam(aMsg, aParam.mData.mScrollTargets);
-    }
+    WriteParam(aMsg, aParam.mData);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     if (!ReadParam(aMsg, aIter, &aResult->mSequenceNumber) ||
         !ReadParam(aMsg, aIter, &aResult->mFocusHasKeyEventListeners) ||
-        !ReadParam(aMsg, aIter, &aResult->mType)) {
+        !ReadParam(aMsg, aIter, &aResult->mData)) {
       return false;
     }
-
-    if (aResult->mType == mozilla::layers::FocusTarget::eRefLayer) {
-      return ReadParam(aMsg, aIter, &aResult->mData.mRefLayerId);
-    } else if (aResult->mType == mozilla::layers::FocusTarget::eScrollLayer) {
-      return ReadParam(aMsg, aIter, &aResult->mData.mScrollTargets);
-    }
-
     return true;
   }
 };
 
 template <>
 struct ParamTraits<mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType>
   : public ContiguousEnumSerializerInclusive<
              mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType,
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -281,16 +281,33 @@ struct PlainOldDataSerializer
     aMsg->WriteBytes(&aParam, sizeof(aParam));
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
     return aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType));
   }
 };
 
+/**
+ * A helper class for serializing empty structs. Since the struct is empty there
+ * is nothing to write, and a priori we know the result of the read.
+ */
+template <typename T>
+struct EmptyStructSerializer
+{
+  typedef T paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam) {}
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
+    *aResult = {};
+    return true;
+  }
+};
+
 template<>
 struct ParamTraits<int8_t>
 {
   typedef int8_t paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     aMsg->WriteBytes(&aParam, sizeof(aParam));