Bug 1353629 - PBlob refactoring - part 10 - Make nsFileInputStream cloneable, r=smaug
☠☠ backed out by cabdccfa10f0 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 20 Apr 2017 15:20:56 +0200
changeset 354067 b225ae4bfc09e5bd2b7ef8139eac5abd253bd084
parent 354066 c930526369c233e6d45219b0178ff83c9e599cc6
child 354068 607b25ac6c31b14f29e010ab61d3270ca98c939d
push id89396
push useramarchesini@mozilla.com
push dateThu, 20 Apr 2017 13:21:34 +0000
treeherdermozilla-inbound@d4ab7cc36551 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1353629
milestone55.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 1353629 - PBlob refactoring - part 10 - Make nsFileInputStream cloneable, r=smaug This is important to avoid extra copy when IPCInputStreamStorage::GetStream() returns a file inputStream
netwerk/base/nsFileStreams.cpp
netwerk/base/nsFileStreams.h
--- a/netwerk/base/nsFileStreams.cpp
+++ b/netwerk/base/nsFileStreams.cpp
@@ -392,16 +392,17 @@ NS_IMPL_CLASSINFO(nsFileInputStream, nul
                   NS_LOCALFILEINPUTSTREAM_CID)
 
 NS_INTERFACE_MAP_BEGIN(nsFileInputStream)
     NS_INTERFACE_MAP_ENTRY(nsIInputStream)
     NS_INTERFACE_MAP_ENTRY(nsIFileInputStream)
     NS_INTERFACE_MAP_ENTRY(nsILineInputStream)
     NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableInputStream)
     NS_IMPL_QUERY_CLASSINFO(nsFileInputStream)
+    NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICloneableInputStream, IsCloneable())
 NS_INTERFACE_MAP_END_INHERITING(nsFileStreamBase)
 
 NS_IMPL_CI_INTERFACE_GETTER(nsFileInputStream,
                             nsIInputStream,
                             nsIFileInputStream,
                             nsISeekableStream,
                             nsILineInputStream)
 
@@ -677,16 +678,37 @@ nsFileInputStream::Deserialize(const Inp
 }
 
 Maybe<uint64_t>
 nsFileInputStream::ExpectedSerializedLength()
 {
     return Nothing();
 }
 
+bool
+nsFileInputStream::IsCloneable() const
+{
+    return XRE_IsParentProcess();
+}
+
+NS_IMETHODIMP
+nsFileInputStream::GetCloneable(bool* aCloneable)
+{
+    *aCloneable = IsCloneable();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsFileInputStream::Clone(nsIInputStream** aResult)
+{
+    MOZ_ASSERT(IsCloneable());
+    return NS_NewLocalFileInputStream(aResult, mFile, mIOFlags, mPerm,
+                                      mBehaviorFlags);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // nsFileOutputStream
 
 NS_IMPL_ISUPPORTS_INHERITED(nsFileOutputStream,
                             nsFileStreamBase,
                             nsIOutputStream,
                             nsIFileOutputStream)
 
--- a/netwerk/base/nsFileStreams.h
+++ b/netwerk/base/nsFileStreams.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsFileStreams_h__
 #define nsFileStreams_h__
 
 #include "nsAutoPtr.h"
 #include "nsIFileStreams.h"
 #include "nsIFile.h"
+#include "nsICloneableInputStream.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsISafeOutputStream.h"
 #include "nsISeekableStream.h"
 #include "nsILineInputStream.h"
 #include "nsCOMPtr.h"
 #include "nsIIPCSerializableInputStream.h"
 #include "nsReadLine.h"
@@ -108,26 +109,31 @@ protected:
      * nothing. If the return value is not NS_OK, please, return it back to the
      * callee.
      */
     inline nsresult DoPendingOpen();
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
-class nsFileInputStream : public nsFileStreamBase,
-                          public nsIFileInputStream,
-                          public nsILineInputStream,
-                          public nsIIPCSerializableInputStream
+// nsFileInputStream is cloneable only on the parent process because only there
+// it can open the same file multiple times.
+
+class nsFileInputStream : public nsFileStreamBase
+                        , public nsIFileInputStream
+                        , public nsILineInputStream
+                        , public nsIIPCSerializableInputStream
+                        , public nsICloneableInputStream
 {
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIFILEINPUTSTREAM
     NS_DECL_NSILINEINPUTSTREAM
     NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
+    NS_DECL_NSICLONEABLEINPUTSTREAM
 
     NS_IMETHOD Close() override;
     NS_IMETHOD Tell(int64_t *aResult) override;
     NS_IMETHOD Available(uint64_t* _retval) override;
     NS_IMETHOD Read(char* aBuf, uint32_t aCount, uint32_t* _retval) override;
     NS_IMETHOD ReadSegments(nsWriteSegmentFun aWriter, void *aClosure,
                             uint32_t aCount, uint32_t* _retval) override
     {
@@ -178,16 +184,18 @@ protected:
     int64_t mCachedPosition;
 
 protected:
     /**
      * Internal, called to open a file.  Parameters are the same as their
      * Init() analogues.
      */
     nsresult Open(nsIFile* file, int32_t ioFlags, int32_t perm);
+
+    bool IsCloneable() const;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
 class nsFileOutputStream : public nsFileStreamBase,
                            public nsIFileOutputStream
 {
 public: