diff options
author | mkosiba <mkosiba@chromium.org> | 2015-01-09 05:10:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-09 13:11:05 +0000 |
commit | 3c766cc321a77febd8cf726436e22ab385f8ac1b (patch) | |
tree | 69f80a3088b48f0cd108a179f30adcc315b862b2 /base | |
parent | c5feb0407d876d63c4db686e0b7c8b8f2b73bf6e (diff) | |
download | chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.zip chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.tar.gz chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.tar.bz2 |
mmap V8 snapshot and ICU data file in the android_webview
This makes it possible to mmap the V8 snapshot and ICU data file
directly from the WebView APK.
Doing so makes it possible to remove the android_webview_telemetry_build
flag which in turns means we can build the WebView with the same
set of flags that Chrome on Android uses.
BUG=442338
Review URL: https://codereview.chromium.org/812393002
Cr-Commit-Position: refs/heads/master@{#310765}
Diffstat (limited to 'base')
-rw-r--r-- | base/files/memory_mapped_file.cc | 2 | ||||
-rw-r--r-- | base/files/memory_mapped_file_posix.cc | 2 | ||||
-rw-r--r-- | base/i18n/icu_util.cc | 27 | ||||
-rw-r--r-- | base/i18n/icu_util.h | 9 | ||||
-rw-r--r-- | base/posix/global_descriptors.cc | 39 | ||||
-rw-r--r-- | base/posix/global_descriptors.h | 26 |
6 files changed, 80 insertions, 25 deletions
diff --git a/base/files/memory_mapped_file.cc b/base/files/memory_mapped_file.cc index 745a5ff..891fcff 100644 --- a/base/files/memory_mapped_file.cc +++ b/base/files/memory_mapped_file.cc @@ -31,6 +31,7 @@ MemoryMappedFile::~MemoryMappedFile() { CloseHandles(); } +#if !defined(OS_NACL) bool MemoryMappedFile::Initialize(const FilePath& file_name) { if (IsValid()) return false; @@ -85,5 +86,6 @@ void MemoryMappedFile::CalculateVMAlignedBoundaries(int64 start, *aligned_start = start & ~mask; *aligned_size = (size + *offset + mask) & ~mask; } +#endif } // namespace base diff --git a/base/files/memory_mapped_file_posix.cc b/base/files/memory_mapped_file_posix.cc index ebf38779..168da92 100644 --- a/base/files/memory_mapped_file_posix.cc +++ b/base/files/memory_mapped_file_posix.cc @@ -16,6 +16,7 @@ namespace base { MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) { } +#if !defined(OS_NACL) bool MemoryMappedFile::MapFileRegionToMemory( const MemoryMappedFile::Region& region) { ThreadRestrictions::AssertIOAllowed(); @@ -74,6 +75,7 @@ bool MemoryMappedFile::MapFileRegionToMemory( data_ += data_offset; return true; } +#endif void MemoryMappedFile::CloseHandles() { ThreadRestrictions::AssertIOAllowed(); diff --git a/base/i18n/icu_util.cc b/base/i18n/icu_util.cc index e0bd62c..f1fdda7 100644 --- a/base/i18n/icu_util.cc +++ b/base/i18n/icu_util.cc @@ -27,21 +27,21 @@ #define ICU_UTIL_DATA_SHARED 1 #define ICU_UTIL_DATA_STATIC 2 -#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE +namespace base { +namespace i18n { + // Use an unversioned file name to simplify a icu version update down the road. // No need to change the filename in multiple places (gyp files, windows // build pkg configurations, etc). 'l' stands for Little Endian. -#define ICU_UTIL_DATA_FILE_NAME "icudtl.dat" -#elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED +// This variable is exported through the header file. +const char kIcuDataFileName[] = "icudtl.dat"; +#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" #if defined(OS_WIN) #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" #endif #endif -namespace base { -namespace i18n { - namespace { #if !defined(NDEBUG) @@ -53,9 +53,10 @@ bool g_check_called_once = true; #endif } - #if defined(OS_ANDROID) -bool InitializeICUWithFileDescriptor(int data_fd) { +bool InitializeICUWithFileDescriptor( + int data_fd, + base::MemoryMappedFile::Region data_region) { #if !defined(NDEBUG) DCHECK(!g_check_called_once || !g_called_once); g_called_once = true; @@ -67,7 +68,7 @@ bool InitializeICUWithFileDescriptor(int data_fd) { #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); if (!mapped_file.IsValid()) { - if (!mapped_file.Initialize(base::File(data_fd))) { + if (!mapped_file.Initialize(base::File(data_fd), data_region)) { LOG(ERROR) << "Couldn't mmap icu data file"; return false; } @@ -135,13 +136,15 @@ bool InitializeICU() { bool path_ok = PathService::Get(base::DIR_EXE, &data_path); #endif DCHECK(path_ok); - data_path = data_path.AppendASCII(ICU_UTIL_DATA_FILE_NAME); + data_path = data_path.AppendASCII(kIcuDataFileName); #else // Assume it is in the framework bundle's Resources directory. + base::ScopedCFTypeRef<CFStringRef> data_file_name( + SysUTF8ToCFStringRef(kIcuDataFileName)); FilePath data_path = - base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); + base::mac::PathForFrameworkBundleResource(data_file_name); if (data_path.empty()) { - LOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; + LOG(ERROR) << kIcuDataFileName << " not found in bundle"; return false; } #endif // OS check diff --git a/base/i18n/icu_util.h b/base/i18n/icu_util.h index b0a5dbc..5094cb0 100644 --- a/base/i18n/icu_util.h +++ b/base/i18n/icu_util.h @@ -5,12 +5,15 @@ #ifndef BASE_I18N_ICU_UTIL_H_ #define BASE_I18N_ICU_UTIL_H_ -#include "build/build_config.h" +#include "base/files/memory_mapped_file.h" #include "base/i18n/base_i18n_export.h" +#include "build/build_config.h" namespace base { namespace i18n { +BASE_I18N_EXPORT extern const char kIcuDataFileName[]; + // Call this function to load ICU's data tables for the current process. This // function should be called before ICU is used. BASE_I18N_EXPORT bool InitializeICU(); @@ -18,7 +21,9 @@ BASE_I18N_EXPORT bool InitializeICU(); #if defined(OS_ANDROID) // Android uses a file descriptor passed by browser process to initialize ICU // in render processes. -BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor(int data_fd); +BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor( + int data_fd, + base::MemoryMappedFile::Region data_region); #endif // In a test binary, the call above might occur twice. diff --git a/base/posix/global_descriptors.cc b/base/posix/global_descriptors.cc index bcca443..6c18783 100644 --- a/base/posix/global_descriptors.cc +++ b/base/posix/global_descriptors.cc @@ -11,6 +11,16 @@ namespace base { +GlobalDescriptors::Descriptor::Descriptor(Key key, int fd) + : key(key), fd(fd), region(base::MemoryMappedFile::Region::kWholeFile) { +} + +GlobalDescriptors::Descriptor::Descriptor(Key key, + int fd, + base::MemoryMappedFile::Region region) + : key(key), fd(fd), region(region) { +} + // static GlobalDescriptors* GlobalDescriptors::GetInstance() { typedef Singleton<base::GlobalDescriptors, @@ -30,23 +40,38 @@ int GlobalDescriptors::Get(Key key) const { int GlobalDescriptors::MaybeGet(Key key) const { for (Mapping::const_iterator i = descriptors_.begin(); i != descriptors_.end(); ++i) { - if (i->first == key) - return i->second; + if (i->key == key) + return i->fd; } return -1; } void GlobalDescriptors::Set(Key key, int fd) { - for (Mapping::iterator - i = descriptors_.begin(); i != descriptors_.end(); ++i) { - if (i->first == key) { - i->second = fd; + Set(key, fd, base::MemoryMappedFile::Region::kWholeFile); +} + +void GlobalDescriptors::Set(Key key, + int fd, + base::MemoryMappedFile::Region region) { + for (auto& i : descriptors_) { + if (i.key == key) { + i.fd = fd; + i.region = region; return; } } - descriptors_.push_back(std::make_pair(key, fd)); + descriptors_.push_back(Descriptor(key, fd, region)); +} + +base::MemoryMappedFile::Region GlobalDescriptors::GetRegion(Key key) const { + for (const auto& i : descriptors_) { + if (i.key == key) + return i.region; + } + DLOG(FATAL) << "Unknown global descriptor: " << key; + return base::MemoryMappedFile::Region::kWholeFile; } void GlobalDescriptors::Reset(const Mapping& mapping) { diff --git a/base/posix/global_descriptors.h b/base/posix/global_descriptors.h index 3d7369c31..c774634 100644 --- a/base/posix/global_descriptors.h +++ b/base/posix/global_descriptors.h @@ -12,6 +12,7 @@ #include <stdint.h> +#include "base/files/memory_mapped_file.h" #include "base/memory/singleton.h" namespace base { @@ -36,8 +37,18 @@ namespace base { class BASE_EXPORT GlobalDescriptors { public: typedef uint32_t Key; - typedef std::pair<Key, int> KeyFDPair; - typedef std::vector<KeyFDPair> Mapping; + struct Descriptor { + Descriptor(Key key, int fd); + Descriptor(Key key, int fd, base::MemoryMappedFile::Region region); + + // Globally unique key. + Key key; + // Actual FD. + int fd; + // Optional region, defaults to kWholeFile. + base::MemoryMappedFile::Region region; + }; + typedef std::vector<Descriptor> Mapping; // Often we want a canonical descriptor for a given Key. In this case, we add // the following constant to the key value: @@ -53,12 +64,19 @@ class BASE_EXPORT GlobalDescriptors { // Get a descriptor given a key. It is a fatal error if the key is not known. int Get(Key key) const; - // Get a descriptor give a key. Returns -1 on error. + // Get a descriptor given a key. Returns -1 on error. int MaybeGet(Key key) const; - // Set the descriptor for the given key. + // Get a region given a key. It is a fatal error if the key is not known. + base::MemoryMappedFile::Region GetRegion(Key key) const; + + // Set the descriptor for the given |key|. This sets the region associated + // with |key| to kWholeFile. void Set(Key key, int fd); + // Set the descriptor and |region| for the given |key|. + void Set(Key key, int fd, base::MemoryMappedFile::Region region); + void Reset(const Mapping& mapping); private: |