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

Side by Side Diff: base/file_descriptor_store.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Synced + addressed comment from @rockot 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
9 #include "base/logging.h"
10
11 namespace base {
12
13 FileDescriptorStore::Descriptor::Descriptor(const std::string& key,
14 base::ScopedFD fd)
15 : key(key),
16 fd(std::move(fd)),
17 region(base::MemoryMappedFile::Region::kWholeFile) {}
18
19 FileDescriptorStore::Descriptor::Descriptor(
20 const std::string& key,
21 base::ScopedFD fd,
22 base::MemoryMappedFile::Region region)
23 : key(key), fd(std::move(fd)), region(region) {}
24
25 FileDescriptorStore::Descriptor::Descriptor(
26 FileDescriptorStore::Descriptor&& other)
27 : key(other.key), fd(std::move(other.fd)), region(other.region) {}
28
29 FileDescriptorStore::Descriptor::~Descriptor() {}
30
31 FileDescriptorStore::Descriptor& FileDescriptorStore::Descriptor::operator=(
32 FileDescriptorStore::Descriptor&& other) {
dcheng 2017/02/10 08:44:15 I think this and the move ctor can be explicitly d
Jay Civelli 2017/02/13 18:48:25 If I default the move constructor, I get a "Compl
dcheng 2017/02/15 08:05:27 Sorry, to clarify, they should only be declared in
33 key = other.key;
34 fd = std::move(other.fd);
35 region = other.region;
36 return *this;
37 }
38
39 // static
40 FileDescriptorStore& FileDescriptorStore::GetInstance() {
41 static FileDescriptorStore* store = new FileDescriptorStore;
42 return *store;
43 }
44
45 base::ScopedFD FileDescriptorStore::TakeFD(
46 const std::string& key,
47 base::MemoryMappedFile::Region* region) {
48 base::ScopedFD fd = MaybeTakeFD(key, region);
49 if (!fd.is_valid())
50 DLOG(FATAL) << "Unknown global descriptor: " << key;
51 return fd;
52 }
53
54 base::ScopedFD FileDescriptorStore::MaybeTakeFD(
55 const std::string& key,
56 base::MemoryMappedFile::Region* region) {
57 auto iter = descriptors_.find(key);
58 if (iter == descriptors_.end())
59 return base::ScopedFD();
60 descriptors_.erase(iter);
61 if (region)
62 *region = iter->second.region;
dcheng 2017/02/10 08:44:15 Isn't referencing |iter| here undefined behavior?
Jay Civelli 2017/02/13 18:48:25 You are right! Fixed.
63 return std::move(iter->second.fd);
64 }
65
66 void FileDescriptorStore::Set(const std::string& key, base::ScopedFD fd) {
67 Set(key, std::move(fd), base::MemoryMappedFile::Region::kWholeFile);
68 }
69
70 void FileDescriptorStore::Set(const std::string& key,
71 base::ScopedFD fd,
72 base::MemoryMappedFile::Region region) {
73 Descriptor descriptor(key, std::move(fd), region);
74 descriptors_.insert(std::make_pair(key, std::move(descriptor)));
75 }
76
77 FileDescriptorStore::FileDescriptorStore() {}
78
79 FileDescriptorStore::~FileDescriptorStore() {}
80
81 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698