LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void operator()(LogLevel logLevel, const std::string& message, | 100 void operator()(LogLevel logLevel, const std::string& message, |
101 const std::string& source) | 101 const std::string& source) |
102 { | 102 { |
103 throw std::runtime_error("Unexpected error: " + message); | 103 throw std::runtime_error("Unexpected error: " + message); |
104 } | 104 } |
105 }; | 105 }; |
106 | 106 |
107 class ThrowingFileSystem : public AdblockPlus::IFileSystem, public AdblockPlus::
FileSystem | 107 class ThrowingFileSystem : public AdblockPlus::IFileSystem, public AdblockPlus::
FileSystem |
108 { | 108 { |
109 public: | 109 public: |
110 std::shared_ptr<std::istream> Read(const std::string& path) const | 110 IOBuffer Read(const std::string& path) const |
111 { | 111 { |
112 throw std::runtime_error("Not implemented"); | 112 throw std::runtime_error("Not implemented"); |
113 } | 113 } |
114 void Read(const std::string& path, | 114 void Read(const std::string& path, |
115 const ReadCallback& callback) const | 115 const ReadCallback& callback) const |
116 { | 116 { |
117 throw std::runtime_error("Not implemented"); | 117 throw std::runtime_error("Not implemented"); |
118 } | 118 } |
119 | 119 |
120 void Write(const std::string& path, std::ostream& content) | 120 void Write(const std::string& path, const IOBuffer& content) |
121 { | 121 { |
122 throw std::runtime_error("Not implemented"); | 122 throw std::runtime_error("Not implemented"); |
123 } | 123 } |
124 void Write(const std::string& path, const std::vector<char>& data, | 124 void Write(const std::string& path, const IOBuffer& data, |
125 const Callback& callback) | 125 const Callback& callback) |
126 { | 126 { |
127 throw std::runtime_error("Not implemented"); | 127 throw std::runtime_error("Not implemented"); |
128 } | 128 } |
129 | 129 |
130 void Move(const std::string& fromPath, const std::string& toPath) | 130 void Move(const std::string& fromPath, const std::string& toPath) |
131 { | 131 { |
132 throw std::runtime_error("Not implemented"); | 132 throw std::runtime_error("Not implemented"); |
133 } | 133 } |
134 void Move(const std::string& fromPath, const std::string& toPath, | 134 void Move(const std::string& fromPath, const std::string& toPath, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 public: | 167 public: |
168 void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders
, const GetCallback&) override | 168 void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders
, const GetCallback&) override |
169 { | 169 { |
170 throw std::runtime_error("Unexpected GET: " + url); | 170 throw std::runtime_error("Unexpected GET: " + url); |
171 } | 171 } |
172 }; | 172 }; |
173 | 173 |
174 class LazyFileSystem : public AdblockPlus::IFileSystem, public AdblockPlus::File
System | 174 class LazyFileSystem : public AdblockPlus::IFileSystem, public AdblockPlus::File
System |
175 { | 175 { |
176 public: | 176 public: |
177 std::shared_ptr<std::istream> Read(const std::string& path) const | 177 IOBuffer Read(const std::string& path) const |
178 { | 178 { |
179 std::string dummyData(""); | 179 std::string dummyData(""); |
180 if (path == "patterns.ini") | 180 if (path == "patterns.ini") |
181 dummyData = "# Adblock Plus preferences\n[Subscription]\nurl=~fl~"; | 181 dummyData = "# Adblock Plus preferences\n[Subscription]\nurl=~fl~"; |
182 else if (path == "prefs.json") | 182 else if (path == "prefs.json") |
183 dummyData = "{}"; | 183 dummyData = "{}"; |
184 return std::shared_ptr<std::istream>(new std::istringstream(dummyData)); | 184 return IOBuffer(dummyData.cbegin(), dummyData.cend()); |
185 } | 185 } |
186 | 186 |
187 void Read(const std::string& path, const ReadCallback& callback) const | 187 void Read(const std::string& path, const ReadCallback& callback) const |
188 { | 188 { |
189 std::thread([this, path, callback] | 189 std::thread([this, path, callback] |
190 { | 190 { |
191 auto is = Read(path); | 191 auto data = Read(path); |
192 is->seekg(0, std::ios_base::end); | |
193 auto dataSize = is->tellg(); | |
194 is->seekg(0, std::ios_base::beg); | |
195 | |
196 std::vector<char> data(dataSize); | |
197 is->read(data.data(), data.size()); | |
198 callback(std::move(data), ""); | 192 callback(std::move(data), ""); |
199 }).detach(); | 193 }).detach(); |
200 } | 194 } |
201 | 195 |
202 void Write(const std::string& path, std::ostream& content) | 196 void Write(const std::string& path, const IOBuffer& content) |
203 { | 197 { |
204 } | 198 } |
205 | 199 |
206 void Write(const std::string& path, const std::vector<char>& data, | 200 void Write(const std::string& path, const IOBuffer& data, |
207 const Callback& callback) | 201 const Callback& callback) |
208 { | 202 { |
209 std::thread([this, path, data, callback] | 203 std::thread([this, path, data, callback] |
210 { | 204 { |
211 std::stringstream stream; | 205 Write(path, data); |
212 stream.write(data.data(), data.size()); | |
213 Write(path, stream); | |
214 callback(""); | 206 callback(""); |
215 }).detach(); | 207 }).detach(); |
216 } | 208 } |
217 | 209 |
218 void Move(const std::string& fromPath, const std::string& toPath) | 210 void Move(const std::string& fromPath, const std::string& toPath) |
219 { | 211 { |
220 } | 212 } |
221 | 213 |
222 void Move(const std::string& fromPath, const std::string& toPath, | 214 void Move(const std::string& fromPath, const std::string& toPath, |
223 const Callback& callback) | 215 const Callback& callback) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 protected: | 311 protected: |
320 AdblockPlus::JsEnginePtr jsEngine; | 312 AdblockPlus::JsEnginePtr jsEngine; |
321 | 313 |
322 virtual void SetUp() | 314 virtual void SetUp() |
323 { | 315 { |
324 jsEngine = CreateJsEngine(); | 316 jsEngine = CreateJsEngine(); |
325 } | 317 } |
326 }; | 318 }; |
327 | 319 |
328 #endif | 320 #endif |
LEFT | RIGHT |