OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium OS 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 COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ | |
6 #define COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ | |
7 | |
8 #include <pthread.h> | |
9 #include <string> | |
10 | |
11 #include "archive.h" | |
12 #include "ppapi/cpp/instance_handle.h" | |
13 #include "ppapi/cpp/var_array_buffer.h" | |
14 #include "ppapi/utility/completion_callback_factory.h" | |
15 #include "ppapi/utility/threading/lock.h" | |
16 #include "ppapi/utility/threading/simple_thread.h" | |
17 | |
18 #include "compressor_stream.h" | |
19 #include "javascript_compressor_requestor_interface.h" | |
20 | |
21 class CompressorIOJavaScriptStream : public CompressorStream { | |
22 public: | |
23 CompressorIOJavaScriptStream( | |
24 JavaScriptCompressorRequestorInterface* requestor); | |
25 | |
26 virtual ~CompressorIOJavaScriptStream(); | |
27 | |
28 virtual int64_t Write(int64_t bytes_to_read, | |
29 const pp::VarArrayBuffer& buffer); | |
30 | |
31 virtual void WriteChunkDone(int64_t write_bytes); | |
32 | |
33 virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer); | |
34 | |
35 virtual void ReadFileChunkDone(int64_t read_bytes, | |
36 pp::VarArrayBuffer* buffer); | |
37 | |
38 private: | |
39 // A requestor that makes calls to JavaScript to read and write chunks. | |
40 JavaScriptCompressorRequestorInterface* requestor_; | |
41 | |
42 pthread_mutex_t shared_state_lock_; | |
43 pthread_cond_t available_data_cond_; | |
44 pthread_cond_t data_written_cond_; | |
45 | |
46 // The bytelength of the data written onto the archive for the last write | |
47 // chunk request. If this value is negative, some error occurred when writing | |
48 // a chunk in JavaScript. | |
49 int64_t written_bytes_; | |
50 | |
51 // The bytelength of the data read from the entry for the last read file chunk | |
52 // request. If this value is negative, some error occurred when reading a | |
53 // chunk in JavaScript. | |
54 int64_t read_bytes_; | |
55 | |
56 // True if destination_buffer_ is available. | |
57 bool available_data_; | |
58 | |
59 // Stores the data read from JavaScript. | |
60 char* destination_buffer_; | |
61 }; | |
62 | |
63 #endif // COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ | |
OLD | NEW |