| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_ | |
| 6 #define COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/files/file.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 | |
| 14 #include "ppapi/c/private/pp_file_handle.h" | |
| 15 | |
| 16 namespace plugin { | |
| 17 | |
| 18 class Plugin; | |
| 19 | |
| 20 // Translation creates two temporary files. The first temporary file holds | |
| 21 // the object file created by llc. The second holds the nexe produced by | |
| 22 // the linker. Both of these temporary files are used to both write and | |
| 23 // read according to the following matrix: | |
| 24 // | |
| 25 // PnaclCoordinator::obj_file_: | |
| 26 // written by: llc (passed in explicitly through SRPC) | |
| 27 // read by: ld (returned via lookup service from SRPC) | |
| 28 // PnaclCoordinator::nexe_file_: | |
| 29 // written by: ld (passed in explicitly through SRPC) | |
| 30 // read by: sel_ldr (passed in explicitly to command channel) | |
| 31 // | |
| 32 | |
| 33 // TempFile represents a file used as a temporary between stages in | |
| 34 // translation. It is automatically deleted when all handles are closed | |
| 35 // (or earlier -- immediately unlinked on POSIX systems). The file is only | |
| 36 // opened, once, but because both reading and writing are necessary (and in | |
| 37 // different processes), the user should reset / seek back to the beginning | |
| 38 // of the file between sessions. | |
| 39 class TempFile { | |
| 40 public: | |
| 41 // Create a TempFile. | |
| 42 TempFile(Plugin* plugin, PP_FileHandle handle); | |
| 43 ~TempFile(); | |
| 44 | |
| 45 bool IsValid() { return file_handle_.IsValid(); } | |
| 46 // Resets file position of the handle, for reuse. | |
| 47 bool Reset(); | |
| 48 | |
| 49 // Returns the current size of this file. | |
| 50 int64_t GetLength(); | |
| 51 | |
| 52 // Returns a handle to the file, transferring ownership of it. | |
| 53 PP_FileHandle TakeFileHandle(); | |
| 54 | |
| 55 // Returns a handle to the file, without transferring ownership of it. | |
| 56 // This handle remains valid until the TempFile object is destroyed or | |
| 57 // TakeFileHandle() is called. | |
| 58 PP_FileHandle GetFileHandle(); | |
| 59 | |
| 60 private: | |
| 61 Plugin* plugin_; | |
| 62 base::File file_handle_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(TempFile); | |
| 65 }; | |
| 66 | |
| 67 } // namespace plugin | |
| 68 | |
| 69 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_ | |
| OLD | NEW |