| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 MOJO_DART_EMBEDDER_IO_FILTER_H_ |
| 6 #define MOJO_DART_EMBEDDER_IO_FILTER_H_ |
| 7 |
| 8 #include "dart/runtime/include/dart_api.h" |
| 9 #include "mojo/public/cpp/system/macros.h" |
| 10 #include "third_party/zlib/zlib.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace dart { |
| 14 |
| 15 class Filter { |
| 16 public: |
| 17 virtual ~Filter() {} |
| 18 |
| 19 virtual bool Init() = 0; |
| 20 |
| 21 /** |
| 22 * On a successful call to Process, Process will take ownership of data. On |
| 23 * successive calls to either Processed or ~Filter, data will be freed with |
| 24 * a delete[] call. |
| 25 */ |
| 26 virtual bool Process(uint8_t* data, intptr_t length) = 0; |
| 27 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
| 28 bool end) = 0; |
| 29 |
| 30 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, |
| 31 Filter* filter_pointer); |
| 32 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, |
| 33 Filter** filter_pointer); |
| 34 |
| 35 bool initialized() const { return initialized_; } |
| 36 void set_initialized(bool value) { initialized_ = value; } |
| 37 uint8_t* processed_buffer() { return processed_buffer_; } |
| 38 intptr_t processed_buffer_size() const { return kFilterBufferSize; } |
| 39 |
| 40 protected: |
| 41 Filter() : initialized_(false) {} |
| 42 |
| 43 private: |
| 44 static const intptr_t kFilterBufferSize = 65536; |
| 45 uint8_t processed_buffer_[kFilterBufferSize]; |
| 46 bool initialized_; |
| 47 |
| 48 MOJO_DISALLOW_COPY_AND_ASSIGN(Filter); |
| 49 }; |
| 50 |
| 51 class ZLibDeflateFilter : public Filter { |
| 52 public: |
| 53 ZLibDeflateFilter(bool gzip, int32_t level, int32_t window_bits, |
| 54 int32_t mem_level, int32_t strategy, |
| 55 uint8_t* dictionary, intptr_t dictionary_length, bool raw) |
| 56 : gzip_(gzip), level_(level), window_bits_(window_bits), |
| 57 mem_level_(mem_level), strategy_(strategy), dictionary_(dictionary), |
| 58 dictionary_length_(dictionary_length), raw_(raw), current_buffer_(NULL) |
| 59 {} |
| 60 virtual ~ZLibDeflateFilter(); |
| 61 |
| 62 virtual bool Init(); |
| 63 virtual bool Process(uint8_t* data, intptr_t length); |
| 64 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
| 65 bool end); |
| 66 |
| 67 private: |
| 68 const bool gzip_; |
| 69 const int32_t level_; |
| 70 const int32_t window_bits_; |
| 71 const int32_t mem_level_; |
| 72 const int32_t strategy_; |
| 73 uint8_t* dictionary_; |
| 74 const intptr_t dictionary_length_; |
| 75 const bool raw_; |
| 76 uint8_t* current_buffer_; |
| 77 z_stream stream_; |
| 78 |
| 79 MOJO_DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter); |
| 80 }; |
| 81 |
| 82 class ZLibInflateFilter : public Filter { |
| 83 public: |
| 84 ZLibInflateFilter(int32_t window_bits, uint8_t* dictionary, |
| 85 intptr_t dictionary_length, bool raw) |
| 86 : window_bits_(window_bits), dictionary_(dictionary), |
| 87 dictionary_length_(dictionary_length), raw_(raw), current_buffer_(NULL) |
| 88 {} |
| 89 virtual ~ZLibInflateFilter(); |
| 90 |
| 91 virtual bool Init(); |
| 92 virtual bool Process(uint8_t* data, intptr_t length); |
| 93 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
| 94 bool end); |
| 95 |
| 96 private: |
| 97 const int32_t window_bits_; |
| 98 uint8_t* dictionary_; |
| 99 const intptr_t dictionary_length_; |
| 100 const bool raw_; |
| 101 uint8_t* current_buffer_; |
| 102 z_stream stream_; |
| 103 |
| 104 MOJO_DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter); |
| 105 }; |
| 106 |
| 107 } // namespace dart |
| 108 } // namespace mojo |
| 109 |
| 110 #endif // MOJO_DART_EMBEDDER_IO_FILTER_H_ |
| OLD | NEW |