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

Side by Side Diff: base/file_descriptor_store.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Fixed analysis. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_descriptor_store.h"
6
7 #include <utility>
8 #include <vector>
9
10 #include "base/logging.h"
11
12 namespace base {
13
14 FileDescriptorStore::Descriptor::Descriptor(const std::string& key, int fd)
15 : key(key), fd(fd), region(base::MemoryMappedFile::Region::kWholeFile) {}
16
17 FileDescriptorStore::Descriptor::Descriptor(
18 const std::string& key,
19 int fd,
20 base::MemoryMappedFile::Region region)
21 : key(key), fd(fd), region(region) {}
22
23 // static
24 FileDescriptorStore* FileDescriptorStore::GetInstance() {
25 typedef Singleton<base::FileDescriptorStore,
Ken Rockot(use gerrit already) 2017/02/09 17:17:27 Not sure Singleton is necessary, though I honestly
Jay Civelli 2017/02/09 22:08:26 Done.
26 LeakySingletonTraits<base::FileDescriptorStore>>
27 FileDescriptorStoreSingleton;
28 return FileDescriptorStoreSingleton::get();
29 }
30
31 int FileDescriptorStore::Get(const std::string& key) const {
32 const int ret = MaybeGet(key);
33
34 if (ret == -1)
35 DLOG(FATAL) << "Unknown global descriptor: " << key;
36 return ret;
37 }
38
39 int FileDescriptorStore::MaybeGet(const std::string& key) const {
40 for (Mapping::const_iterator i = descriptors_.begin();
41 i != descriptors_.end(); ++i) {
42 if (i->key == key)
43 return i->fd;
44 }
45 return -1;
46 }
47
48 void FileDescriptorStore::Set(const std::string& key, int fd) {
49 Set(key, fd, base::MemoryMappedFile::Region::kWholeFile);
50 }
51
52 void FileDescriptorStore::Set(const std::string& key,
53 int fd,
54 base::MemoryMappedFile::Region region) {
55 for (auto& i : descriptors_) {
56 if (i.key == key) {
57 i.fd = fd;
58 i.region = region;
59 return;
60 }
61 }
62
63 descriptors_.push_back(Descriptor(key, fd, region));
64 }
65
66 base::MemoryMappedFile::Region FileDescriptorStore::GetRegion(
67 const std::string& key) const {
68 for (const auto& i : descriptors_) {
69 if (i.key == key)
70 return i.region;
71 }
72 DLOG(FATAL) << "Unknown global descriptor: " << key;
73 return base::MemoryMappedFile::Region::kWholeFile;
74 }
75
76 void FileDescriptorStore::Reset(const Mapping& mapping) {
77 descriptors_ = mapping;
78 }
79
80 FileDescriptorStore::FileDescriptorStore() {}
81
82 FileDescriptorStore::~FileDescriptorStore() {}
83
84 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698