diff --git a/base/BUILD.gn b/base/BUILD.gn index 5ad4e4869019..57d330c19ad0 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -103,7 +103,7 @@ if (is_apple) { # Determines whether libevent should be dep. dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl - && !use_cobalt_customizations + && (!use_cobalt_customizations || sb_api_version >= 16) # Determines whether message_pump_libevent should be used. use_libevent = dep_libevent && !is_ios @@ -980,6 +980,26 @@ component("base") { "message_loop/message_pump_io_starboard.h", "message_loop/message_pump_ui_starboard.cc", "message_loop/message_pump_ui_starboard.h", + + # added for posix - by zhangmax + + + "synchronization/condition_variable_posix.cc", + "time/time_conversion_posix.cc", + + "files/file_posix.cc", + "files/file_util_posix.cc", + "files/file_descriptor_watcher_posix.cc", + "files/file_descriptor_watcher_posix.h", + "files/file_enumerator_posix.cc", + + "memory/page_size_posix.cc", + + "message_loop/watchable_io_message_pump_posix.cc", + "message_loop/watchable_io_message_pump_posix.h", + + # end of adding - zhangmax + "process/launch.cc", "process/launch.h", "process/launch_starboard.cc", @@ -2345,7 +2365,7 @@ component("base") { ] } - if (!use_cobalt_customizations && is_posix && !is_apple) { + if (use_libevent) { sources += [ "strings/sys_string_conversions_posix.cc", "synchronization/waitable_event_posix.cc", diff --git a/base/allocator/partition_allocator/partition_alloc_base/time/time.h b/base/allocator/partition_allocator/partition_alloc_base/time/time.h index 82a8d6b137f2..98f3f7389de5 100644 --- a/base/allocator/partition_allocator/partition_alloc_base/time/time.h +++ b/base/allocator/partition_allocator/partition_alloc_base/time/time.h @@ -93,7 +93,7 @@ #include #endif -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #include #endif @@ -126,14 +126,13 @@ class PlatformThreadHandle; class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta { public: constexpr TimeDelta() = default; - #if BUILDFLAG(IS_WIN) static TimeDelta FromQPCValue(LONGLONG qpc_value); // TODO(crbug.com/989694): Avoid base::TimeDelta factory functions // based on absolute time static TimeDelta FromFileTime(FILETIME ft); static TimeDelta FromWinrtDateTime(ABI::Windows::Foundation::DateTime dt); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 static TimeDelta FromTimeSpec(const timespec& ts); #endif #if BUILDFLAG(IS_FUCHSIA) @@ -198,7 +197,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta { constexpr bool is_min() const { return *this == Min(); } constexpr bool is_inf() const { return is_min() || is_max(); } -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 struct timespec ToTimeSpec() const; #endif #if BUILDFLAG(IS_FUCHSIA) @@ -586,7 +585,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time static Time FromDoubleT(double dt); double ToDoubleT() const; -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Converts the timespec structure to time. MacOS X 10.8.3 (and tentatively, // earlier versions) will have the |ts|'s tv_nsec component zeroed out, // having a 1 second resolution, which agrees with @@ -612,7 +611,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time static Time FromJavaTime(int64_t ms_since_epoch); int64_t ToJavaTime() const; -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 static Time FromTimeVal(struct timeval t); struct timeval ToTimeVal() const; #endif diff --git a/base/check.cc b/base/check.cc index 89e7894f88a0..51b43dc161d8 100644 --- a/base/check.cc +++ b/base/check.cc @@ -83,7 +83,7 @@ class DCheckLogMessage : public LogMessage { const base::Location location_; }; -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 class DCheckStarboardErrorLogMessage : public StarboardErrorLogMessage { public: DCheckStarboardErrorLogMessage(const base::Location& location, @@ -123,7 +123,7 @@ class DCheckWin32ErrorLogMessage : public Win32ErrorLogMessage { private: const base::Location location_; }; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 class DCheckErrnoLogMessage : public ErrnoLogMessage { public: DCheckErrnoLogMessage(const base::Location& location, @@ -166,13 +166,13 @@ CheckError CheckError::PCheck(const char* file, int line, const char* condition) { SystemErrorCode err_code = logging::GetLastSystemErrorCode(); -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 auto* const log_message = new StarboardErrorLogMessage(file, line, LOGGING_FATAL, err_code); #elif BUILDFLAG(IS_WIN) auto* const log_message = new Win32ErrorLogMessage(file, line, LOGGING_FATAL, err_code); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 auto* const log_message = new ErrnoLogMessage(file, line, LOGGING_FATAL, err_code); #endif @@ -187,13 +187,13 @@ CheckError CheckError::PCheck(const char* file, int line) { CheckError CheckError::DPCheck(const char* condition, const base::Location& location) { SystemErrorCode err_code = logging::GetLastSystemErrorCode(); -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 auto* const log_message = new DCheckStarboardErrorLogMessage(location, LOGGING_DCHECK, err_code); #elif BUILDFLAG(IS_WIN) auto* const log_message = new DCheckWin32ErrorLogMessage(location, LOGGING_DCHECK, err_code); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 auto* const log_message = new DCheckErrnoLogMessage(location, LOGGING_DCHECK, err_code); #endif diff --git a/base/files/file.h b/base/files/file.h index 855f763e8d9e..04bf0c26e73e 100644 --- a/base/files/file.h +++ b/base/files/file.h @@ -22,10 +22,13 @@ struct stat; namespace base { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 using stat_wrapper_t = struct ::stat; #else using stat_wrapper_t = struct stat; +#ifndef ftruncate64 +#define ftruncate64 ftruncate +#endif #endif // Thin wrapper around an OS-level file. @@ -357,11 +360,11 @@ class BASE_EXPORT File { bool DeleteOnClose(bool delete_on_close); #endif -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 static Error OSErrorToFileError(SbSystemError sb_system_error); #elif BUILDFLAG(IS_WIN) static Error OSErrorToFileError(DWORD last_error); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 static Error OSErrorToFileError(int saved_errno); #endif @@ -378,7 +381,7 @@ class BASE_EXPORT File { // Wrapper for stat() or stat64(). static int Stat(const char* path, stat_wrapper_t* sb); static int Fstat(int fd, stat_wrapper_t* sb); -# if !defined(STARBOARD) +# if !defined(STARBOARD) || (defined(STARBOARD) && SB_API_VERSION >= 16) // Starboard does not support lstat yet. static int Lstat(const char* path, stat_wrapper_t* sb); #endif diff --git a/base/files/file_descriptor_watcher_posix.cc b/base/files/file_descriptor_watcher_posix.cc index cb520db19a39..402870f9fb51 100644 --- a/base/files/file_descriptor_watcher_posix.cc +++ b/base/files/file_descriptor_watcher_posix.cc @@ -21,6 +21,8 @@ namespace base { +#if SB_API_VERSION >= 16 + namespace { // Per-thread FileDescriptorWatcher registration. @@ -272,4 +274,6 @@ void FileDescriptorWatcher::AssertAllowed() { } #endif +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/files/file_enumerator.h b/base/files/file_enumerator.h index b970055bc8aa..fc01d7fd356a 100644 --- a/base/files/file_enumerator.h +++ b/base/files/file_enumerator.h @@ -17,13 +17,13 @@ #include "base/time/time.h" #include "build/build_config.h" -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include #include #include "starboard/file.h" #elif BUILDFLAG(IS_WIN) #include "base/win/windows_types.h" -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #include #include @@ -96,8 +96,8 @@ class BASE_EXPORT FileEnumerator { // called. NAMES_ONLY = 1 << 3, -#if defined(STARBOARD) -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if defined(STARBOARD) && SB_API_VERSION <= 15 +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 SHOW_SYM_LINKS = 1 << 4, #endif }; @@ -193,7 +193,7 @@ class BASE_EXPORT FileEnumerator { bool IsPatternMatched(const FilePath& src) const; -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 std::vector ReadDirectory(const FilePath& source); // The files in the current directory @@ -210,7 +210,7 @@ class BASE_EXPORT FileEnumerator { bool has_find_data_ = false; CHROME_WIN32_FIND_DATA find_data_; HANDLE find_handle_ = INVALID_HANDLE_VALUE; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // The files in the current directory std::vector directory_entries_; diff --git a/base/files/file_enumerator_posix.cc b/base/files/file_enumerator_posix.cc index e329b88a0d94..327b7f7a617c 100644 --- a/base/files/file_enumerator_posix.cc +++ b/base/files/file_enumerator_posix.cc @@ -15,6 +15,9 @@ #include "build/build_config.h" namespace base { + +#if SB_API_VERSION >= 16 + namespace { void GetStat(const FilePath& path, bool show_links, stat_wrapper_t* st) { @@ -258,4 +261,6 @@ bool FileEnumerator::IsPatternMatched(const FilePath& path) const { !fnmatch(pattern_.c_str(), path.value().c_str(), FNM_NOESCAPE); } +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/files/file_enumerator_starboard.cc b/base/files/file_enumerator_starboard.cc index a4ebb01e4f9a..34ae8bbb3531 100644 --- a/base/files/file_enumerator_starboard.cc +++ b/base/files/file_enumerator_starboard.cc @@ -28,6 +28,8 @@ namespace base { +#if SB_API_VERSION <= 15 + // FileEnumerator::FileInfo ---------------------------------------------------- FileEnumerator::FileInfo::FileInfo() { @@ -225,4 +227,6 @@ FileEnumerator::FileInfo FileEnumerator::GetInfo() const { return directory_entries_[current_directory_entry_]; } +#endif // SB_API_VERSION <= 15 + } // namespace base diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc index 0808bb0e3ade..d45c84b0c910 100644 --- a/base/files/file_posix.cc +++ b/base/files/file_posix.cc @@ -33,6 +33,8 @@ static_assert(sizeof(base::stat_wrapper_t::st_size) >= 8); namespace base { +#if SB_API_VERSION >= 16 + // Make sure our Whence mappings match the system headers. static_assert(File::FROM_BEGIN == SEEK_SET && File::FROM_CURRENT == SEEK_CUR && File::FROM_END == SEEK_END, @@ -615,4 +617,6 @@ int File::Lstat(const char* path, stat_wrapper_t* sb) { return lstat(path, sb); } +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/files/file_starboard.cc b/base/files/file_starboard.cc index 17a4a4d308c1..9549be51d7f6 100644 --- a/base/files/file_starboard.cc +++ b/base/files/file_starboard.cc @@ -32,6 +32,8 @@ namespace base { +#if SB_API_VERSION <= 15 + namespace { SbFileError g_sb_file_error = kSbFileOk; } // namespace @@ -503,4 +505,6 @@ File File::Duplicate() const { return File(); } +#endif // SB_API_VERSION <= 15 + } // namespace base diff --git a/base/files/file_util.h b/base/files/file_util.h index c47f00265f41..033f64828be3 100644 --- a/base/files/file_util.h +++ b/base/files/file_util.h @@ -27,7 +27,7 @@ #if BUILDFLAG(IS_WIN) #include "base/win/windows_types.h" -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #include #include "base/posix/eintr_wrapper.h" @@ -50,7 +50,7 @@ class Time; // 3) it removes "." and ".." directory components. BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input); -#if BUILDFLAG(IS_POSIX) +#if BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 // Prepends the current working directory if `input` is not already absolute, // and removes "/./" and "/../" This is similar to MakeAbsoluteFilePath(), but // MakeAbsoluteFilePath() expands all symlinks in the path and this does not. @@ -252,7 +252,7 @@ BASE_EXPORT bool ReadFileToStringWithMaxSize(const FilePath& path, std::string* contents, size_t max_size); -#if !defined(STARBOARD) +#if !defined(STARBOARD) || SB_API_VERSION >= 16 // As ReadFileToString, but reading from an open stream after seeking to its // start (if supported by the stream). This can also be used to read the whole // file from a file descriptor by converting the file descriptor into a stream @@ -266,7 +266,7 @@ BASE_EXPORT bool ReadStreamToStringWithMaxSize(FILE* stream, std::string* contents); #endif -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result // in |buffer|. This function is protected against EINTR and partial reads. @@ -281,9 +281,9 @@ BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); BASE_EXPORT ScopedFD CreateAndOpenFdForTemporaryFileInDir(const FilePath& dir, FilePath* path); -#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 -#if BUILDFLAG(IS_POSIX) +#if BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 // ReadFileToStringNonBlocking is identical to ReadFileToString except it // guarantees that it will not block. This guarantee is provided on POSIX by @@ -354,7 +354,7 @@ BASE_EXPORT bool ExecutableExistsInPath(Environment* env, BASE_EXPORT bool IsPathExecutable(const FilePath& path); #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) -#endif // BUILDFLAG(IS_POSIX) +#endif // BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 // Returns true if the given directory is empty BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path); @@ -549,7 +549,7 @@ BASE_EXPORT bool WriteFile(const FilePath& filename, span data); // do manual conversions from a char span to a uint8_t span. BASE_EXPORT bool WriteFile(const FilePath& filename, StringPiece data); -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Appends |data| to |fd|. Does not close |fd| when done. Returns true iff all // of |data| were written to |fd|. BASE_EXPORT bool WriteFileDescriptor(int fd, span data); @@ -627,7 +627,7 @@ BASE_EXPORT bool PreReadFile( bool is_executable, int64_t max_bytes = std::numeric_limits::max()); -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Creates a pipe. Returns true on success, otherwise false. // On success, |read_fd| will be set to the fd of the read side, and @@ -648,7 +648,7 @@ BASE_EXPORT bool CreateLocalNonBlockingPipe(int fds[2]); // Returns true if it was able to set it in the close-on-exec mode, otherwise // false. BASE_EXPORT bool SetCloseOnExec(int fd); -#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #if BUILDFLAG(IS_MAC) // Test that |path| can only be changed by a given user and members of @@ -681,7 +681,7 @@ BASE_EXPORT bool VerifyPathControlledByAdmin(const base::FilePath& path); // the directory |path|, in the number of FilePath::CharType, or -1 on failure. BASE_EXPORT int GetMaximumPathComponentLength(const base::FilePath& path); -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Get a temporary directory for shared memory files. The directory may depend // on whether the destination is intended for executable files, which in turn // depends on how /dev/shmem was mounted. As a result, you must supply whether diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc index da04b251ce91..bbb27d860979 100644 --- a/base/files/file_util_posix.cc +++ b/base/files/file_util_posix.cc @@ -75,6 +75,8 @@ extern "C" char* mkdtemp(char* path); namespace base { +#if SB_API_VERSION >= 16 + namespace { #if BUILDFLAG(IS_MAC) @@ -1363,4 +1365,6 @@ BASE_EXPORT bool IsPathExecutable(const FilePath& path) { } #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/files/file_util_starboard.cc b/base/files/file_util_starboard.cc index bcec62a16edd..61318a5e0921 100644 --- a/base/files/file_util_starboard.cc +++ b/base/files/file_util_starboard.cc @@ -41,6 +41,8 @@ namespace base { +#if SB_API_VERSION <= 15 + namespace { // The list of portable filename characters as per POSIX. This should be the @@ -477,6 +479,17 @@ FilePath MakeAbsoluteFilePath(const FilePath& input) { return input; } +bool SetNonBlocking(int fd) { + const int flags = fcntl(fd, F_GETFL); + if (flags == -1) + return false; + if (flags & O_NONBLOCK) + return true; + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) + return false; + return true; +} + namespace internal { bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) { @@ -488,4 +501,6 @@ bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) { } // internal +#endif // SB_API_VERSION <= 15 + } // namespace base diff --git a/base/files/scoped_file.h b/base/files/scoped_file.h index f0a57f283a44..753af9d42482 100644 --- a/base/files/scoped_file.h +++ b/base/files/scoped_file.h @@ -24,7 +24,7 @@ namespace base { namespace internal { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 struct BASE_EXPORT ScopedFDCloseTraits { static int InvalidValue() { return -1; } static void Free(int file) { if (file >= 0) {close(file);} } @@ -37,7 +37,7 @@ struct BASE_EXPORT ScopedFDCloseTraits : public ScopedGenericOwnershipTracking { static void Acquire(const ScopedGeneric&, int); static void Release(const ScopedGeneric&, int); }; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX) // On ChromeOS and Linux we guard FD lifetime with a global table and hook into // libc close() to perform checks. @@ -56,7 +56,7 @@ struct BASE_EXPORT ScopedFDCloseTraits { }; #endif -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 // Functor for |ScopedFILE| (below). struct ScopedFILECloser { inline void operator()(int* x) const { @@ -127,7 +127,7 @@ typedef ScopedGeneric ScopedFD; #endif // Automatically closes |FILE*|s. -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 typedef std::unique_ptr ScopedFILE; #else typedef std::unique_ptr ScopedFILE; diff --git a/base/logging.cc b/base/logging.cc index 5900a58e9e7f..318739f31762 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -38,7 +38,7 @@ #include "base/debug/leak_annotations.h" #endif // defined(LEAK_SANITIZER) && !BUILDFLAG(IS_NACL) -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include #include "base/files/file_starboard.h" @@ -69,8 +69,8 @@ typedef HANDLE FileHandle; #include #include -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) -#if BUILDFLAG(IS_NACL) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 +#if BUILDFLAG(IS_NACL) || SB_API_VERSION >= 16 #include // timespec doesn't seem to be in #endif #include @@ -84,7 +84,7 @@ typedef HANDLE FileHandle; #include #endif -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #include #include @@ -130,7 +130,7 @@ typedef FILE* FileHandle; #include "base/win/win_util.h" #endif -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include "base/posix/safe_strerror.h" #endif @@ -293,7 +293,7 @@ base::stack& GetLogAssertHandlerStack() { LogMessageHandlerFunction g_log_message_handler = nullptr; uint64_t TickCount() { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 return starboard::CurrentMonotonicTime(); #elif BUILDFLAG(IS_WIN) return GetTickCount(); @@ -307,7 +307,7 @@ uint64_t TickCount() { // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h // So we have to use clock() for now. return clock(); -#elif BUILDFLAG(IS_POSIX) +#elif BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); @@ -319,13 +319,13 @@ uint64_t TickCount() { } void DeleteFilePath(const PathString& log_name) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 unlink(log_name.c_str()); #elif BUILDFLAG(IS_WIN) DeleteFile(log_name.c_str()); #elif BUILDFLAG(IS_NACL) // Do nothing; unlink() isn't supported on NaCl. -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 unlink(log_name.c_str()); #else #error Unsupported platform @@ -333,7 +333,7 @@ void DeleteFilePath(const PathString& log_name) { } PathString GetDefaultLogFile() { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 // On Starboard, we politely ask for the log directory, like a civilized // platform. std::vector path(kSbFileMaxPath + 1); @@ -352,7 +352,7 @@ PathString GetDefaultLogFile() { log_name.erase(last_backslash + 1); log_name += FILE_PATH_LITERAL("debug.log"); return log_name; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // On other platforms we just use the current directory. return PathString("debug.log"); #endif @@ -360,7 +360,7 @@ PathString GetDefaultLogFile() { // We don't need locks on Windows for atomically appending to files. The OS // provides this functionality. -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Provides a lock to synchronize appending to the log file across // threads. This can be required to support NFS file systems even on OSes that @@ -378,7 +378,7 @@ base::Lock& GetLoggingLock() { return *lock; } -#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Called by logging functions to ensure that |g_log_file| is initialized // and can be used for writing. Returns false if the file could not be @@ -393,7 +393,7 @@ bool InitializeLogFileHandle() { g_log_file_name = new PathString(GetDefaultLogFile()); } -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 // This seems to get called a lot with an empty filename, at least in // base_unittests. if (g_log_file_name->empty()) { @@ -404,7 +404,7 @@ bool InitializeLogFileHandle() { if ((g_logging_destination & LOG_TO_FILE) == 0) return true; -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 int g_log_file_descriptor = open(g_log_file_name->c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); g_log_file = &g_log_file_descriptor; @@ -447,7 +447,7 @@ bool InitializeLogFileHandle() { return false; } } -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 g_log_file = fopen(g_log_file_name->c_str(), "a"); if (g_log_file == nullptr) return false; @@ -459,13 +459,13 @@ bool InitializeLogFileHandle() { } void CloseFile(FileHandle log) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 if (*log >= 0) { close(*log); } #elif BUILDFLAG(IS_WIN) CloseHandle(log); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 fclose(log); #else #error Unsupported platform @@ -485,7 +485,7 @@ void CloseLogFileUnlocked() { g_logging_destination &= ~LOG_TO_FILE; } -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 SbLogPriority LogLevelToStarboardLogPriority(int level) { switch (level) { case LOG_INFO: @@ -508,7 +508,7 @@ SbLogPriority LogLevelToStarboardLogPriority(int level) { return kSbLogPriorityInfo; } } -#endif // defined(STARBOARD) +#endif // defined(STARBOARD) && SB_API_VERSION <= 15 #if BUILDFLAG(IS_FUCHSIA) inline FuchsiaLogSeverity LogSeverityToFuchsiaLogSeverity( @@ -534,7 +534,7 @@ inline FuchsiaLogSeverity LogSeverityToFuchsiaLogSeverity( #endif // BUILDFLAG(IS_FUCHSIA) void WriteToFd(int fd, const char* data, size_t length) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 if (length > 0) { SbLogRaw(data); if (data[length - 1] != '\n') { @@ -552,7 +552,7 @@ void WriteToFd(int fd, const char* data, size_t length) { } bytes_written += static_cast(rv); } -#endif // defined(STARBOARD) +#endif // defined(STARBOARD) && SB_API_VERSION <= 15 } void SetLogFatalCrashKey(LogMessage* log_message) { @@ -651,7 +651,7 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) { if ((g_logging_destination & LOG_TO_FILE) == 0) return true; -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 base::AutoLock guard(GetLoggingLock()); #endif @@ -700,7 +700,7 @@ bool ShouldCreateLogMessage(int severity) { // set, or only LOG_TO_FILE is set, since that is useful for local development // and debugging. bool ShouldLogToStderr(int severity) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) { // Don't SbLog to stderr if already logging to system debug log. return false; @@ -854,7 +854,7 @@ LogMessage::~LogMessage() { } if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 SbLog(LogLevelToStarboardLogPriority(severity_), str_newline.c_str()); #elif BUILDFLAG(IS_WIN) OutputDebugStringA(str_newline.c_str()); @@ -994,7 +994,7 @@ LogMessage::~LogMessage() { // LOG(ERROR) << "Something went wrong"; // free_something(); // } -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 SbLog(LogLevelToStarboardLogPriority(severity_), str_newline.c_str()); #else WriteToFd(STDERR_FILENO, str_newline.data(), str_newline.size()); @@ -1002,7 +1002,7 @@ LogMessage::~LogMessage() { } if ((g_logging_destination & LOG_TO_FILE) != 0) { -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // If the client app did not call InitLogging() and the lock has not // been created it will be done now on calling GetLoggingLock(). We do this // on demand, but if two threads try to do this at the same time, there will @@ -1011,7 +1011,7 @@ LogMessage::~LogMessage() { base::AutoLock guard(GetLoggingLock()); #endif if (InitializeLogFileHandle()) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 lseek(*g_log_file, 0, SEEK_END); int written = 0; while (written < str_newline.length()) { @@ -1031,7 +1031,7 @@ LogMessage::~LogMessage() { static_cast(str_newline.length()), &num_written, nullptr); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 std::ignore = fwrite(str_newline.data(), str_newline.size(), 1, g_log_file); fflush(g_log_file); @@ -1104,7 +1104,7 @@ void LogMessage::Init(const char* file, int line) { if (g_log_process_id) stream_ << base::GetUniqueIdForProcess() << ':'; if (g_log_thread_id) -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 // Logging the thread name is added for Starboard logs. stream_ << base::PlatformThread::GetName() << '/' << base::PlatformThread::CurrentId() << ":"; @@ -1112,7 +1112,7 @@ void LogMessage::Init(const char* file, int line) { stream_ << base::PlatformThread::CurrentId() << ':'; #endif if (g_log_timestamp) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 EzTimeValue time_value; EzTimeValueGetNow(&time_value, NULL); struct EzTimeExploded local_time = {0}; @@ -1140,7 +1140,7 @@ void LogMessage::Init(const char* file, int line) { << '.' << std::setw(3) << local_time.wMilliseconds << ':'; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 timeval tv; gettimeofday(&tv, nullptr); time_t t = tv.tv_sec; @@ -1181,17 +1181,17 @@ typedef DWORD SystemErrorCode; #endif SystemErrorCode GetLastSystemErrorCode() { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 return SbSystemGetLastError(); #elif BUILDFLAG(IS_WIN) return ::GetLastError(); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 return errno; #endif } BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 const int kErrorMessageBufferSize = 256; char msgbuf[kErrorMessageBufferSize]; @@ -1216,13 +1216,13 @@ BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { } return base::StringPrintf("Error (0x%lX) while retrieving error. (0x%lX)", GetLastError(), error_code); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 return base::safe_strerror(error_code) + base::StringPrintf(" (%d)", error_code); #endif // BUILDFLAG(IS_WIN) } -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 StarboardErrorLogMessage::StarboardErrorLogMessage(const char* file, int line, LogSeverity severity, @@ -1250,7 +1250,7 @@ Win32ErrorLogMessage::~Win32ErrorLogMessage() { DWORD last_error = err_; base::debug::Alias(&last_error); } -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 ErrnoLogMessage::ErrnoLogMessage(const char* file, int line, LogSeverity severity, @@ -1267,7 +1267,7 @@ ErrnoLogMessage::~ErrnoLogMessage() { #endif // BUILDFLAG(IS_WIN) void CloseLogFile() { -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 base::AutoLock guard(GetLoggingLock()); #endif CloseLogFileUnlocked(); @@ -1319,7 +1319,7 @@ ScopedLoggingSettings::ScopedLoggingSettings() ScopedLoggingSettings::~ScopedLoggingSettings() { // Re-initialize logging via the normal path. This will clean up old file // name and handle state, including re-initializing the VLOG internal state. -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 CHECK(InitLogging({ logging_destination_, log_file_name_ ? log_file_name_->data() : nullptr, @@ -1350,7 +1350,7 @@ void ScopedLoggingSettings::SetLogFormat(LogFormat log_format) const { void RawLog(int level, const char* message) { if (level >= g_min_log_level && message) { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 SbLogRaw(message); const size_t message_len = strlen(message); if (message_len > 0 && message[message_len - 1] != '\n') { diff --git a/base/logging.h b/base/logging.h index aeddb4c1de24..8d5668d16b49 100644 --- a/base/logging.h +++ b/base/logging.h @@ -217,11 +217,12 @@ enum : uint32_t { // On POSIX platforms, where it may not even be possible to locate the // executable on disk, use stderr. // On Fuchsia, use the Fuchsia logging service. -#if BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_NACL) || defined(STARBOARD) +#if BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_NACL) || \ + (defined(STARBOARD) && SB_API_VERSION <= 15) LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG, #elif BUILDFLAG(IS_WIN) LOG_DEFAULT = LOG_TO_FILE, -#elif BUILDFLAG(IS_POSIX) +#elif BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG | LOG_TO_STDERR, #endif }; @@ -530,7 +531,7 @@ BASE_EXPORT int GetDisableAllVLogLevel(); LAZY_STREAM(VLOG_STREAM(verbose_level), \ VLOG_IS_ON(verbose_level) && (condition)) -#if defined (STARBOARD) +#if defined (STARBOARD) && SB_API_VERSION <= 15 #define VPLOG_STREAM(verbose_level) \ ::logging::StarboardErrorLogMessage(__FILE__, __LINE__, -verbose_level, \ ::logging::GetLastSystemErrorCode()).stream() @@ -538,7 +539,7 @@ BASE_EXPORT int GetDisableAllVLogLevel(); #define VPLOG_STREAM(verbose_level) \ ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -(verbose_level), \ ::logging::GetLastSystemErrorCode()).stream() -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #define VPLOG_STREAM(verbose_level) \ ::logging::ErrnoLogMessage(__FILE__, __LINE__, -(verbose_level), \ ::logging::GetLastSystemErrorCode()).stream() @@ -557,7 +558,7 @@ BASE_EXPORT int GetDisableAllVLogLevel(); LOG_IF(FATAL, !(ANALYZER_ASSUME_TRUE(condition))) \ << "Assert failed: " #condition ". " -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #define PLOG_STREAM(severity) \ COMPACT_GOOGLE_LOG_EX_ ## severity(StarboardErrorLogMessage, \ ::logging::GetLastSystemErrorCode()).stream() @@ -565,7 +566,7 @@ BASE_EXPORT int GetDisableAllVLogLevel(); #define PLOG_STREAM(severity) \ COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \ ::logging::GetLastSystemErrorCode()).stream() -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #define PLOG_STREAM(severity) \ COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \ ::logging::GetLastSystemErrorCode()).stream() @@ -658,6 +659,7 @@ class BASE_EXPORT LogMessage { // Used for CHECK(). Implied severity = LOGGING_FATAL. LogMessage(const char* file, int line, const char* condition); + LogMessage(const LogMessage&) = delete; LogMessage& operator=(const LogMessage&) = delete; virtual ~LogMessage(); @@ -712,11 +714,11 @@ class LogMessageVoidify { void operator&(std::ostream&) { } }; -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 typedef SbSystemError SystemErrorCode; #elif BUILDFLAG(IS_WIN) typedef unsigned long SystemErrorCode; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 typedef int SystemErrorCode; #endif @@ -725,7 +727,7 @@ typedef int SystemErrorCode; BASE_EXPORT SystemErrorCode GetLastSystemErrorCode(); BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code); -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 // Appends a formatted system message of the GetLastError() type. class BASE_EXPORT StarboardErrorLogMessage : public LogMessage { public: @@ -763,7 +765,7 @@ class BASE_EXPORT Win32ErrorLogMessage : public LogMessage { private: SystemErrorCode err_; }; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Appends a formatted system message of the errno type class BASE_EXPORT ErrnoLogMessage : public LogMessage { public: @@ -771,6 +773,11 @@ class BASE_EXPORT ErrnoLogMessage : public LogMessage { int line, LogSeverity severity, SystemErrorCode err); + ErrnoLogMessage(const char* function, + const char* file, + int line, + LogSeverity severity, + int err); ErrnoLogMessage(const ErrnoLogMessage&) = delete; ErrnoLogMessage& operator=(const ErrnoLogMessage&) = delete; // Appends the error message before destructing the encapsulated class. diff --git a/base/memory/page_size_posix.cc b/base/memory/page_size_posix.cc index 61189677efa1..612ce379a95c 100644 --- a/base/memory/page_size_posix.cc +++ b/base/memory/page_size_posix.cc @@ -8,6 +8,8 @@ namespace base { +#if SB_API_VERSION >= 16 + size_t GetPageSize() { static const size_t pagesize = []() -> size_t { // For more information see getpagesize(2). Portable applications should use @@ -21,4 +23,6 @@ size_t GetPageSize() { return pagesize; } +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/memory/page_size_starboard.cc b/base/memory/page_size_starboard.cc index 65d6ed8dd57f..bc82df70b2bf 100644 --- a/base/memory/page_size_starboard.cc +++ b/base/memory/page_size_starboard.cc @@ -18,9 +18,13 @@ namespace base { +#if SB_API_VERSION <= 15 + size_t GetPageSize() { NOTREACHED(); return 0; } +#endif // SB_API_VERSIO <= 15 + } \ No newline at end of file diff --git a/base/message_loop/fd_watch_controller_posix_unittest.cc b/base/message_loop/fd_watch_controller_posix_unittest.cc index 87fdb1652d2a..3a33742d1ef8 100644 --- a/base/message_loop/fd_watch_controller_posix_unittest.cc +++ b/base/message_loop/fd_watch_controller_posix_unittest.cc @@ -209,7 +209,7 @@ class ReaderWriterHandler : public MessagePumpForIO::FdWatcher { ReaderWriterHandler& operator=(const ReaderWriterHandler&) = delete; // base::WatchableIOMessagePumpPosix::FdWatcher: - void OnFileCanReadWithoutBlocking(int fd) override { + void OnSocketReadyToRead(int fd) override { if (when_ == kOnReadEvent) { DoAction(); } else { diff --git a/base/message_loop/message_pump_for_io.h b/base/message_loop/message_pump_for_io.h index 08bf51a39ec3..d09face7a1de 100644 --- a/base/message_loop/message_pump_for_io.h +++ b/base/message_loop/message_pump_for_io.h @@ -11,7 +11,7 @@ #include "base/message_loop/ios_cronet_buildflags.h" #include "build/build_config.h" -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include "base/message_loop/message_pump_io_starboard.h" #elif BUILDFLAG(IS_WIN) #include "base/message_loop/message_pump_win.h" @@ -23,13 +23,13 @@ #include "base/message_loop/message_pump_default.h" #elif BUILDFLAG(IS_FUCHSIA) #include "base/message_loop/message_pump_fuchsia.h" -#elif BUILDFLAG(IS_POSIX) +#elif BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 #include "base/message_loop/message_pump_libevent.h" #endif namespace base { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 using MessagePumpForIO = MessagePumpIOStarboard; #elif BUILDFLAG(IS_WIN) // Windows defines it as-is. @@ -42,7 +42,7 @@ using MessagePumpForIO = MessagePumpKqueue; using MessagePumpForIO = MessagePumpDefault; #elif BUILDFLAG(IS_FUCHSIA) using MessagePumpForIO = MessagePumpFuchsia; -#elif BUILDFLAG(IS_POSIX) +#elif BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16 using MessagePumpForIO = MessagePumpLibevent; #else #error Platform does not define MessagePumpForIO diff --git a/base/message_loop/message_pump_for_ui.h b/base/message_loop/message_pump_for_ui.h index 639a462946a9..0da9c874a766 100644 --- a/base/message_loop/message_pump_for_ui.h +++ b/base/message_loop/message_pump_for_ui.h @@ -10,7 +10,7 @@ #include "build/build_config.h" -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include "base/message_loop/message_pump_ui_starboard.h" #elif BUILDFLAG(IS_WIN) #include "base/message_loop/message_pump_win.h" @@ -22,7 +22,7 @@ // No MessagePumpForUI, see below. #elif defined(USE_GLIB) #include "base/message_loop/message_pump_glib.h" -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD) || SB_API_VERSION >= 16 #include "base/message_loop/message_pump_libevent.h" #elif BUILDFLAG(IS_FUCHSIA) #include "base/message_loop/message_pump_fuchsia.h" @@ -30,7 +30,7 @@ namespace base { -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 using MessagePumpForUI = MessagePumpUIStarboard; #elif BUILDFLAG(IS_WIN) // Windows defines it as-is. @@ -48,7 +48,7 @@ using MessagePumpForUI = MessagePump; // TODO(abarth): Figure out if we need this. #elif defined(USE_GLIB) using MessagePumpForUI = MessagePumpGlib; -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD) || SB_API_VERSION >= 16 using MessagePumpForUI = MessagePumpLibevent; #elif BUILDFLAG(IS_FUCHSIA) using MessagePumpForUI = MessagePumpFuchsia; diff --git a/base/message_loop/message_pump_glib_unittest.cc b/base/message_loop/message_pump_glib_unittest.cc index 77b5ca425024..a47f8dc9c3e2 100644 --- a/base/message_loop/message_pump_glib_unittest.cc +++ b/base/message_loop/message_pump_glib_unittest.cc @@ -717,14 +717,14 @@ class NestedPumpWatcher : public MessagePumpGlib::FdWatcher { NestedPumpWatcher() = default; ~NestedPumpWatcher() override = default; - void OnFileCanReadWithoutBlocking(int /* fd */) override { + void OnFileCanWriteWithoutBlocking(int /* fd */) override { RunLoop runloop; SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, BindOnce(&QuitMessageLoopAndStart, runloop.QuitClosure())); runloop.Run(); } - void OnFileCanWriteWithoutBlocking(int /* fd */) override {} + void OnSocketReadyToWrite(int /* fd */) override {} }; class QuitWatcher : public DeleteWatcher { diff --git a/base/message_loop/message_pump_libevent.cc b/base/message_loop/message_pump_libevent.cc index 72f67b836c6f..be507b9dcd92 100644 --- a/base/message_loop/message_pump_libevent.cc +++ b/base/message_loop/message_pump_libevent.cc @@ -39,6 +39,8 @@ namespace base { +#if SB_API_VERSION >= 16 + namespace { #if BUILDFLAG(ENABLE_MESSAGE_PUMP_EPOLL) @@ -485,4 +487,6 @@ MessagePumpLibevent::EpollInterest::EpollInterest( MessagePumpLibevent::EpollInterest::~EpollInterest() = default; +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/message_loop/message_pump_libevent.h b/base/message_loop/message_pump_libevent.h index 0389de964599..f6644747d069 100644 --- a/base/message_loop/message_pump_libevent.h +++ b/base/message_loop/message_pump_libevent.h @@ -263,6 +263,8 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump, ThreadChecker watch_file_descriptor_caller_checker_; }; +using MessagePumpForUI = MessagePumpLibevent; + } // namespace base #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ diff --git a/base/strings/sys_string_conversions_starboard.cc b/base/strings/sys_string_conversions_starboard.cc index 3e7cfda9eecc..d98a1df56482 100644 --- a/base/strings/sys_string_conversions_starboard.cc +++ b/base/strings/sys_string_conversions_starboard.cc @@ -13,4 +13,6 @@ // limitations under the License. // We use the same code as the POSIX version. +#if SB_API_VERSION <= 15 #include "sys_string_conversions_posix.cc" +#endif // SB_API_VERSIO <= 15 diff --git a/base/synchronization/condition_variable.h b/base/synchronization/condition_variable.h index 4c84bc200b25..c6598bb549e5 100644 --- a/base/synchronization/condition_variable.h +++ b/base/synchronization/condition_variable.h @@ -69,14 +69,10 @@ #include "base/base_export.h" #include "base/synchronization/lock.h" -#if defined(STARBOARD) -#if SB_API_VERSION < 16 +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include "starboard/condition_variable.h" #else -#include -#endif // SB_API_VERSION < 16 -#else -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #endif @@ -121,18 +117,13 @@ class BASE_EXPORT ConditionVariable { void declare_only_used_while_idle() { waiting_is_blocking_ = false; } private: -#if defined(STARBOARD) -#if SB_API_VERSION < 16 +#if defined(STARBOARD) && SB_API_VERSION <= 15 SbConditionVariable condition_; SbMutex* user_mutex_; -#else - pthread_cond_t condition_; - pthread_mutex_t* user_mutex_; -#endif // SB_API_VERSION < 16 #elif BUILDFLAG(IS_WIN) CHROME_CONDITION_VARIABLE cv_; const raw_ptr srwlock_; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 pthread_cond_t condition_; raw_ptr user_mutex_; #endif diff --git a/base/synchronization/condition_variable_posix.cc b/base/synchronization/condition_variable_posix.cc index 0b7ccc9bdba7..dde24d122d35 100644 --- a/base/synchronization/condition_variable_posix.cc +++ b/base/synchronization/condition_variable_posix.cc @@ -21,6 +21,8 @@ namespace base { +#if SB_API_VERSION >= 16 + ConditionVariable::ConditionVariable(Lock* user_lock) : user_mutex_(user_lock->lock_.native_handle()) #if DCHECK_IS_ON() @@ -151,4 +153,6 @@ void ConditionVariable::Signal() { DCHECK_EQ(0, rv); } +#endif // SB_API_VERSION >= 16 + } // namespace base diff --git a/base/synchronization/condition_variable_starboard.cc b/base/synchronization/condition_variable_starboard.cc index c46217e0490d..f29716c0b124 100644 --- a/base/synchronization/condition_variable_starboard.cc +++ b/base/synchronization/condition_variable_starboard.cc @@ -23,6 +23,8 @@ namespace base { +#if SB_API_VERSION <= 15 + ConditionVariable::ConditionVariable(Lock* user_lock) : user_mutex_(user_lock->lock_.native_handle()) #if DCHECK_IS_ON() @@ -136,4 +138,6 @@ void ConditionVariable::Signal() { #endif // SB_API_VERSION < 16 } +#endif // SB_API_VERSION <= 15 + } // namespace base diff --git a/base/synchronization/waitable_event_starboard.cc b/base/synchronization/waitable_event_starboard.cc index 43010d671fc6..1cb65a4ac437 100644 --- a/base/synchronization/waitable_event_starboard.cc +++ b/base/synchronization/waitable_event_starboard.cc @@ -13,4 +13,6 @@ // limitations under the License. // We use the same code as the POSIX version. +#if SB_API_VERSION <= 15 #include "base/synchronization/waitable_event_posix.cc" +#endif // SB_API_VERSIO <= 15 \ No newline at end of file diff --git a/base/synchronization/waitable_event_watcher_starboard.cc b/base/synchronization/waitable_event_watcher_starboard.cc index 518f92966332..8b3339487c49 100644 --- a/base/synchronization/waitable_event_watcher_starboard.cc +++ b/base/synchronization/waitable_event_watcher_starboard.cc @@ -13,4 +13,6 @@ // limitations under the License. // We use the same code as the POSIX version. +#if SB_API_VERSION <= 15 #include "base/synchronization/waitable_event_watcher_posix.cc" +#endif // SB_API_VERSIO <= 15 \ No newline at end of file diff --git a/base/task/current_thread.cc b/base/task/current_thread.cc index 673e2028d4a2..fbb1fae1c6bf 100644 --- a/base/task/current_thread.cc +++ b/base/task/current_thread.cc @@ -211,12 +211,13 @@ MessagePumpForIO* CurrentIOThread::GetMessagePumpForIO() const { #if !BUILDFLAG(IS_NACL) -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 bool CurrentIOThread::Watch(SbSocket socket, bool persistent, int mode, SocketWatcher* controller, Watcher* delegate) { + return static_cast(GetMessagePumpForIO()) ->Watch(socket, persistent, mode, controller, delegate); } @@ -234,7 +235,7 @@ bool CurrentIOThread::RegisterJobObject(HANDLE job, return GetMessagePumpForIO()->RegisterJobObject(job, handler); } -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 bool CurrentIOThread::WatchFileDescriptor( int fd, bool persistent, diff --git a/base/task/current_thread.h b/base/task/current_thread.h index 5106c5e9fd71..822ea0fab11f 100644 --- a/base/task/current_thread.h +++ b/base/task/current_thread.h @@ -270,7 +270,7 @@ class BASE_EXPORT CurrentIOThread : public CurrentThread { #if !BUILDFLAG(IS_NACL) -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 typedef base::MessagePumpIOStarboard::Watcher Watcher; typedef base::MessagePumpIOStarboard::SocketWatcher SocketWatcher; typedef base::MessagePumpIOStarboard::IOObserver IOObserver; @@ -284,11 +284,12 @@ class BASE_EXPORT CurrentIOThread : public CurrentThread { int mode, SocketWatcher* controller, Watcher* delegate); + #elif BUILDFLAG(IS_WIN) // Please see MessagePumpWin for definitions of these methods. HRESULT RegisterIOHandler(HANDLE file, MessagePumpForIO::IOHandler* handler); bool RegisterJobObject(HANDLE job, MessagePumpForIO::IOHandler* handler); -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 // Please see WatchableIOMessagePumpPosix for definition. // Prefer base::FileDescriptorWatcher for non-critical IO. bool WatchFileDescriptor(int fd, diff --git a/base/task/sequence_manager/sequence_manager_impl.cc b/base/task/sequence_manager/sequence_manager_impl.cc index 15b96bde3bcc..e61d4f7e7bad 100644 --- a/base/task/sequence_manager/sequence_manager_impl.cc +++ b/base/task/sequence_manager/sequence_manager_impl.cc @@ -368,7 +368,7 @@ void SequenceManagerImpl::BindToMessagePump(std::unique_ptr pump) { #endif // On iOS attach to the native loop when there is one. -#if BUILDFLAG(IS_IOS) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || (defined(STARBOARD) && SB_API_VERSION <= 15) if (settings_.message_loop_type == MessagePumpType::UI) { controller_->AttachToMessagePump(); } @@ -1159,7 +1159,7 @@ bool SequenceManagerImpl::IsTaskExecutionAllowed() const { return controller_->IsTaskExecutionAllowed(); } -#if BUILDFLAG(IS_IOS) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || (defined(STARBOARD) && SB_API_VERSION <= 15) void SequenceManagerImpl::AttachToMessagePump() { return controller_->AttachToMessagePump(); } diff --git a/base/task/sequence_manager/sequence_manager_impl.h b/base/task/sequence_manager/sequence_manager_impl.h index a0a0c169dd9f..5d9c9775fc1f 100644 --- a/base/task/sequence_manager/sequence_manager_impl.h +++ b/base/task/sequence_manager/sequence_manager_impl.h @@ -172,7 +172,7 @@ class BASE_EXPORT SequenceManagerImpl void SetAddQueueTimeToTasks(bool enable); void SetTaskExecutionAllowed(bool allowed); bool IsTaskExecutionAllowed() const; -#if BUILDFLAG(IS_IOS) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || (defined(STARBOARD) && SB_API_VERSION <= 15) void AttachToMessagePump(); #endif bool IsIdleForTesting() override; diff --git a/base/task/sequence_manager/thread_controller.h b/base/task/sequence_manager/thread_controller.h index 2db10ba82ea8..446d4dee3747 100644 --- a/base/task/sequence_manager/thread_controller.h +++ b/base/task/sequence_manager/thread_controller.h @@ -132,7 +132,7 @@ class BASE_EXPORT ThreadController { // Returns true if the current run loop should quit when idle. virtual bool ShouldQuitRunLoopWhenIdle() = 0; -#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || (defined(STARBOARD) && SB_API_VERSION <= 15) // On iOS, the main message loop cannot be Run(). Instead call // AttachToMessagePump(), which connects this ThreadController to the // UI thread's CFRunLoop and allows PostTask() to work. diff --git a/base/task/sequence_manager/thread_controller_impl.cc b/base/task/sequence_manager/thread_controller_impl.cc index ce77f88be9d4..446a56f0b6fd 100644 --- a/base/task/sequence_manager/thread_controller_impl.cc +++ b/base/task/sequence_manager/thread_controller_impl.cc @@ -363,7 +363,7 @@ MessagePump* ThreadControllerImpl::GetBoundMessagePump() const { return nullptr; } -#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || (defined(STARBOARD) && SB_API_VERSION <= 15) void ThreadControllerImpl::AttachToMessagePump() { NOTREACHED(); } diff --git a/base/task/sequence_manager/thread_controller_impl.h b/base/task/sequence_manager/thread_controller_impl.h index 262a4bdd6c57..f21287a6a9c4 100644 --- a/base/task/sequence_manager/thread_controller_impl.h +++ b/base/task/sequence_manager/thread_controller_impl.h @@ -61,7 +61,7 @@ class BASE_EXPORT ThreadControllerImpl : public ThreadController, void SetTaskExecutionAllowed(bool allowed) override; bool IsTaskExecutionAllowed() const override; MessagePump* GetBoundMessagePump() const override; -#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || (defined(STARBOARD) && SB_API_VERSION <= 15) void AttachToMessagePump() override; #endif #if BUILDFLAG(IS_IOS) diff --git a/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc b/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc index e2eb0fd38864..8d4ffe0a38c7 100644 --- a/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc +++ b/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc @@ -731,7 +731,7 @@ void ThreadControllerWithMessagePumpImpl::AttachToMessagePump() { void ThreadControllerWithMessagePumpImpl::DetachFromMessagePump() { static_cast(pump_.get())->Detach(); } -#elif BUILDFLAG(IS_ANDROID) || defined(STARBOARD) +#elif BUILDFLAG(IS_ANDROID) || (defined(STARBOARD) && SB_API_VERSION <= 15) void ThreadControllerWithMessagePumpImpl::AttachToMessagePump() { CHECK(main_thread_only().work_batch_size == 1); // Aborting the message pump currently relies on the batch size being 1. diff --git a/base/task/sequence_manager/thread_controller_with_message_pump_impl.h b/base/task/sequence_manager/thread_controller_with_message_pump_impl.h index e3c6c97863c3..1f9c7b4eeaeb 100644 --- a/base/task/sequence_manager/thread_controller_with_message_pump_impl.h +++ b/base/task/sequence_manager/thread_controller_with_message_pump_impl.h @@ -74,7 +74,7 @@ class BASE_EXPORT ThreadControllerWithMessagePumpImpl bool IsTaskExecutionAllowed() const override; MessagePump* GetBoundMessagePump() const override; void PrioritizeYieldingToNative(base::TimeTicks prioritize_until) override; -#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || defined(STARBOARD) +#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) || (defined(STARBOARD) && SB_API_VERSION <= 15) void AttachToMessagePump() override; #endif #if BUILDFLAG(IS_IOS) diff --git a/base/time/time.h b/base/time/time.h index d84b2f69d01a..676683874e10 100644 --- a/base/time/time.h +++ b/base/time/time.h @@ -77,7 +77,7 @@ #include "build/build_config.h" #include "build/chromeos_buildflags.h" -#if defined(STARBOARD) +#if defined(STARBOARD) && SB_API_VERSION <= 15 #include "starboard/common/time.h" #else #if BUILDFLAG(IS_APPLE) @@ -99,7 +99,7 @@ #include #endif -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 #include #include #endif @@ -206,6 +206,11 @@ class BASE_EXPORT TimeDelta { MakeClampedNum(n)) : TimeDelta::Max(); } + +#if SB_API_VERSION >= 16 + static TimeDelta FromTimeSpec(const timespec& ts); +#endif + #elif BUILDFLAG(IS_WIN) static TimeDelta FromQPCValue(LONGLONG qpc_value); // TODO(crbug.com/989694): Avoid base::TimeDelta factory functions @@ -278,7 +283,7 @@ class BASE_EXPORT TimeDelta { constexpr bool is_min() const { return *this == Min(); } constexpr bool is_inf() const { return is_min() || is_max(); } -#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16 struct timespec ToTimeSpec() const; #endif #if BUILDFLAG(IS_FUCHSIA) @@ -740,6 +745,9 @@ class BASE_EXPORT Time : public time_internal::TimeBase