Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #ifndef BASE_MEMORY_SHARED_MEMORY_HELPER_H_ | |
| 6 #define BASE_MEMORY_SHARED_MEMORY_HELPER_H_ | |
| 7 | |
| 8 #include "base/memory/shared_memory.h" | |
| 9 | |
| 10 #include <fcntl.h> | |
| 11 | |
| 12 namespace base { | |
| 13 | |
| 14 struct ScopedPathUnlinkerTraits { | |
|
Mark Mentovai
2016/12/09 19:53:53
Does this need to be in the header? Doesn’t look l
lawrencewu
2016/12/09 20:32:12
Moved to the .cc file.
| |
| 15 static FilePath* InvalidValue() { return nullptr; } | |
|
Mark Mentovai
2016/12/09 19:53:53
Can probably use const FilePath for this unlinker
lawrencewu
2016/12/09 20:32:12
Done.
| |
| 16 | |
| 17 static void Free(FilePath* path) { | |
| 18 if (unlink(path->value().c_str())) | |
| 19 PLOG(WARNING) << "unlink"; | |
| 20 } | |
| 21 }; | |
| 22 | |
| 23 // Unlinks the FilePath when the object is destroyed. | |
| 24 using ScopedPathUnlinker = ScopedGeneric<FilePath*, ScopedPathUnlinkerTraits>; | |
|
Mark Mentovai
2016/12/09 19:53:53
(through here)
lawrencewu
2016/12/09 20:32:13
Done.
| |
| 25 | |
| 26 #if !defined(OS_ANDROID) | |
| 27 // Makes a temporary file, fdopens it, and then unlinks it. |fp| is populated | |
| 28 // with the fdopened FILE. |readonly_fd| is populated with the opened fd if | |
| 29 // options.share_read_only is true. |path| is populated with the location of | |
| 30 // the file before it was unlinked. | |
| 31 // Returns false if there's an unhandled failure. | |
| 32 bool CreateAnonymousSharedMemory(const SharedMemoryCreateOptions& options, | |
| 33 ScopedFILE* fp, | |
| 34 ScopedFD* readonly_fd, | |
| 35 FilePath* path); | |
| 36 | |
| 37 // Takes the outputs of CreateAnonymousSharedMemory and maps them properly to | |
| 38 // |mapped_file| or |readonly_mapped_file|, depending on which one is populated. | |
| 39 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd, int* mapped_file, | |
| 40 int* readonly_mapped_file); | |
| 41 #endif | |
| 42 | |
| 43 } // namespace base | |
| 44 | |
| 45 #endif // BASE_MEMORY_SHARED_MEMORY_HELPER_H_ | |
| OLD | NEW |