Commit 7c8c782e authored by Jari Jalkanen's avatar Jari Jalkanen
Browse files

Bug 18267804 - Use ContentType instead of nsString as OPFS file type. r=dom-storage-reviewers,janv

parent 60e17658
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ FileSystemAccessHandle::BeginInit() {
    return CreateAndRejectMozPromise<InitPromise>(aFunc, aRv);
  };

  nsString type;
  fs::ContentType type;
  fs::TimeStamp lastModifiedMilliSeconds;
  fs::Path path;
  nsCOMPtr<nsIFile> file;
+6 −5
Original line number Diff line number Diff line
@@ -102,9 +102,10 @@ IPCResult FileSystemManagerParent::RecvGetFileHandle(
    aResolver(response);
  };

  ContentType type;
  QM_TRY_UNWRAP(fs::EntryId entryId,
                mDataManager->MutableDatabaseManagerPtr()->GetOrCreateFile(
                    aRequest.handle(), aRequest.create()),
                    aRequest.handle(), type, aRequest.create()),
                IPC_OK(), reportError);
  MOZ_ASSERT(!entryId.IsEmpty());

@@ -200,7 +201,7 @@ mozilla::ipc::IPCResult FileSystemManagerParent::RecvGetWritable(

  auto reportError = [aResolver](nsresult rv) { aResolver(rv); };

  nsString type;
  fs::ContentType type;
  fs::TimeStamp lastModifiedMilliSeconds;
  fs::Path path;
  nsCOMPtr<nsIFile> file;
@@ -263,7 +264,7 @@ IPCResult FileSystemManagerParent::RecvGetFile(
    aResolver(rv);
  };

  nsString type;
  fs::ContentType type;
  fs::TimeStamp lastModifiedMilliSeconds;
  fs::Path path;
  nsCOMPtr<nsIFile> fileObject;
@@ -281,8 +282,8 @@ IPCResult FileSystemManagerParent::RecvGetFile(

  // TODO: Currently, there is no way to assign type and it is empty.
  // See bug 1826780.
  RefPtr<BlobImpl> blob =
      MakeRefPtr<FileBlobImpl>(fileObject, path.LastElement(), type);
  RefPtr<BlobImpl> blob = MakeRefPtr<FileBlobImpl>(
      fileObject, path.LastElement(), NS_ConvertUTF8toUTF16(type));

  IPCBlob ipcBlob;
  QM_TRY(MOZ_TO_RESULT(IPCBlobUtils::Serialize(blob, ipcBlob)), IPC_OK(),
+6 −2
Original line number Diff line number Diff line
@@ -70,7 +70,11 @@ class ResultStatement {

  inline nsresult BindContentTypeByName(const nsACString& aField,
                                        const ContentType& aValue) {
    return mStmt->BindStringByName(aField, aValue);
    if (0u == aValue.Length()) {  // Otherwise empty string becomes null
      return mStmt->BindUTF8StringByName(aField, aValue);
    }

    return mStmt->BindUTF8StringAsBlobByName(aField, aValue);
  }

  inline nsresult BindNameByName(const nsACString& aField, const Name& aValue) {
@@ -99,7 +103,7 @@ class ResultStatement {

  inline Result<ContentType, QMResult> GetContentTypeByColumn(Column aColumn) {
    ContentType value;
    QM_TRY(QM_TO_RESULT(mStmt->GetString(aColumn, value)));
    QM_TRY(QM_TO_RESULT(mStmt->GetUTF8String(aColumn, value)));

    return value;
  }
+5 −2
Original line number Diff line number Diff line
@@ -85,15 +85,18 @@ class FileSystemDatabaseManager {
   * @brief Returns file identifier, optionally creating it if it doesn't exist
   *
   * @param aHandle Current directory and filename
   * @param aType Content type which is ignored if the file already exists
   * @param aCreate true if file is to be created when it does not already exist
   * @return Result<bool, QMResult> File identifier or error
   */
  virtual Result<EntryId, QMResult> GetOrCreateFile(
      const FileSystemChildMetadata& aHandle, bool aCreate) = 0;
      const FileSystemChildMetadata& aHandle, const ContentType& aType,
      bool aCreate) = 0;

  /**
   * @brief Returns the properties of a file corresponding to a file handle
   */
  virtual nsresult GetFile(const EntryId& aEntryId, nsString& aType,
  virtual nsresult GetFile(const EntryId& aEntryId, ContentType& aType,
                           TimeStamp& lastModifiedMilliSeconds, Path& aPath,
                           nsCOMPtr<nsIFile>& aFile) const = 0;

+6 −4
Original line number Diff line number Diff line
@@ -857,7 +857,8 @@ FileSystemDatabaseManagerVersion001::GetOrCreateDirectory(
}

Result<EntryId, QMResult> FileSystemDatabaseManagerVersion001::GetOrCreateFile(
    const FileSystemChildMetadata& aHandle, bool aCreate) {
    const FileSystemChildMetadata& aHandle, const ContentType& aType,
    bool aCreate) {
  MOZ_ASSERT(!aHandle.parentId().IsEmpty());

  const auto& name = aHandle.childName();
@@ -894,9 +895,9 @@ Result<EntryId, QMResult> FileSystemDatabaseManagerVersion001::GetOrCreateFile(

  const nsLiteralCString insertFileQuery =
      "INSERT INTO Files "
      "( handle, name ) "
      "( handle, type, name ) "
      "VALUES "
      "( :handle, :name ) "
      "( :handle, :type, :name ) "
      ";"_ns;

  QM_TRY_UNWRAP(EntryId entryId, GetUniqueEntryId(mConnection, aHandle));
@@ -917,6 +918,7 @@ Result<EntryId, QMResult> FileSystemDatabaseManagerVersion001::GetOrCreateFile(
    QM_TRY_UNWRAP(ResultStatement stmt,
                  ResultStatement::Create(mConnection, insertFileQuery));
    QM_TRY(QM_TO_RESULT(stmt.BindEntryIdByName("handle"_ns, entryId)));
    QM_TRY(QM_TO_RESULT(stmt.BindContentTypeByName("type"_ns, aType)));
    QM_TRY(QM_TO_RESULT(stmt.BindNameByName("name"_ns, name)));
    QM_TRY(QM_TO_RESULT(stmt.Execute()));
  }
@@ -967,7 +969,7 @@ FileSystemDatabaseManagerVersion001::GetDirectoryEntries(
}

nsresult FileSystemDatabaseManagerVersion001::GetFile(
    const EntryId& aEntryId, nsString& aType,
    const EntryId& aEntryId, ContentType& aType,
    TimeStamp& lastModifiedMilliSeconds, nsTArray<Name>& aPath,
    nsCOMPtr<nsIFile>& aFile) const {
  MOZ_ASSERT(!aEntryId.IsEmpty());
Loading