Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back necessary c25 base changes #4752

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/base_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "build/build_config.h"

#if defined(STARBOARD)
#include "base/base_paths_starboard.h"
#else
#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#elif BUILDFLAG(IS_APPLE)
Expand All @@ -21,6 +24,7 @@
#if BUILDFLAG(IS_POSIX)
#include "base/base_paths_posix.h"
#endif
#endif

namespace base {

Expand Down
119 changes: 119 additions & 0 deletions base/base_paths_starboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "starboard/configuration_constants.h"
#include "starboard/system.h"

namespace base {

// This is where we can control the path for placement of a lot of file
// resources for cobalt.
bool PathProviderStarboard(int key, FilePath *result) {
std::vector<char> path(kSbFileMaxPath, 0);
switch (key) {
case base::FILE_EXE:
case base::FILE_MODULE: {
bool success = SbSystemGetPath(kSbSystemPathExecutableFile, path.data(),
path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "FILE_EXE not defined.";
return false;
}

case base::DIR_EXE:
case base::DIR_MODULE:
case base::DIR_ASSETS: {
bool success = SbSystemGetPath(kSbSystemPathContentDirectory, path.data(),
path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "DIR_EXE/DIR_MODULE not defined.";
return false;
}

#if defined(ENABLE_TEST_DATA)
case base::DIR_TEST_DATA: {
bool success = SbSystemGetPath(kSbSystemPathContentDirectory, path.data(),
path.size());
DCHECK(success);
if (success) {
// Append "test" to match the output of the files copied during builds.
*result = FilePath(path.data()).Append(FILE_PATH_LITERAL("test"));
return true;
}
DLOG(ERROR) << "DIR_TEST_DATA not defined.";
return false;
}
#endif // ENABLE_TEST_DATA

case base::DIR_CACHE: {
bool success = SbSystemGetPath(kSbSystemPathCacheDirectory, path.data(),
path.size());
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_CACHE not defined.";
return false;
}

case base::DIR_TEMP: {
bool success =
SbSystemGetPath(kSbSystemPathTempDirectory, path.data(), path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "DIR_TEMP not defined.";
return false;
}

case base::DIR_HOME:
// TODO: Add a home directory to SbSystemPathId and get it from there.
return PathProviderStarboard(base::DIR_CACHE, result);

case base::DIR_SYSTEM_FONTS:
if (SbSystemGetPath(kSbSystemPathFontDirectory, path.data(),
path.size())) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_SYSTEM_FONTS not defined.";
return false;

case base::DIR_SYSTEM_FONTS_CONFIGURATION:
if (SbSystemGetPath(kSbSystemPathFontConfigurationDirectory, path.data(),
path.size())) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_SYSTEM_FONTS_CONFIGURATION not defined.";
return false;
}

return false;
}

}
48 changes: 48 additions & 0 deletions base/base_paths_starboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef BASE_BASE_PATHS_STARBOARD_H_
#define BASE_BASE_PATHS_STARBOARD_H_

// This file declares Starboard-specific path keys for the base module. These
// can be used with the PathService to access various special directories and
// files.

namespace base {

enum {
PATH_STARBOARD_START = 500,

DIR_CACHE, // Directory where to put cache data. Note this is
// *not* where the browser cache lives, but the
// browser cache can be a subdirectory.

DIR_SYSTEM_FONTS, // Directory where system font files can be
// be found. This is only specified on
// platforms that provide fonts usable by
// Starboard applications.

DIR_SYSTEM_FONTS_CONFIGURATION, // Directory where system font configuration
// metadata can be found. May be the same
// directory as DIR_SYSTEM_FONTS, but not
// necessarily. This is only specified on
// platforms that provide fonts usable by
// Starboard applications.

PATH_STARBOARD_END
};

} // namespace base

#endif // BASE_BASE_PATHS_STARBOARD_H_
1 change: 1 addition & 0 deletions base/containers/id_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <limits>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not needed
Also there is not #ifdef guard.


#include "base/check.h"
#include "base/check_op.h"
Expand Down
1 change: 1 addition & 0 deletions base/debug/asan_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#if defined(ADDRESS_SANITIZER)
#include <sanitizer/asan_interface.h>
#include <string.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


#include "base/debug/task_trace.h"
#include "base/no_destructor.h"
Expand Down
6 changes: 6 additions & 0 deletions base/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class EnvironmentImpl : public Environment {
if (result)
*result = env_value;
return true;
#else
return false;
#endif
}

Expand All @@ -83,6 +85,8 @@ class EnvironmentImpl : public Environment {
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// On success, zero is returned.
return !setenv(variable_name.data(), new_value.c_str(), 1);
#else
return false;
#endif
}

Expand All @@ -93,6 +97,8 @@ class EnvironmentImpl : public Environment {
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// On success, zero is returned.
return !unsetenv(variable_name.data());
#else
return false;
#endif
}
};
Expand Down
17 changes: 17 additions & 0 deletions base/functional/unretained_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ struct hb_set_t;
struct wl_gpu;
struct wl_shm;
struct wl_surface;
#ifdef COBALT_PENDING_CLEAN_UP
struct SbPlayerPrivate;
struct SbWindowPrivate;
struct SbUiNavItemPrivate;
struct SbDrmSystemPrivate;
#endif

namespace base::internal {

Expand Down Expand Up @@ -114,6 +120,17 @@ inline constexpr bool IsIncompleteTypeSafeForUnretained<wl_shm> = true;
template <>
inline constexpr bool IsIncompleteTypeSafeForUnretained<wl_surface> = true;

#ifdef COBALT_PENDING_CLEAN_UP
template <>
inline constexpr bool IsIncompleteTypeSafeForUnretained<SbPlayerPrivate> = true;
template <>
inline constexpr bool IsIncompleteTypeSafeForUnretained<SbWindowPrivate> = true;
template <>
inline constexpr bool IsIncompleteTypeSafeForUnretained<SbUiNavItemPrivate> = true;
template <>
inline constexpr bool IsIncompleteTypeSafeForUnretained<SbDrmSystemPrivate> = true;
#endif

template <typename T, typename SFINAE = void>
struct TypeSupportsUnretained {
// Incrementally enforce the requirement to be completely defined. For now,
Expand Down
8 changes: 5 additions & 3 deletions base/i18n/break_iterator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ TEST(BreakIteratorTest, BreakWordThai) {
// dictionary to detect word boundaries in Thai, Chinese, Japanese, Burmese,
// and Khmer. Due to the size of such a table, the part for Chinese and
// Japanese is not shipped on mobile.
// Cobalt does not support Chinese/Japanese word breaking yet. This feature
// requires a big dictionary(cjdict.txt) to support.
#if !(BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID))

TEST(BreakIteratorTest, BreakWordChinese) {
TEST(BreakIteratorTest, DISABLED_BreakWordChinese) {
// Terms in Traditional Chinese, without spaces in between.
const char16_t term1[] = u"瀏覽";
const char16_t term2[] = u"速度";
Expand All @@ -164,7 +166,7 @@ TEST(BreakIteratorTest, BreakWordChinese) {
EXPECT_FALSE(iter.IsWord());
}

TEST(BreakIteratorTest, BreakWordJapanese) {
TEST(BreakIteratorTest, DISABLED_BreakWordJapanese) {
// Terms in Japanese, without spaces in between.
const char16_t term1[] = u"モバイル";
const char16_t term2[] = u"でも";
Expand All @@ -182,7 +184,7 @@ TEST(BreakIteratorTest, BreakWordJapanese) {
EXPECT_FALSE(iter.IsWord());
}

TEST(BreakIteratorTest, BreakWordChineseEnglish) {
TEST(BreakIteratorTest, DISABLED_BreakWordChineseEnglish) {
// Terms in Simplified Chinese mixed with English and wide punctuations.
std::u16string space(u" ");
const char16_t token1[] = u"下载";
Expand Down
10 changes: 10 additions & 0 deletions base/i18n/icu_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
#include "third_party/icu/source/i18n/unicode/timezone.h"
#endif

#if defined(STARBOARD)
#include "starboard/client_porting/icu_init/icu_init.h"
#include "starboard/types.h"
#endif

namespace base::i18n {

#if !BUILDFLAG(IS_NACL)
Expand Down Expand Up @@ -418,6 +423,10 @@ void SetIcuTimeZoneDataDirForTesting(const char* dir) {
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)

bool InitializeICU() {
#if defined(STARBOARD)
IcuInit();
return true;
#else
#if DCHECK_IS_ON()
DCHECK(!g_check_called_once || !g_called_once);
g_called_once = true;
Expand All @@ -433,6 +442,7 @@ bool InitializeICU() {
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)

return DoCommonInitialization();
#endif // defined(STARBOARD)
}

void AllowMultipleInitializeCallsForTesting() {
Expand Down
9 changes: 8 additions & 1 deletion base/immediate_crash.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#define BASE_IMMEDIATE_CRASH_H_

#include "build/build_config.h"
#if defined(STARBOARD)
#include "starboard/common/log.h"
#endif

// Crashes in the fastest possible way with no attempt at logging.
// There are several constraints; see http://crbug.com/664209 for more context.
Expand Down Expand Up @@ -41,7 +44,11 @@
// be removed in followups, so splitting it up like this now makes it easy to
// land the followups.

#if defined(COMPILER_GCC)
#if defined(STARBOARD)
#define IMMEDIATE_CRASH() SB_CHECK(false)
#define TRAP_SEQUENCE1_() SB_CHECK(false)
#define TRAP_SEQUENCE2_()
#elif defined(COMPILER_GCC)

#if BUILDFLAG(IS_NACL)

Expand Down
5 changes: 5 additions & 0 deletions base/json/json_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ TEST(JSONReaderTest, LiteralRoots) {
TEST(JSONReaderTest, ReadFromFile) {
FilePath path;
ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path));
#if defined(STARBOARD)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave out for now

path = path.Append(FILE_PATH_LITERAL("base"));
path = path.Append(FILE_PATH_LITERAL("test"));
path = path.Append(FILE_PATH_LITERAL("data"));
#endif
path = path.AppendASCII("json");
ASSERT_TRUE(base::PathExists(path));

Expand Down
Loading
Loading