Bug 572579 - Commit merge. a=backout
authorChris Pearce <chris@pearce.org.nz>
Tue, 26 Oct 2010 17:44:12 +1300
changeset 56486 41d1e4327b9f239933f520fb0123246b3b4321d2
parent 56483 987686fe67cb00e995adf55e737e245ed851bc43 (current diff)
parent 56484 70f12cfa19d9735af64be7bebec582b64ccd5f73 (diff)
child 56487 c9074c25fd5a86f02cb671fb68ec24692feeb419
push id16573
push usercpearce@mozilla.com
push dateTue, 26 Oct 2010 04:45:26 +0000
treeherdermozilla-central@c9074c25fd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs572579
milestone2.0b8pre
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 572579 - Commit merge. a=backout
--- a/content/media/nsMediaCache.cpp
+++ b/content/media/nsMediaCache.cpp
@@ -66,17 +66,17 @@ static const double NONSEEKABLE_READAHEA
 
 // Assume that any replaying or backward seeking will happen
 // this far in the future (in seconds). This is a random guess/estimate
 // penalty to account for the possibility that we might not replay at
 // all.
 static const PRUint32 REPLAY_DELAY = 30;
 
 // When looking for a reusable block, scan forward this many blocks
-// from the desired "best" block location to look for free blocks,
+// from the desired "best" block location to look for free blocks, 
 // before we resort to scanning the whole cache. The idea is to try to
 // store runs of stream blocks close-to-consecutively in the cache if we
 // can.
 static const PRUint32 FREE_BLOCK_SCAN_LIMIT = 16;
 
 using mozilla::TimeStamp;
 using mozilla::TimeDuration;
 
@@ -551,51 +551,45 @@ nsMediaCache::Init()
 
   if (!mMonitor) {
     // the constructor failed
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   nsCOMPtr<nsIFile> tmp;
   nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmp));
-  NS_ENSURE_SUCCESS(rv,rv);
-
+  if (NS_FAILED(rv))
+    return rv;
   nsCOMPtr<nsILocalFile> tmpFile = do_QueryInterface(tmp);
-  NS_ENSURE_TRUE(tmpFile != nsnull, NS_ERROR_FAILURE);
 
   // We put the media cache file in
   // ${TempDir}/mozilla-media-cache/media_cache
+  if (!tmpFile)
+    return NS_ERROR_FAILURE;
   rv = tmpFile->AppendNative(nsDependentCString("mozilla-media-cache"));
-  NS_ENSURE_SUCCESS(rv,rv);
+  if (NS_FAILED(rv))
+    return rv;
+  rv = tmpFile->Create(nsIFile::DIRECTORY_TYPE, 0600);
+  if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS)
+    return rv;
 
-  rv = tmpFile->Create(nsIFile::DIRECTORY_TYPE, 0700);
-  if (rv == NS_ERROR_FILE_ALREADY_EXISTS) {
-    // Ensure the permissions are 0700. If not, we won't be able to create,
-    // read to and write from the media cache file in its subdirectory on
-    // non-Windows platforms.
-    PRUint32 perms;
-    rv = tmpFile->GetPermissions(&perms);
-    NS_ENSURE_SUCCESS(rv,rv);
-    if (perms != 0700) {
-      rv = tmpFile->SetPermissions(0700);
-      NS_ENSURE_SUCCESS(rv,rv);
-    }
-  } else {
-    NS_ENSURE_SUCCESS(rv,rv);
-  }
+  rv = tmpFile->Create(nsIFile::DIRECTORY_TYPE, 0600);
+  if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS)
+    return rv;
 
   rv = tmpFile->AppendNative(nsDependentCString("media_cache"));
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0700);
-  NS_ENSURE_SUCCESS(rv,rv);
-
+  if (NS_FAILED(rv))
+    return rv;
+  rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
+  if (NS_FAILED(rv))
+    return rv;
   rv = tmpFile->OpenNSPRFileDesc(PR_RDWR | nsILocalFile::DELETE_ON_CLOSE,
                                  PR_IRWXU, &mFD);
-  NS_ENSURE_SUCCESS(rv,rv);
+  if (NS_FAILED(rv))
+    return rv;
 
 #ifdef PR_LOGGING
   if (!gMediaCacheLog) {
     gMediaCacheLog = PR_NewLogModule("nsMediaCache");
   }
 #endif
 
   nsMediaCacheFlusher::Init();
@@ -631,17 +625,17 @@ nsMediaCache::FlushInternal()
     mFD = nsnull;
   }
   Init();
 }
 
 void
 nsMediaCache::MaybeShutdown()
 {
-  NS_ASSERTION(NS_IsMainThread(),
+  NS_ASSERTION(NS_IsMainThread(), 
                "nsMediaCache::MaybeShutdown called on non-main thread");
   if (!gMediaCache->mStreams.IsEmpty()) {
     // Don't shut down yet, streams are still alive
     return;
   }
 
   // Since we're on the main thread, no-one is going to add a new stream
   // while we shut down.
@@ -1499,17 +1493,17 @@ nsMediaCache::AllocateAndWriteBlock(nsMe
 
   // Extend the mBlocks array as necessary
 
   TimeStamp now = TimeStamp::Now();
   PRInt32 blockIndex = FindBlockForIncomingData(now, aStream);
   if (blockIndex >= 0) {
     FreeBlock(blockIndex);
 
-    Block* block = &mIndex[blockIndex];
+    Block* block = &mIndex[blockIndex];    
     LOG(PR_LOG_DEBUG, ("Allocated block %d to stream %p block %d(%lld)",
         blockIndex, aStream, streamBlockIndex, (long long)streamBlockIndex*BLOCK_SIZE));
 
     mFreeBlocks.RemoveBlock(blockIndex);
 
     // Tell each stream using this resource about the new block.
     ResourceStreamIterator iter(aStream->mResourceID);
     while (nsMediaCacheStream* stream = iter.Next()) {
@@ -1706,17 +1700,17 @@ nsMediaCacheStream::NotifyDataLength(PRI
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsAutoMonitor mon(gMediaCache->Monitor());
   mStreamLength = aLength;
 }
 
 void
-nsMediaCacheStream::NotifyDataStarted(PRInt64 aOffset)
+nsMediaCacheStream::NotifyDataStarted(PRInt64 aOffset) 
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsAutoMonitor mon(gMediaCache->Monitor());
   NS_WARN_IF_FALSE(aOffset == mChannelOffset,
                    "Server is giving us unexpected offset");
   mChannelOffset = aOffset;
   if (mStreamLength >= 0) {
@@ -1826,17 +1820,17 @@ nsMediaCacheStream::NotifyDataReceived(P
 
   // Notify in case there's a waiting reader
   // XXX it would be fairly easy to optimize things a lot more to
   // avoid waking up reader threads unnecessarily
   mon.NotifyAll();
 }
 
 void
-nsMediaCacheStream::NotifyDataEnded(nsresult aStatus)
+nsMediaCacheStream::NotifyDataEnded(nsresult aStatus) 
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsAutoMonitor mon(gMediaCache->Monitor());
 
   PRInt32 blockOffset = PRInt32(mChannelOffset%BLOCK_SIZE);
   if (blockOffset > 0) {
     // Write back the partial block
@@ -1990,17 +1984,17 @@ nsMediaCacheStream::GetCachedDataEndInte
 }
 
 PRInt64
 nsMediaCacheStream::GetNextCachedDataInternal(PRInt64 aOffset)
 {
   PR_ASSERT_CURRENT_THREAD_IN_MONITOR(gMediaCache->Monitor());
   if (aOffset == mStreamLength)
     return -1;
-
+  
   PRUint32 startBlockIndex = aOffset/BLOCK_SIZE;
   PRUint32 channelBlockIndex = mChannelOffset/BLOCK_SIZE;
 
   if (startBlockIndex == channelBlockIndex &&
       aOffset < mChannelOffset) {
     // The block containing mChannelOffset is partially read, but not
     // yet committed to the main cache. aOffset lies in the partially
     // read portion, thus it is effectively cached.
@@ -2231,17 +2225,17 @@ nsMediaCacheStream::ReadFromCache(char* 
       nsresult rv = gMediaCache->ReadCacheFile(offset, aBuffer + count, size, &bytes);
       if (NS_FAILED(rv)) {
         return rv;
       }
     }
     streamOffset += bytes;
     count += bytes;
   }
-
+  
   return NS_OK;
 }
 
 nsresult
 nsMediaCacheStream::Init()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");