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 305176 ab4ae8b37941493a3ec12506d28fc82ec3bf5c34
parent 305175 8033580f6a1d20abe8635ad724866475631263e6
child 305177 e2069b87af4c2291c9d2ef391c7759c3464d0341
push id30455
push usercbook@mozilla.com
push dateSun, 17 Jul 2016 08:08:29 +0000
treeherdermozilla-central@711963e8daa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1286165
milestone50.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 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");