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_H_ | |
6 #define COMPRESSOR_H_ | |
7 | |
8 #include <ctime> | |
9 #include <pthread.h> | |
10 | |
11 #include "archive.h" | |
12 #include "ppapi/cpp/instance_handle.h" | |
13 #include "ppapi/cpp/var_array_buffer.h" | |
14 #include "ppapi/cpp/var_dictionary.h" | |
15 #include "ppapi/utility/completion_callback_factory.h" | |
16 #include "ppapi/utility/threading/simple_thread.h" | |
17 | |
18 #include "compressor_archive.h" | |
19 #include "compressor_stream.h" | |
20 #include "javascript_compressor_requestor_interface.h" | |
21 #include "javascript_message_sender_interface.h" | |
22 | |
23 // Handles all packing operations like creating archive objects and writing data | |
24 // onto the archive. | |
25 class Compressor { | |
26 public: | |
27 Compressor(const pp::InstanceHandle& instance_handle /* Used for workers. */, | |
28 int compressor_id, | |
29 JavaScriptMessageSenderInterface* message_sender); | |
30 | |
31 virtual ~Compressor(); | |
32 | |
33 // Initializes the compressor. | |
34 bool Init(); | |
35 | |
36 // Creates an archive object. | |
37 void CreateArchive(); | |
38 | |
39 // Adds an entry to the archive. | |
40 void AddToArchive(const pp::VarDictionary& dictionary); | |
41 | |
42 // Processes a file chunk sent from JavaScript. | |
43 void ReadFileChunkDone(const pp::VarDictionary& dictionary); | |
44 | |
45 // Receives a write chunk response from JavaScript. | |
46 void WriteChunkDone(const pp::VarDictionary& dictionary); | |
47 | |
48 // Releases all resources obtained by libarchive. | |
49 void CloseArchive(const pp::VarDictionary& dictionary); | |
50 | |
51 // A getter function for the message sender. | |
52 JavaScriptMessageSenderInterface* message_sender() { return message_sender_; } | |
53 | |
54 // A getter function for the requestor. | |
55 JavaScriptCompressorRequestorInterface* requestor() { return requestor_; } | |
56 | |
57 // A getter function for the compressor id. | |
58 int compressor_id() { return compressor_id_; } | |
59 | |
60 private: | |
61 | |
62 // A callback helper for AddToArchive. | |
63 void AddToArchiveCallback(int32_t, const pp::VarDictionary& dictionary); | |
64 | |
65 // A callback helper for CloseArchive. | |
66 void CloseArchiveCallback(int32_t, bool has_error); | |
67 | |
68 // The compressor id of this compressor. | |
69 int compressor_id_; | |
70 | |
71 // An object that sends messages to JavaScript. | |
72 JavaScriptMessageSenderInterface* message_sender_; | |
73 | |
74 // A worker for jobs that require blocking operations or a lot of processing | |
75 // time. Those shouldn't be done on the main thread. The jobs submitted to | |
76 // this thread are executed in order, so a new job must wait for the last job | |
77 // to finish. | |
78 pp::SimpleThread worker_; | |
79 | |
80 // Callback factory used to submit jobs to worker_. | |
81 pp::CompletionCallbackFactory<Compressor> callback_factory_; | |
82 | |
83 // A requestor for making calls to JavaScript. | |
84 JavaScriptCompressorRequestorInterface* requestor_; | |
85 | |
86 // Libarchive wrapper instance per compressor, shared across all operations. | |
87 CompressorArchive* compressor_archive_; | |
88 | |
89 // An instance that takes care of all IO operations. | |
90 CompressorStream* compressor_stream_; | |
91 }; | |
92 | |
93 #endif /// COMPRESSOR_H_ | |
OLD | NEW |