Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: ui/file_manager/zip_archiver/cpp/compressor_io_javascript_stream.h

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Delete BUILD.gn Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium OS Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ 5 #ifndef COMPRESSOR_IO_JAVSCRIPT_STREAM_H_
6 #define COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ 6 #define COMPRESSOR_IO_JAVSCRIPT_STREAM_H_
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <string> 9 #include <string>
10 10
11 #include "archive.h"
12 #include "ppapi/cpp/instance_handle.h" 11 #include "ppapi/cpp/instance_handle.h"
13 #include "ppapi/cpp/var_array_buffer.h" 12 #include "ppapi/cpp/var_array_buffer.h"
14 #include "ppapi/utility/completion_callback_factory.h" 13 #include "ppapi/utility/completion_callback_factory.h"
15 #include "ppapi/utility/threading/lock.h" 14 #include "ppapi/utility/threading/lock.h"
16 #include "ppapi/utility/threading/simple_thread.h" 15 #include "ppapi/utility/threading/simple_thread.h"
17 16
18 #include "compressor_stream.h" 17 #include "compressor_stream.h"
19 #include "javascript_compressor_requestor_interface.h" 18 #include "javascript_compressor_requestor_interface.h"
20 19
20 // A namespace with constants used by CompressorArchiveLibarchive.
21 namespace compressor_stream_constants {
22 // We need at least 256KB for MiniZip.
23 const int64_t kMaximumDataChunkSize = 512 * 1024;
mtomasz 2017/04/10 07:15:09 nit: AFAIK initializations should be in .cc file.
takise 2017/04/11 06:00:51 I want to place this constant here because this va
24 } // namespace compressor_archive_constants
25
21 class CompressorIOJavaScriptStream : public CompressorStream { 26 class CompressorIOJavaScriptStream : public CompressorStream {
22 public: 27 public:
23 CompressorIOJavaScriptStream( 28 CompressorIOJavaScriptStream(
24 JavaScriptCompressorRequestorInterface* requestor); 29 JavaScriptCompressorRequestorInterface* requestor);
25 30
26 virtual ~CompressorIOJavaScriptStream(); 31 virtual ~CompressorIOJavaScriptStream();
27 32
28 virtual int64_t Write(int64_t bytes_to_read, 33 // Flushes the data in buffer_. Since minizip sends tons of write requests and
29 const pp::VarArrayBuffer& buffer); 34 // communication between C++ and JS is very expensive, we need to cache data
35 // in buffer_ and send them in a lump.
36 virtual int64_t Flush();
30 37
31 virtual void WriteChunkDone(int64_t write_bytes); 38 virtual int64_t Write(int64_t zip_offset,
39 int64_t zip_length,
40 const void* zip_buffer);
41
42 virtual int64_t WriteChunkDone(int64_t write_bytes);
32 43
33 virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer); 44 virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer);
34 45
35 virtual void ReadFileChunkDone(int64_t read_bytes, 46 virtual int64_t ReadFileChunkDone(int64_t read_bytes,
36 pp::VarArrayBuffer* buffer); 47 pp::VarArrayBuffer* buffer);
37 48
38 private: 49 private:
39 // A requestor that makes calls to JavaScript to read and write chunks. 50 // A requestor that makes calls to JavaScript to read and write chunks.
40 JavaScriptCompressorRequestorInterface* requestor_; 51 JavaScriptCompressorRequestorInterface* requestor_;
41 52
42 pthread_mutex_t shared_state_lock_; 53 pthread_mutex_t shared_state_lock_;
43 pthread_cond_t available_data_cond_; 54 pthread_cond_t available_data_cond_;
44 pthread_cond_t data_written_cond_; 55 pthread_cond_t data_written_cond_;
45 56
46 // The bytelength of the data written onto the archive for the last write 57 // 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 58 // chunk request. If this value is negative, some error occurred when writing
48 // a chunk in JavaScript. 59 // a chunk in JavaScript.
49 int64_t written_bytes_; 60 int64_t written_bytes_;
50 61
51 // The bytelength of the data read from the entry for the last read file chunk 62 // 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 63 // request. If this value is negative, some error occurred when reading a
53 // chunk in JavaScript. 64 // chunk in JavaScript.
54 int64_t read_bytes_; 65 int64_t read_bytes_;
55 66
56 // True if destination_buffer_ is available. 67 // True if destination_buffer_ is available.
57 bool available_data_; 68 bool available_data_;
58 69
59 // Stores the data read from JavaScript. 70 // Stores the data read from JavaScript.
60 char* destination_buffer_; 71 char* destination_buffer_;
72
73 // The current offset from which buffer_ has data.
74 int64_t buffer_offset_;
75
76 // The size of the data in buffer_.
77 int64_t buffer_data_length_;
78
79 // The buffer that contains cached data.
80 char buffer_[compressor_stream_constants::kMaximumDataChunkSize];
61 }; 81 };
62 82
63 #endif // COMPRESSOR_IO_JAVSCRIPT_STREAM_H_ 83 #endif // COMPRESSOR_IO_JAVSCRIPT_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698