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

Unified Diff: base/file_descriptor_store.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Fix build. Created 3 years, 10 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/file_descriptor_store.h ('k') | base/posix/global_descriptors.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_descriptor_store.cc
diff --git a/base/file_descriptor_store.cc b/base/file_descriptor_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..15188cdf3be4dcc189a984c9defd3938f8ce5c20
--- /dev/null
+++ b/base/file_descriptor_store.cc
@@ -0,0 +1,73 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_descriptor_store.h"
+
+#include <utility>
+
+#include "base/logging.h"
+
+namespace base {
+
+FileDescriptorStore::Descriptor::Descriptor(const std::string& key,
+ base::ScopedFD fd)
+ : key(key),
+ fd(std::move(fd)),
+ region(base::MemoryMappedFile::Region::kWholeFile) {}
+
+FileDescriptorStore::Descriptor::Descriptor(
+ const std::string& key,
+ base::ScopedFD fd,
+ base::MemoryMappedFile::Region region)
+ : key(key), fd(std::move(fd)), region(region) {}
+
+FileDescriptorStore::Descriptor::Descriptor(
+ FileDescriptorStore::Descriptor&& other)
+ : key(other.key), fd(std::move(other.fd)), region(other.region) {}
+
+FileDescriptorStore::Descriptor::~Descriptor() {}
+
+// static
+FileDescriptorStore& FileDescriptorStore::GetInstance() {
+ static FileDescriptorStore* store = new FileDescriptorStore;
+ return *store;
+}
+
+base::ScopedFD FileDescriptorStore::TakeFD(
+ const std::string& key,
+ base::MemoryMappedFile::Region* region) {
+ base::ScopedFD fd = MaybeTakeFD(key, region);
+ if (!fd.is_valid())
+ DLOG(FATAL) << "Unknown global descriptor: " << key;
+ return fd;
+}
+
+base::ScopedFD FileDescriptorStore::MaybeTakeFD(
+ const std::string& key,
+ base::MemoryMappedFile::Region* region) {
+ auto iter = descriptors_.find(key);
+ if (iter == descriptors_.end())
+ return base::ScopedFD();
+ *region = iter->second.region;
+ base::ScopedFD result = std::move(iter->second.fd);
+ descriptors_.erase(iter);
+ return result;
+}
+
+void FileDescriptorStore::Set(const std::string& key, base::ScopedFD fd) {
+ Set(key, std::move(fd), base::MemoryMappedFile::Region::kWholeFile);
+}
+
+void FileDescriptorStore::Set(const std::string& key,
+ base::ScopedFD fd,
+ base::MemoryMappedFile::Region region) {
+ Descriptor descriptor(key, std::move(fd), region);
+ descriptors_.insert(std::make_pair(key, std::move(descriptor)));
+}
+
+FileDescriptorStore::FileDescriptorStore() {}
+
+FileDescriptorStore::~FileDescriptorStore() {}
+
+} // namespace base
« no previous file with comments | « base/file_descriptor_store.h ('k') | base/posix/global_descriptors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698