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 NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_TEMPORARY_FILE_H_ |
| 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_TEMPORARY_FILE_H_ |
| 7 |
| 8 #include "native_client/src/include/nacl_macros.h" |
| 9 #include "native_client/src/include/nacl_string.h" |
| 10 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 11 |
| 12 #include "ppapi/cpp/completion_callback.h" |
| 13 |
| 14 namespace plugin { |
| 15 |
| 16 class Plugin; |
| 17 |
| 18 // Translation creates two temporary files. The first temporary file holds |
| 19 // the object file created by llc. The second holds the nexe produced by |
| 20 // the linker. Both of these temporary files are used to both write and |
| 21 // read according to the following matrix: |
| 22 // |
| 23 // PnaclCoordinator::obj_file_: |
| 24 // written by: llc (passed in explicitly through SRPC) |
| 25 // read by: ld (returned via lookup service from SRPC) |
| 26 // PnaclCoordinator::nexe_file_: |
| 27 // written by: ld (passed in explicitly through SRPC) |
| 28 // read by: sel_ldr (passed in explicitly to command channel) |
| 29 // |
| 30 |
| 31 // TempFile represents a file used as a temporary between stages in |
| 32 // translation. It is automatically deleted when all handles are closed |
| 33 // (or earlier -- immediately unlinked on POSIX systems). The file is only |
| 34 // opened, once, but because both reading and writing are necessary (and in |
| 35 // different processes), the user should reset / seek back to the beginning |
| 36 // of the file between sessions. |
| 37 class TempFile { |
| 38 public: |
| 39 // Create a TempFile. |
| 40 explicit TempFile(Plugin* plugin); |
| 41 ~TempFile(); |
| 42 |
| 43 // Opens a writeable file IO object and descriptor referring to the file. |
| 44 void Open(const pp::CompletionCallback& cb); |
| 45 // Resets file position of the handle, for reuse. |
| 46 bool Reset(); |
| 47 |
| 48 // Accessors. |
| 49 // The nacl::DescWrapper* for the writeable version of the file. |
| 50 nacl::DescWrapper* get_wrapper() { return wrapper_.get(); } |
| 51 nacl::DescWrapper* release_wrapper() { |
| 52 return wrapper_.release(); |
| 53 } |
| 54 |
| 55 // For quota management. |
| 56 const nacl::string identifier() const { |
| 57 return nacl::string(reinterpret_cast<const char*>(identifier_)); |
| 58 } |
| 59 |
| 60 private: |
| 61 NACL_DISALLOW_COPY_AND_ASSIGN(TempFile); |
| 62 |
| 63 Plugin* plugin_; |
| 64 nacl::scoped_ptr<nacl::DescWrapper> wrapper_; |
| 65 |
| 66 // An identifier string used for quota request processing. The quota |
| 67 // interface needs a string that is unique per sel_ldr instance only, so |
| 68 // the identifiers can be reused between runs of the translator, start-ups of |
| 69 // the browser, etc. |
| 70 uint8_t identifier_[16]; |
| 71 // A counter to dole out unique identifiers. |
| 72 static uint32_t next_identifier; |
| 73 }; |
| 74 |
| 75 } // namespace plugin |
| 76 |
| 77 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_TEMPORARY_FILE_H_ |
OLD | NEW |