summaryrefslogtreecommitdiffstats
path: root/base/posix
diff options
context:
space:
mode:
authormkosiba <mkosiba@chromium.org>2015-01-09 05:10:22 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-09 13:11:05 +0000
commit3c766cc321a77febd8cf726436e22ab385f8ac1b (patch)
tree69f80a3088b48f0cd108a179f30adcc315b862b2 /base/posix
parentc5feb0407d876d63c4db686e0b7c8b8f2b73bf6e (diff)
downloadchromium_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/posix')
-rw-r--r--base/posix/global_descriptors.cc39
-rw-r--r--base/posix/global_descriptors.h26
2 files changed, 54 insertions, 11 deletions
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: