Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / nacl / renderer / plugin / temporary_file.h
blob5237b4664cd8add9018cd280780f4cee060968a7
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.
5 #ifndef COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_
6 #define COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_
8 #include "native_client/src/include/nacl_macros.h"
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
11 #include "ppapi/c/private/pp_file_handle.h"
13 namespace plugin {
15 class Plugin;
17 // Translation creates two temporary files. The first temporary file holds
18 // the object file created by llc. The second holds the nexe produced by
19 // the linker. Both of these temporary files are used to both write and
20 // read according to the following matrix:
22 // PnaclCoordinator::obj_file_:
23 // written by: llc (passed in explicitly through SRPC)
24 // read by: ld (returned via lookup service from SRPC)
25 // PnaclCoordinator::nexe_file_:
26 // written by: ld (passed in explicitly through SRPC)
27 // read by: sel_ldr (passed in explicitly to command channel)
30 // TempFile represents a file used as a temporary between stages in
31 // translation. It is automatically deleted when all handles are closed
32 // (or earlier -- immediately unlinked on POSIX systems). The file is only
33 // opened, once, but because both reading and writing are necessary (and in
34 // different processes), the user should reset / seek back to the beginning
35 // of the file between sessions.
36 class TempFile {
37 public:
38 // Create a TempFile.
39 TempFile(Plugin* plugin, PP_FileHandle handle);
40 ~TempFile();
42 // Opens a temporary file object and descriptor wrapper referring to the file.
43 // If |writeable| is true, the descriptor will be opened for writing, and
44 // write_wrapper will return a valid pointer, otherwise it will return NULL.
45 int32_t Open(bool writeable);
46 // Resets file position of the handle, for reuse.
47 bool Reset();
49 // Accessors.
50 // The nacl::DescWrapper* for the writeable version of the file.
51 nacl::DescWrapper* write_wrapper() { return write_wrapper_.get(); }
52 nacl::DescWrapper* read_wrapper() { return read_wrapper_.get(); }
54 // Returns the handle to the file repesented and resets the internal handle
55 // and all wrappers.
56 PP_FileHandle TakeFileHandle();
58 private:
59 NACL_DISALLOW_COPY_AND_ASSIGN(TempFile);
61 Plugin* plugin_;
62 nacl::scoped_ptr<nacl::DescWrapper> read_wrapper_;
63 nacl::scoped_ptr<nacl::DescWrapper> write_wrapper_;
64 PP_FileHandle internal_handle_;
67 } // namespace plugin
69 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_TEMPORARY_FILE_H_