Minor cleanup: Factor out some common stuff in MessagePipe::EndSerialize().

R=yzshen@chromium.org

Review URL: https://codereview.chromium.org/791623003