Skip to content

Commit

Permalink
Deprecate SbFile APIs.
Browse files Browse the repository at this point in the history
Change-Id: Ib016e4cbaf4fcc80634dbeb1ea902fb92adc10f6
  • Loading branch information
yjzhang111 committed Jul 18, 2024
1 parent d45a41a commit ab7356c
Show file tree
Hide file tree
Showing 83 changed files with 666 additions and 184 deletions.
6 changes: 3 additions & 3 deletions base/files/file_util_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "starboard/configuration_constants.h"
#include "starboard/common/file.h"
#include "starboard/directory.h"
#include "starboard/file.h"
#include "base/strings/strcat.h"
#include "starboard/system.h"

Expand Down Expand Up @@ -244,12 +244,12 @@ bool PathExists(const FilePath &path) {

bool PathIsReadable(const FilePath &path) {
internal::AssertBlockingAllowed();
return SbFileCanOpen(path.value().c_str(), kSbFileOpenAlways | kSbFileRead);
return starboard::FileCanOpen(path.value().c_str(), O_CREAT | O_RDONLY);
}

bool PathIsWritable(const FilePath &path) {
internal::AssertBlockingAllowed();
return SbFileCanOpen(path.value().c_str(), kSbFileOpenAlways | kSbFileWrite);
return starboard::FileCanOpen(path.value().c_str(), O_CREAT | O_WRONLY);
}

bool DirectoryExists(const FilePath& path) {
Expand Down
5 changes: 3 additions & 2 deletions cobalt/media/sandbox/format_guesstimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "media/filters/chunk_demuxer.h"
#include "net/base/filename_util.h"
#include "net/base/url_util.h"
#include "starboard/common/file.h"
#include "starboard/memory.h"
#include "starboard/types.h"
#include "ui/gfx/geometry/size.h"
Expand Down Expand Up @@ -81,7 +82,7 @@ base::FilePath ResolvePath(const std::string& path) {
base::PathService::Get(base::DIR_TEST_DATA, &content_path);
result = content_path.Append(result);
}
if (SbFileCanOpen(result.value().c_str(), kSbFileOpenOnly | kSbFileRead)) {
if (starboard::FileCanOpen(result.value().c_str(), O_RDONLY)) {
return result;
}
LOG(WARNING) << "Failed to resolve path \"" << path << "\" as \""
Expand Down Expand Up @@ -141,7 +142,7 @@ FormatGuesstimator::FormatGuesstimator(const std::string& path_or_url,
return;
}
base::FilePath path = ResolvePath(path_or_url);
if (path.empty() || !SbFileCanOpen(path.value().c_str(), kSbFileRead)) {
if (path.empty() || !starboard::FileCanOpen(path.value().c_str(), O_RDONLY)) {
return;
}
InitializeAsAdaptive(path, media_module);
Expand Down
32 changes: 15 additions & 17 deletions cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
#include "base/optional.h"
#include "base/path_service.h"
#include "starboard/common/file.h"
#include "starboard/common/file_wrapper.h"

// Implement functionality declared in SkOSFile.h via primitives provided
// by Chromium. In doing this, we need only ensure that support for Chromium
// file utilities is working and then Skia file utilities will also work.

namespace {

starboard::FilePtr ToFilePtr(FILE* sk_file) {
FilePtr ToFilePtr(FILE* sk_file) {
// PlatformFile is a pointer type in Starboard, so we cannot use static_cast
// from intptr_t.
return reinterpret_cast<starboard::FilePtr>(sk_file);
return reinterpret_cast<FilePtr>(sk_file);
}

FILE* ToFILE(starboard::FilePtr starboard_file) {
FILE* ToFILE(FilePtr starboard_file) {
return reinterpret_cast<FILE*>(starboard_file);
}

Expand All @@ -53,11 +54,8 @@ int ToFileFlags(SkFILE_Flags sk_flags) {
} // namespace

FILE* sk_fopen(const char path[], SkFILE_Flags sk_flags) {
starboard::FilePtr file;
file->fd = open(path, ToFileFlags(sk_flags), S_IRUSR | S_IWUSR);
// TODO: temporarily replace with kSbFileInvalid, will be deprecated with
// SBFile.
if (!file || !starboard::IsValid(file->fd)) {
FilePtr file = file_open(path, ToFileFlags(sk_flags));
if (!file || file->fd < 0) {
return nullptr;
}

Expand All @@ -66,12 +64,12 @@ FILE* sk_fopen(const char path[], SkFILE_Flags sk_flags) {

void sk_fclose(FILE* sk_file) {
SkASSERT(sk_file);
close(ToFilePtr(sk_file)->fd);
int ret = file_close(ToFilePtr(sk_file));
}

size_t sk_fgetsize(FILE* sk_file) {
SkASSERT(sk_file);
starboard::FilePtr file = ToFilePtr(sk_file);
FilePtr file = ToFilePtr(sk_file);

// Save current position so we can restore it.
int64_t current_position = lseek(file->fd, 0, SEEK_CUR);
Expand All @@ -92,7 +90,7 @@ size_t sk_fgetsize(FILE* sk_file) {

size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* sk_file) {
SkASSERT(sk_file);
starboard::FilePtr file = ToFilePtr(sk_file);
FilePtr file = ToFilePtr(sk_file);
int result =
write(file->fd, reinterpret_cast<const char*>(buffer), byteCount);
base::RecordFileWriteStat(result);
Expand All @@ -101,20 +99,20 @@ size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* sk_file) {

void sk_fflush(FILE* sk_file) {
SkASSERT(sk_file);
starboard::FilePtr file = ToFilePtr(sk_file);
FilePtr file = ToFilePtr(sk_file);
fsync(file->fd);
}

bool sk_fseek(FILE* sk_file, size_t position) {
SkASSERT(sk_file);
starboard::FilePtr file = ToFilePtr(sk_file);
FilePtr file = ToFilePtr(sk_file);
int64_t new_position = lseek(file->fd, position, SEEK_SET);
return new_position == position;
}

size_t sk_ftell(FILE* sk_file) {
SkASSERT(sk_file);
starboard::FilePtr file = ToFilePtr(sk_file);
FilePtr file = ToFilePtr(sk_file);
return lseek(file->fd, 0, SEEK_CUR);
}

Expand Down Expand Up @@ -159,15 +157,15 @@ bool sk_mkdir(const char* path) {

void sk_fsync(FILE* f) {
SkASSERT(f);
starboard::FilePtr file = ToFilePtr(f);
FilePtr file = ToFilePtr(f);
// Technically, flush doesn't have to call sync... but this is the best
// effort we can make.
fsync(file->fd);
}

size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) {
SkASSERT(file);
starboard::FilePtr starboard_file = ToFilePtr(file);
FilePtr starboard_file = ToFilePtr(file);

int original_position = lseek(starboard_file->fd, 0, SEEK_CUR);
if (original_position < 0) {
Expand All @@ -191,7 +189,7 @@ size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) {

size_t sk_fread(void* buffer, size_t byteCount, FILE* file) {
SkASSERT(file);
starboard::FilePtr starboard_file = ToFilePtr(file);
FilePtr starboard_file = ToFilePtr(file);
return starboard::ReadAll(starboard_file->fd, reinterpret_cast<char*>(buffer),
byteCount);
}
6 changes: 4 additions & 2 deletions components/update_client/action_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "components/update_client/action_runner.h"

#include <unistd.h>

#include <iterator>
#include <stack>
#include <utility>
Expand Down Expand Up @@ -42,11 +44,11 @@ void CleanupDirectory(base::FilePath& dir) {
if (info.IsDirectory()) {
directories.push(path.value());
} else {
SbFileDelete(path.value().c_str());
unlink(path.value().c_str());
}
}
while (!directories.empty()) {
SbFileDelete(directories.top().c_str());
rmdir(directories.top().c_str());
directories.pop();
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/update_client/url_fetcher_downloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ void CleanupDirectory(base::FilePath& dir) {
if (info.IsDirectory()) {
directories.push(path.value());
} else {
SbFileDelete(path.value().c_str());
unlink(path.value().c_str());
}
}
while (!directories.empty()) {
SbFileDelete(directories.top().c_str());
rmdir(directories.top().c_str());
directories.pop();
}
}
Expand Down
4 changes: 4 additions & 0 deletions starboard/android/shared/file_can_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand Down Expand Up @@ -41,3 +43,5 @@ bool SbFileCanOpen(const char* path, int flags) {

return result;
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_close.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand All @@ -28,3 +30,5 @@ bool SbFileClose(SbFile file) {

return ::starboard::shared::posix::impl::FileClose(file);
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include "starboard/android/shared/file_internal.h"
Expand All @@ -20,3 +22,5 @@
bool SbFileDelete(const char* path) {
return ::starboard::shared::posix::impl::FileDelete(path);
}

#endif // SB_API_VERSION < 16
4 changes: 3 additions & 1 deletion starboard/android/shared/file_exists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

bool SbFileExists(const char* path) {
return SbFileCanOpen(path, kSbFileRead);
}
#endif

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include "starboard/android/shared/file_internal.h"
Expand All @@ -20,3 +22,5 @@
bool SbFileFlush(SbFile file) {
return ::starboard::shared::posix::impl::FileFlush(file);
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_get_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand All @@ -32,3 +34,5 @@ bool SbFileGetInfo(SbFile file, SbFileInfo* out_info) {

return ::starboard::shared::posix::impl::FileGetInfo(file, out_info);
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand Down Expand Up @@ -104,3 +106,5 @@ SbFile SbFileOpen(const char* path,
}
return kSbFileInvalid;
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand All @@ -30,3 +32,5 @@ int SbFileRead(SbFile file, char* data, int size) {
return ::starboard::shared::posix::impl::FileRead(file, data, size);
}
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_seek.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <android/asset_manager.h>
Expand All @@ -26,3 +28,5 @@ int64_t SbFileSeek(SbFile file, SbFileWhence whence, int64_t offset) {
return ::starboard::shared::posix::impl::FileSeek(file, whence, offset);
}
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_truncate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include "starboard/android/shared/file_internal.h"
Expand All @@ -20,3 +22,5 @@
bool SbFileTruncate(SbFile file, int64_t length) {
return ::starboard::shared::posix::impl::FileTruncate(file, length);
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/android/shared/file_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include "starboard/android/shared/file_internal.h"
Expand All @@ -20,3 +22,5 @@
int SbFileWrite(SbFile file, const char* data, int size) {
return ::starboard::shared::posix::impl::FileWrite(file, data, size);
}

#endif // SB_API_VERSION < 16
5 changes: 4 additions & 1 deletion starboard/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ static_library("common") {

static_library("file_wrapper") {
check_includes = false
sources = [ "file_wrapper.h" ]
sources = [
"file_wrapper.cc",
"file_wrapper.h",
]
}

target(gtest_target_type, "common_test") {
Expand Down
Loading

0 comments on commit ab7356c

Please sign in to comment.