Bug 1286165 (Part 1) - Allow advancing a SourceBufferIterator without an IResumable. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 12 Jul 2016 00:15:03 -0700
changeset 388585 ab4ae8b37941493a3ec12506d28fc82ec3bf5c34
parent 388584 8033580f6a1d20abe8635ad724866475631263e6
child 388586 e2069b87af4c2291c9d2ef391c7759c3464d0341
push id23207
push userrthijssen@mozilla.com
push dateSat, 16 Jul 2016 09:33:55 +0000
reviewersedwin
bugs1286165
milestone50.0a1
Bug 1286165 (Part 1) - Allow advancing a SourceBufferIterator without an IResumable. r=edwin
image/SourceBuffer.cpp
image/SourceBuffer.h
--- a/image/SourceBuffer.cpp
+++ b/image/SourceBuffer.cpp
@@ -232,17 +232,19 @@ SourceBuffer::FibonacciCapacityWithMinim
 
 void
 SourceBuffer::AddWaitingConsumer(IResumable* aConsumer)
 {
   mMutex.AssertCurrentThreadOwns();
 
   MOZ_ASSERT(!mStatus, "Waiting when we're complete?");
 
-  mWaitingConsumers.AppendElement(aConsumer);
+  if (aConsumer) {
+    mWaitingConsumers.AppendElement(aConsumer);
+  }
 }
 
 void
 SourceBuffer::ResumeWaitingConsumers()
 {
   mMutex.AssertCurrentThreadOwns();
 
   if (mWaitingConsumers.Length() == 0) {
--- a/image/SourceBuffer.h
+++ b/image/SourceBuffer.h
@@ -104,19 +104,46 @@ public:
 
   /**
    * Returns true if there are no more than @aBytes remaining in the
    * SourceBuffer. If the SourceBuffer is not yet complete, returns false.
    */
   bool RemainingBytesIsNoMoreThan(size_t aBytes) const;
 
   /**
-   * Advances the iterator through the SourceBuffer if possible. If not,
-   * arranges to call the @aConsumer's Resume() method when more data is
-   * available.
+   * Advances the iterator through the SourceBuffer if possible.
+   *
+   * This is a wrapper around AdvanceOrScheduleResume() that makes it clearer at
+   * the callsite when the no resuming is intended.
+   *
+   * @return State::READY if the iterator was successfully advanced.
+   *         State::WAITING if the iterator could not be advanced because it's
+   *           at the end of the underlying SourceBuffer, but the SourceBuffer
+   *           may still receive additional data.
+   *         State::COMPLETE if the iterator could not be advanced because it's
+   *           at the end of the underlying SourceBuffer and the SourceBuffer is
+   *           marked complete (i.e., it will never receive any additional
+   *           data).
+   */
+  State Advance() { return AdvanceOrScheduleResume(nullptr); }
+
+  /**
+   * Advances the iterator through the SourceBuffer if possible. If advancing is
+   * not possible and @aConsumer is not null, arranges to call the @aConsumer's
+   * Resume() method when more data is available.
+   *
+   * @return State::READY if the iterator was successfully advanced.
+   *         State::WAITING if the iterator could not be advanced because it's
+   *           at the end of the underlying SourceBuffer, but the SourceBuffer
+   *           may still receive additional data. @aConsumer's Resume() method
+   *           will be called when additional data is available.
+   *         State::COMPLETE if the iterator could not be advanced because it's
+   *           at the end of the underlying SourceBuffer and the SourceBuffer is
+   *           marked complete (i.e., it will never receive any additional
+   *           data).
    */
   State AdvanceOrScheduleResume(IResumable* aConsumer);
 
   /// If at the end, returns the status passed to SourceBuffer::Complete().
   nsresult CompletionStatus() const
   {
     MOZ_ASSERT(mState == COMPLETE,
                "Calling CompletionStatus() in the wrong state");