Revert the RPC-style race resolution from bug 532208 in order to use the asynchronous delivery patches.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Sat, 06 Mar 2010 11:08:19 -0500
changeset 39280 6d13458be1b0d48e3e4ad03a313363d065ea7337
parent 39279 37ea3b54ad74ca740c3d7eab0f47c2b581226d2d
child 39281 b594d5b63dd0cceb44f5f47f290981ca6cb414fd
push id12114
push userbsmedberg@mozilla.com
push dateThu, 11 Mar 2010 16:57:13 +0000
treeherdermozilla-central@dc3af645f713 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs532208
milestone1.9.3a3pre
Revert the RPC-style race resolution from bug 532208 in order to use the asynchronous delivery patches.
dom/plugins/BrowserStreamChild.cpp
dom/plugins/BrowserStreamChild.h
dom/plugins/BrowserStreamParent.cpp
dom/plugins/BrowserStreamParent.h
dom/plugins/PBrowserStream.ipdl
dom/plugins/PluginInstanceParent.cpp
dom/plugins/PluginModuleChild.cpp
--- a/dom/plugins/BrowserStreamChild.cpp
+++ b/dom/plugins/BrowserStreamChild.cpp
@@ -147,16 +147,26 @@ BrowserStreamChild::AnswerNPP_StreamAsFi
   if (mClosed)
     return true;
 
   mInstance->mPluginIface->asfile(&mInstance->mData, &mStream,
                                   fname.get());
   return true;
 }
 
+bool
+BrowserStreamChild::Answer__delete__(const NPError& reason,
+                                     const bool& artificial)
+{
+  AssertPluginThread();
+  if (!artificial)
+    NPP_DestroyStream(reason);
+  return true;
+}
+
 NPError
 BrowserStreamChild::NPN_RequestRead(NPByteRange* aRangeList)
 {
   PLUGIN_LOG_DEBUG_FUNCTION;
 
   AssertPluginThread();
 
   IPCByteRanges ranges;
@@ -165,37 +175,24 @@ BrowserStreamChild::NPN_RequestRead(NPBy
     ranges.push_back(br);
   }
 
   NPError result;
   CallNPN_RequestRead(ranges, &result);
   return result;
 }
 
-bool
-BrowserStreamChild::AnswerNPP_DestroyStream(const NPReason& reason,
-                                            NPError* err)
+void
+BrowserStreamChild::NPP_DestroyStream(NPError reason)
 {
   PLUGIN_LOG_DEBUG(("%s (reason=%i)", FULLFUNCTION, reason));
 
   AssertPluginThread();
 
-  if (mClosed) {
-    NS_WARNING("NPP_DestroyStream on a closed stream");
-    return true;
-  }
+  if (mClosed)
+    return;
 
-  *err = mInstance->mPluginIface->destroystream(&mInstance->mData,
-                                                &mStream, reason);
+  mInstance->mPluginIface->destroystream(&mInstance->mData, &mStream, reason);
   mClosed = true;
-  return true;
-}
-
-bool
-BrowserStreamChild::Recv__delete__()
-{
-  if (!mClosed)
-    NS_WARNING("__delete__ on an open stream");
-  return true;
 }
 
 } /* namespace plugins */
 } /* namespace mozilla */
--- a/dom/plugins/BrowserStreamChild.h
+++ b/dom/plugins/BrowserStreamChild.h
@@ -76,22 +76,18 @@ public:
 
   virtual bool AnswerNPP_WriteReady(const int32_t& newlength,
                                         int32_t *size);
   virtual bool AnswerNPP_Write(const int32_t& offset,
                                    const Buffer& data,
                                    int32_t* consumed);
 
   virtual bool AnswerNPP_StreamAsFile(const nsCString& fname);
-
-  NS_OVERRIDE
-  virtual bool AnswerNPP_DestroyStream(const NPReason& reason, NPError* err);
-
-  NS_OVERRIDE
-  virtual bool Recv__delete__();
+  virtual bool Answer__delete__(const NPError& reason,
+                                const bool& artificial);
 
 
   void EnsureCorrectInstance(PluginInstanceChild* i)
   {
     if (i != mInstance)
       NS_RUNTIMEABORT("Incorrect stream instance");
   }
   void EnsureCorrectStream(NPStream* s)
--- a/dom/plugins/BrowserStreamParent.cpp
+++ b/dom/plugins/BrowserStreamParent.cpp
@@ -1,56 +1,26 @@
 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
 
 #include "BrowserStreamParent.h"
 #include "PluginInstanceParent.h"
-#include "PluginModuleParent.h"
-
-template<>
-struct RunnableMethodTraits<mozilla::plugins::BrowserStreamParent>
-{
-  typedef mozilla::plugins::BrowserStreamParent Cls;
-    static void RetainCallee(Cls* obj) { }
-    static void ReleaseCallee(Cls* obj) { }
-};
 
 namespace mozilla {
 namespace plugins {
 
 BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
                                          NPStream* stream)
   : mNPP(npp)
   , mStream(stream)
-  , mDeleteTask(nsnull)
 {
   mStream->pdata = static_cast<AStream*>(this);
 }
 
 BrowserStreamParent::~BrowserStreamParent()
 {
-  if (mDeleteTask) {
-    mDeleteTask->Cancel();
-    // MessageLoop::current() owns this
-    mDeleteTask = nsnull;
-  }
-}
-
-NPError
-BrowserStreamParent::NPP_DestroyStream(NPReason reason)
-{
-  PLUGIN_LOG_DEBUG(("%s (reason=%i)", FULLFUNCTION, reason));
-
-  if (!mDeleteTask) {
-    mDeleteTask = NewRunnableMethod(this, &BrowserStreamParent::Delete);
-    MessageLoop::current()->PostTask(FROM_HERE, mDeleteTask);
-  }
-
-  NPError err = NPERR_NO_ERROR;
-  CallNPP_DestroyStream(reason, &err);
-  return err;
 }
 
 bool
 BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
                                            NPError* result)
 {
   PLUGIN_LOG_DEBUG_FUNCTION;
 
@@ -67,16 +37,25 @@ BrowserStreamParent::AnswerNPN_RequestRe
     rp[i].next = &rp[i + 1];
   }
   rp[ranges.size() - 1].next = NULL;
 
   *result = mNPP->mNPNIface->requestread(mStream, rp);
   return true;
 }
 
+bool
+BrowserStreamParent::Answer__delete__(const NPError& reason,
+                                      const bool& artificial)
+{
+  if (!artificial)
+    NPN_DestroyStream(reason);
+  return true;
+}
+
 int32_t
 BrowserStreamParent::WriteReady()
 {
   PLUGIN_LOG_DEBUG_FUNCTION;
 
   int32_t result;
   if (!CallNPP_WriteReady(mStream->end, &result))
     return -1;
@@ -103,27 +82,18 @@ BrowserStreamParent::Write(int32_t offse
 void
 BrowserStreamParent::StreamAsFile(const char* fname)
 {
   PLUGIN_LOG_DEBUG_FUNCTION;
 
   CallNPP_StreamAsFile(nsCString(fname));
 }
 
-bool
-BrowserStreamParent::AnswerNPN_DestroyStream(const NPReason& reason,
-                                             NPError* result)
+NPError
+BrowserStreamParent::NPN_DestroyStream(NPReason reason)
 {
   PLUGIN_LOG_DEBUG_FUNCTION;
 
-  *result = mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, reason);
-  return true;
-}
-
-void
-BrowserStreamParent::Delete()
-{
-  PBrowserStreamParent::Send__delete__(this);
-  // |this| just got deleted
+  return mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, reason);
 }
 
 } // namespace plugins
 } // namespace mozilla
--- a/dom/plugins/BrowserStreamParent.h
+++ b/dom/plugins/BrowserStreamParent.h
@@ -39,46 +39,43 @@
 #define mozilla_plugins_BrowserStreamParent_h
 
 #include "mozilla/plugins/PBrowserStreamParent.h"
 #include "mozilla/plugins/AStream.h"
 
 namespace mozilla {
 namespace plugins {
 
-class PluginModuleParent;
 class PluginInstanceParent;
 
 class BrowserStreamParent : public PBrowserStreamParent, public AStream
 {
   friend class PluginModuleParent;
   friend class PluginInstanceParent;
 
 public:
   BrowserStreamParent(PluginInstanceParent* npp,
                       NPStream* stream);
   virtual ~BrowserStreamParent();
 
-  NPError NPP_DestroyStream(NPReason reason);
-
   NS_OVERRIDE virtual bool IsBrowserStream() { return true; }
 
   virtual bool AnswerNPN_RequestRead(const IPCByteRanges& ranges,
                                      NPError* result);
 
-  virtual bool AnswerNPN_DestroyStream(const NPReason& reason, NPError* result);
+  virtual bool
+  Answer__delete__(const NPError& reason, const bool& artificial);
 
   int32_t WriteReady();
   int32_t Write(int32_t offset, int32_t len, void* buffer);
   void StreamAsFile(const char* fname);
 
 private:
-  void Delete();
+  NPError NPN_DestroyStream(NPError reason);
 
   PluginInstanceParent* mNPP;
   NPStream* mStream;
-  CancelableTask* mDeleteTask;
 };
 
 } // namespace plugins
 } // namespace mozilla
 
 #endif
--- a/dom/plugins/PBrowserStream.ipdl
+++ b/dom/plugins/PBrowserStream.ipdl
@@ -61,23 +61,23 @@ child:
     returns (int32_t size);
 
   rpc NPP_Write(int32_t offset,
                 Buffer data)
     returns (int32_t consumed);
 
   rpc NPP_StreamAsFile(nsCString fname);
 
-  rpc NPP_DestroyStream(NPReason reason)
-    returns (NPError error);
-
-  async __delete__();
-
 parent:
   rpc NPN_RequestRead(IPCByteRanges ranges)
     returns (NPError result);
 
-  rpc NPN_DestroyStream(NPReason reason)
-    returns (NPError error);
+both:
+  /**
+   * ~PBrowserStream is for both NPN_DestroyStream and NPP_DestroyStream.
+   * @param artificial True when the stream is closed as a by-product of
+   *                        some other call (such as a failure in NPP_Write).
+   */
+  rpc __delete__(NPReason reason, bool artificial);
 };
 
 } // namespace plugins
 } // namespace mozilla
--- a/dom/plugins/PluginInstanceParent.cpp
+++ b/dom/plugins/PluginInstanceParent.cpp
@@ -607,17 +607,17 @@ PluginInstanceParent::NPP_NewStream(NPMI
                                        stream->lastmodified,
                                        static_cast<PStreamNotifyParent*>(stream->notifyData),
                                        NullableString(stream->headers),
                                        NullableString(type), seekable,
                                        &err, stype))
         return NPERR_GENERIC_ERROR;
 
     if (NPERR_NO_ERROR != err)
-        bs->NPP_DestroyStream(NPERR_GENERIC_ERROR);
+        PBrowserStreamParent::Call__delete__(bs, NPERR_GENERIC_ERROR, true);
 
     return err;
 }
 
 NPError
 PluginInstanceParent::NPP_DestroyStream(NPStream* stream, NPReason reason)
 {
     PLUGIN_LOG_DEBUG(("%s (stream=%p, reason=%i)",
@@ -625,17 +625,18 @@ PluginInstanceParent::NPP_DestroyStream(
 
     AStream* s = static_cast<AStream*>(stream->pdata);
     if (s->IsBrowserStream()) {
         BrowserStreamParent* sp =
             static_cast<BrowserStreamParent*>(s);
         if (sp->mNPP != this)
             NS_RUNTIMEABORT("Mismatched plugin data");
 
-        return sp->NPP_DestroyStream(reason);
+        PBrowserStreamParent::Call__delete__(sp, reason, false);
+        return NPERR_NO_ERROR;
     }
     else {
         PluginStreamParent* sp =
             static_cast<PluginStreamParent*>(s);
         if (sp->mInstance != this)
             NS_RUNTIMEABORT("Mismatched plugin data");
 
         PPluginStreamParent::Call__delete__(sp, reason, false);
--- a/dom/plugins/PluginModuleChild.cpp
+++ b/dom/plugins/PluginModuleChild.cpp
@@ -893,19 +893,17 @@ NPError NP_CALLBACK
     PLUGIN_LOG_DEBUG_FUNCTION;
     AssertPluginThread();
 
     PluginInstanceChild* p = InstCast(aNPP);
     AStream* s = static_cast<AStream*>(aStream->ndata);
     if (s->IsBrowserStream()) {
         BrowserStreamChild* bs = static_cast<BrowserStreamChild*>(s);
         bs->EnsureCorrectInstance(p);
-        NPError err = NPERR_NO_ERROR;
-        bs->CallNPN_DestroyStream(aReason, &err);
-        return err;
+        PBrowserStreamChild::Call__delete__(bs, aReason, false);
     }
     else {
         PluginStreamChild* ps = static_cast<PluginStreamChild*>(s);
         ps->EnsureCorrectInstance(p);
         PPluginStreamChild::Call__delete__(ps, aReason, false);
     }
     return NPERR_NO_ERROR;
 }