Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Unified Diff: base/posix/global_descriptors.cc

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/posix/global_descriptors.h ('k') | base/prefs/pref_value_map.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/posix/global_descriptors.cc
diff --git a/base/posix/global_descriptors.cc b/base/posix/global_descriptors.cc
index bcca443acc13a7f52794689ee1f0037a8704e364..6c187838ad69d63051a1155d64c26623de8a2db0 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) {
« no previous file with comments | « base/posix/global_descriptors.h ('k') | base/prefs/pref_value_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698