Bug 860731 - Part b: Use FileMode for LockedFile; r=janv
authorMs2ger <ms2ger@gmail.com>
Wed, 12 Jun 2013 09:00:06 +0200
changeset 134706 7880cbf6200f482cc37aa9ff715813adf5e33eeb
parent 134705 e20539356853f52a09c54a02a7a5e8a40564feb8
child 134707 4eba1004b5ebaf48aef4cb96caab9d079fdd06b1
push id24811
push userMs2ger@gmail.com
push dateWed, 12 Jun 2013 07:00:25 +0000
treeherdermozilla-central@0414d6d0f60d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs860731
milestone24.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 860731 - Part b: Use FileMode for LockedFile; r=janv
dom/file/FileHandle.cpp
dom/file/FileHandle.h
dom/file/FileService.cpp
dom/file/LockedFile.cpp
dom/file/LockedFile.h
dom/file/MetadataHelper.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/webidl/FileHandle.webidl
dom/webidl/FileMode.webidl
dom/webidl/WebIDL.mk
--- a/dom/file/FileHandle.cpp
+++ b/dom/file/FileHandle.cpp
@@ -11,16 +11,17 @@
 
 #include "nsIDOMFile.h"
 #include "nsIFileStorage.h"
 
 #include "FileRequest.h"
 #include "FileService.h"
 #include "LockedFile.h"
 #include "MetadataHelper.h"
+#include "mozilla/dom/FileHandleBinding.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 USING_FILE_NAMESPACE
 
 namespace {
 
 class GetFileHelper : public MetadataHelper
@@ -107,25 +108,17 @@ FileHandle::Open(FileMode aMode, ErrorRe
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (FileService::IsShuttingDown() || mFileStorage->IsShuttingDown()) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
-  MOZ_STATIC_ASSERT(static_cast<uint32_t>(FileMode::Readonly) ==
-                    static_cast<uint32_t>(LockedFile::READ_ONLY),
-                    "Enum values should match.");
-  MOZ_STATIC_ASSERT(static_cast<uint32_t>(FileMode::Readwrite) ==
-                    static_cast<uint32_t>(LockedFile::READ_WRITE),
-                    "Enum values should match.");
-
-  nsRefPtr<LockedFile> lockedFile =
-    LockedFile::Create(this, LockedFile::Mode(static_cast<int>(aMode)));
+  nsRefPtr<LockedFile> lockedFile = LockedFile::Create(this, aMode);
   if (!lockedFile) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   return lockedFile.forget();
 }
 
@@ -144,17 +137,17 @@ FileHandle::GetFile(ErrorResult& aError)
   MOZ_ASSERT(NS_IsMainThread());
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return nullptr;
   }
 
   nsRefPtr<LockedFile> lockedFile =
-    LockedFile::Create(this, LockedFile::READ_ONLY, LockedFile::PARALLEL);
+    LockedFile::Create(this, FileMode::Readonly, LockedFile::PARALLEL);
   if (!lockedFile) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   nsRefPtr<FileRequest> request =
     FileRequest::Create(GetOwner(), lockedFile, false);
 
--- a/dom/file/FileHandle.h
+++ b/dom/file/FileHandle.h
@@ -11,17 +11,17 @@
 
 #include "nsIDOMFileHandle.h"
 #include "nsIFile.h"
 #include "nsIFileStorage.h"
 
 #include "nsDOMEventTargetHelper.h"
 
 #include "mozilla/Attributes.h"
-#include "mozilla/dom/FileHandleBinding.h"
+#include "mozilla/dom/FileModeBinding.h"
 
 class nsIDOMFile;
 class nsIFileStorage;
 
 namespace mozilla {
 namespace dom {
 class DOMRequest;
 } // namespace dom
--- a/dom/file/FileService.cpp
+++ b/dom/file/FileService.cpp
@@ -153,17 +153,17 @@ FileService::Enqueue(LockedFile* aLocked
   FileHandle* fileHandle = aLockedFile->mFileHandle;
 
   if (fileHandle->mFileStorage->IsInvalidated()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsIAtom* storageId = fileHandle->mFileStorage->Id();
   const nsAString& fileName = fileHandle->mFileName;
-  bool modeIsWrite = aLockedFile->mMode == LockedFile::READ_WRITE;
+  bool modeIsWrite = aLockedFile->mMode == FileMode::Readwrite;
 
   FileStorageInfo* fileStorageInfo;
   if (!mFileStorageInfos.Get(storageId, &fileStorageInfo)) {
     nsAutoPtr<FileStorageInfo> newFileStorageInfo(new FileStorageInfo());
 
     mFileStorageInfos.Put(storageId, newFileStorageInfo);
 
     fileStorageInfo = newFileStorageInfo.forget();
@@ -451,17 +451,17 @@ FileService::FileStorageInfo::RemoveLock
       index--;
       count--;
 
       continue;
     }
 
     const nsAString& fileName = lockedFile->mFileHandle->mFileName;
 
-    if (lockedFile->mMode == LockedFile::READ_WRITE) {
+    if (lockedFile->mMode == FileMode::Readwrite) {
       if (!IsFileLockedForWriting(fileName)) {
         LockFileForWriting(fileName);
       }
     }
     else {
       if (!IsFileLockedForReading(fileName)) {
         LockFileForReading(fileName);
       }
--- a/dom/file/LockedFile.cpp
+++ b/dom/file/LockedFile.cpp
@@ -31,18 +31,19 @@
 #include "MetadataHelper.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 
 #include "mozilla/dom/EncodingUtils.h"
 
 #define STREAM_COPY_BLOCK_SIZE 32768
 
+using namespace mozilla;
+using namespace mozilla::dom;
 USING_FILE_NAMESPACE
-using mozilla::dom::EncodingUtils;
 
 namespace {
 
 NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 class ReadHelper : public FileHelper
 {
 public:
@@ -272,17 +273,17 @@ GetInputStreamForJSVal(const JS::Value& 
   return NS_OK;
 }
 
 } // anonymous namespace
 
 // static
 already_AddRefed<LockedFile>
 LockedFile::Create(FileHandle* aFileHandle,
-                   Mode aMode,
+                   FileMode aMode,
                    RequestMode aRequestMode)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   nsRefPtr<LockedFile> lockedFile = new LockedFile();
 
   lockedFile->BindToOwner(aFileHandle);
 
@@ -304,17 +305,17 @@ LockedFile::Create(FileHandle* aFileHand
   rv = service->Enqueue(lockedFile, nullptr);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   return lockedFile.forget();
 }
 
 LockedFile::LockedFile()
 : mReadyState(INITIAL),
-  mMode(READ_ONLY),
+  mMode(FileMode::Readonly),
   mRequestMode(NORMAL),
   mLocation(0),
   mPendingRequests(0),
   mAborted(false),
   mCreating(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
@@ -384,17 +385,17 @@ LockedFile::CreateParallelStream(nsISupp
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   nsIFileStorage* fileStorage = mFileHandle->mFileStorage;
   if (fileStorage->IsInvalidated()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsCOMPtr<nsISupports> stream =
-    mFileHandle->CreateStream(mFileHandle->mFile, mMode == READ_ONLY);
+    mFileHandle->CreateStream(mFileHandle->mFile, mMode == FileMode::Readonly);
   NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
 
   mParallelStreams.AppendElement(stream);
 
   stream.forget(aStream);
   return NS_OK;
 }
 
@@ -405,17 +406,17 @@ LockedFile::GetOrCreateStream(nsISupport
 
   nsIFileStorage* fileStorage = mFileHandle->mFileStorage;
   if (fileStorage->IsInvalidated()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   if (!mStream) {
     nsCOMPtr<nsISupports> stream =
-      mFileHandle->CreateStream(mFileHandle->mFile, mMode == READ_ONLY);
+      mFileHandle->CreateStream(mFileHandle->mFile, mMode == FileMode::Readonly);
     NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
 
     stream.swap(mStream);
   }
 
   nsCOMPtr<nsISupports> stream(mStream);
   stream.forget(aStream);
 
@@ -468,20 +469,20 @@ LockedFile::GetFileHandle(nsIDOMFileHand
 }
 
 NS_IMETHODIMP
 LockedFile::GetMode(nsAString& aMode)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   switch (mMode) {
-   case READ_ONLY:
+   case FileMode::Readonly:
      aMode.AssignLiteral("readonly");
      break;
-   case READ_WRITE:
+   case FileMode::Readwrite:
      aMode.AssignLiteral("readwrite");
      break;
    default:
      NS_NOTREACHED("Unknown mode!");
   }
 
   return NS_OK;
 }
@@ -687,17 +688,17 @@ LockedFile::Truncate(uint64_t aSize,
                      nsISupports** _retval)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   if (!IsOpen()) {
     return NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR;
   }
 
-  if (mMode != READ_WRITE) {
+  if (mMode != FileMode::Readwrite) {
     return NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR;
   }
 
   uint64_t location;
   if (aOptionalArgCount) {
     // Just in case someone calls us from C++
     NS_ASSERTION(aSize != UINT64_MAX, "Passed wrong size!");
     location = aSize;
@@ -736,17 +737,17 @@ NS_IMETHODIMP
 LockedFile::Flush(nsISupports** _retval)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   if (!IsOpen()) {
     return NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR;
   }
 
-  if (mMode != READ_WRITE) {
+  if (mMode != FileMode::Readwrite) {
     return NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR;
   }
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return NS_OK;
   }
 
@@ -844,17 +845,17 @@ LockedFile::WriteOrAppend(const JS::Valu
                           JSContext* aCx,
                           nsISupports** _retval,
                           bool aAppend)
 {
   if (!IsOpen()) {
     return NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR;
   }
 
-  if (mMode != READ_WRITE) {
+  if (mMode != FileMode::Readwrite) {
     return NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR;
   }
 
   if (!aAppend && mLocation == UINT64_MAX) {
     return NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR;
   }
 
   // Do nothing if the window is closed
--- a/dom/file/LockedFile.h
+++ b/dom/file/LockedFile.h
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_file_lockedfile_h__
 #define mozilla_dom_file_lockedfile_h__
 
 #include "mozilla/Attributes.h"
 #include "FileCommon.h"
-
+#include "mozilla/dom/FileModeBinding.h"
 #include "nsIDOMLockedFile.h"
 #include "nsIRunnable.h"
 
 #include "nsDOMEventTargetHelper.h"
 
 class nsIInputStream;
 
 BEGIN_FILE_NAMESPACE
@@ -34,39 +34,33 @@ class LockedFile : public nsDOMEventTarg
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMLOCKEDFILE
   NS_DECL_NSIRUNNABLE
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LockedFile, nsDOMEventTargetHelper)
 
-  enum Mode
-  {
-    READ_ONLY = 0,
-    READ_WRITE
-  };
-
   enum RequestMode
   {
     NORMAL = 0, // Sequential
     PARALLEL
   };
 
   enum ReadyState
   {
     INITIAL = 0,
     LOADING,
     FINISHING,
     DONE
   };
 
   static already_AddRefed<LockedFile>
   Create(FileHandle* aFileHandle,
-         Mode aMode,
+         FileMode aMode,
          RequestMode aRequestMode = NORMAL);
 
   // nsIDOMEventTarget
   virtual nsresult
   PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
 
   nsresult
   CreateParallelStream(nsISupports** aStream);
@@ -110,17 +104,17 @@ private:
   WriteOrAppend(const jsval& aValue, JSContext* aCx,
                 nsISupports** _retval, bool aAppend);
 
   nsresult
   Finish();
 
   nsRefPtr<FileHandle> mFileHandle;
   ReadyState mReadyState;
-  Mode mMode;
+  FileMode mMode;
   RequestMode mRequestMode;
   uint64_t mLocation;
   uint32_t mPendingRequests;
 
   nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
   nsCOMPtr<nsISupports> mStream;
 
   bool mAborted;
--- a/dom/file/MetadataHelper.cpp
+++ b/dom/file/MetadataHelper.cpp
@@ -8,17 +8,17 @@
 
 #include "LockedFile.h"
 
 USING_FILE_NAMESPACE
 
 nsresult
 MetadataHelper::DoAsyncRun(nsISupports* aStream)
 {
-  bool readWrite = mLockedFile->mMode == LockedFile::READ_WRITE;
+  bool readWrite = mLockedFile->mMode == FileMode::Readwrite;
 
   nsRefPtr<AsyncMetadataGetter> getter =
     new AsyncMetadataGetter(aStream, mParams, readWrite);
 
   nsresult rv = getter->AsyncWork(this, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -9,16 +9,17 @@
 #include "IDBObjectStore.h"
 
 #include "mozilla/dom/ipc/nsIRemoteBlob.h"
 #include "nsIOutputStream.h"
 
 #include "jsfriendapi.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
+#include "mozilla/dom/FileHandleBinding.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/ipc/Blob.h"
 #include "mozilla/dom/quota/FileStreams.h"
 #include "mozilla/storage.h"
 #include "nsContentUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsDOMFile.h"
 #include "nsDOMLists.h"
--- a/dom/webidl/FileHandle.webidl
+++ b/dom/webidl/FileHandle.webidl
@@ -1,17 +1,15 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 interface LockedFile;
 
-enum FileMode { "readonly", "readwrite" };
-
 interface FileHandle : EventTarget {
   readonly attribute DOMString name;
   readonly attribute DOMString type;
 
   [Throws]
   LockedFile open(optional FileMode mode = "readonly");
 
   [Throws]
new file mode 100644
--- /dev/null
+++ b/dom/webidl/FileMode.webidl
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+enum FileMode { "readonly", "readwrite" };
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -75,16 +75,17 @@ webidl_files = \
   Event.webidl \
   EventHandler.webidl \
   EventListener.webidl \
   EventSource.webidl \
   EventTarget.webidl \
   File.webidl \
   FileHandle.webidl \
   FileList.webidl \
+  FileMode.webidl \
   FileReader.webidl \
   FileReaderSync.webidl \
   FileRequest.webidl \
   FocusEvent.webidl \
   FormData.webidl \
   Function.webidl \
   GainNode.webidl \
   Geolocation.webidl \