| OLD | NEW | 
|---|
| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 101   void operator()(LogLevel logLevel, const std::string& message, | 101   void operator()(LogLevel logLevel, const std::string& message, | 
| 102         const std::string& source) | 102         const std::string& source) | 
| 103   { | 103   { | 
| 104     throw std::runtime_error("Unexpected error: " + message); | 104     throw std::runtime_error("Unexpected error: " + message); | 
| 105   } | 105   } | 
| 106 }; | 106 }; | 
| 107 | 107 | 
| 108 class ThrowingFileSystem : public AdblockPlus::IFileSystem | 108 class ThrowingFileSystem : public AdblockPlus::IFileSystem | 
| 109 { | 109 { | 
| 110 public: | 110 public: | 
| 111   void Read(const std::string& path, const ReadCallback& callback) const overrid
     e | 111   void Read(const std::string& fileName, const ReadCallback& callback) const ove
     rride | 
| 112   { | 112   { | 
| 113     throw std::runtime_error("Not implemented"); | 113     throw std::runtime_error("Not implemented"); | 
| 114   } | 114   } | 
| 115 | 115 | 
| 116   void Write(const std::string& path, const IOBuffer& data, | 116   void Write(const std::string& fileName, const IOBuffer& data, | 
| 117     const Callback& callback) override | 117     const Callback& callback) override | 
| 118   { | 118   { | 
| 119     throw std::runtime_error("Not implemented"); | 119     throw std::runtime_error("Not implemented"); | 
| 120   } | 120   } | 
| 121 | 121 | 
| 122   void Move(const std::string& fromPath, const std::string& toPath, | 122   void Move(const std::string& fromFileName, const std::string& toFileName, | 
| 123             const Callback& callback) override | 123             const Callback& callback) override | 
| 124   { | 124   { | 
| 125     throw std::runtime_error("Not implemented"); | 125     throw std::runtime_error("Not implemented"); | 
| 126   } | 126   } | 
| 127 | 127 | 
| 128   void Remove(const std::string& path, const Callback& callback) override | 128   void Remove(const std::string& fileName, const Callback& callback) override | 
| 129   { | 129   { | 
| 130     throw std::runtime_error("Not implemented"); | 130     throw std::runtime_error("Not implemented"); | 
| 131   } | 131   } | 
| 132 | 132 | 
| 133   void Stat(const std::string& path, const StatCallback& callback) const overrid
     e | 133   void Stat(const std::string& fileName, const StatCallback& callback) const ove
     rride | 
| 134   { | 134   { | 
| 135     throw std::runtime_error("Not implemented"); | 135     throw std::runtime_error("Not implemented"); | 
| 136   } | 136   } | 
| 137 |  | 
| 138   std::string Resolve(const std::string& path) const override |  | 
| 139   { |  | 
| 140     throw std::runtime_error("Not implemented"); |  | 
| 141   } |  | 
| 142 }; | 137 }; | 
| 143 | 138 | 
| 144 class ThrowingWebRequest : public AdblockPlus::IWebRequest | 139 class ThrowingWebRequest : public AdblockPlus::IWebRequest | 
| 145 { | 140 { | 
| 146 public: | 141 public: | 
| 147   void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders
     , const GetCallback&) override | 142   void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders
     , const GetCallback&) override | 
| 148   { | 143   { | 
| 149     throw std::runtime_error("Unexpected GET: " + url); | 144     throw std::runtime_error("Unexpected GET: " + url); | 
| 150   } | 145   } | 
| 151 }; | 146 }; | 
| 152 | 147 | 
| 153 class LazyFileSystem : public AdblockPlus::IFileSystem | 148 class LazyFileSystem : public AdblockPlus::IFileSystem | 
| 154 { | 149 { | 
| 155 public: | 150 public: | 
| 156   typedef std::function<void()> Task; | 151   typedef std::function<void()> Task; | 
| 157   typedef std::function<void(const Task& task)> Scheduler; | 152   typedef std::function<void(const Task& task)> Scheduler; | 
| 158   static void ExecuteImmediately(const Task& task) | 153   static void ExecuteImmediately(const Task& task) | 
| 159   { | 154   { | 
| 160     if (task) | 155     if (task) | 
| 161       task(); | 156       task(); | 
| 162   } | 157   } | 
| 163   explicit LazyFileSystem(const Scheduler& scheduler = LazyFileSystem::ExecuteIm
     mediately) | 158   explicit LazyFileSystem(const Scheduler& scheduler = LazyFileSystem::ExecuteIm
     mediately) | 
| 164     : scheduler(scheduler) | 159     : scheduler(scheduler) | 
| 165   { | 160   { | 
| 166   } | 161   } | 
| 167 | 162 | 
| 168   void Read(const std::string& path, const ReadCallback& callback) const overrid
     e | 163   void Read(const std::string& fileName, const ReadCallback& callback) const ove
     rride | 
| 169   { | 164   { | 
| 170     scheduler([path, callback] | 165     scheduler([fileName, callback] | 
| 171     { | 166     { | 
| 172       if (path == "patterns.ini") | 167       if (fileName == "patterns.ini") | 
| 173       { | 168       { | 
| 174         std::string dummyData = "# Adblock Plus preferences\n[Subscription]\nurl
     =~fl~"; | 169         std::string dummyData = "# Adblock Plus preferences\n[Subscription]\nurl
     =~user~0000"; | 
| 175         callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), ""); | 170         callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), ""); | 
| 176       } | 171       } | 
| 177       else if (path == "prefs.json") | 172       else if (fileName == "prefs.json") | 
| 178       { | 173       { | 
| 179         std::string dummyData = "{}"; | 174         std::string dummyData = "{}"; | 
| 180         callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), ""); | 175         callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), ""); | 
| 181       } | 176       } | 
| 182     }); | 177     }); | 
| 183   } | 178   } | 
| 184 | 179 | 
| 185   void Write(const std::string& path, const IOBuffer& data, | 180   void Write(const std::string& fileName, const IOBuffer& data, | 
| 186              const Callback& callback) override | 181              const Callback& callback) override | 
| 187   { | 182   { | 
| 188   } | 183   } | 
| 189 | 184 | 
| 190 | 185 | 
| 191   void Move(const std::string& fromPath, const std::string& toPath, | 186   void Move(const std::string& fromFileName, const std::string& toFileName, | 
| 192             const Callback& callback) override | 187             const Callback& callback) override | 
| 193   { | 188   { | 
| 194   } | 189   } | 
| 195 | 190 | 
| 196   void Remove(const std::string& path, const Callback& callback) override | 191   void Remove(const std::string& fileName, const Callback& callback) override | 
| 197   { | 192   { | 
| 198   } | 193   } | 
| 199 | 194 | 
| 200   void Stat(const std::string& path, const StatCallback& callback) const overrid
     e | 195   void Stat(const std::string& fileName, const StatCallback& callback) const ove
     rride | 
| 201   { | 196   { | 
| 202     scheduler([path, callback] | 197     scheduler([fileName, callback] | 
| 203     { | 198     { | 
| 204       StatResult result; | 199       StatResult result; | 
| 205       if (path == "patterns.ini") | 200       if (fileName == "patterns.ini") | 
| 206       { | 201       { | 
| 207         result.exists = true; | 202         result.exists = true; | 
| 208         result.isFile = true; |  | 
| 209       } | 203       } | 
| 210       callback(result, ""); | 204       callback(result, ""); | 
| 211     }); | 205     }); | 
| 212   } | 206   } | 
| 213 |  | 
| 214   std::string Resolve(const std::string& path) const override |  | 
| 215   { |  | 
| 216     return path; |  | 
| 217   } |  | 
| 218 public: | 207 public: | 
| 219   Scheduler scheduler; | 208   Scheduler scheduler; | 
| 220 }; | 209 }; | 
| 221 | 210 | 
| 222 AdblockPlus::FilterEngine& CreateFilterEngine(LazyFileSystem& fileSystem, | 211 AdblockPlus::FilterEngine& CreateFilterEngine(LazyFileSystem& fileSystem, | 
| 223   AdblockPlus::Platform& platform, | 212   AdblockPlus::Platform& platform, | 
| 224   const AdblockPlus::FilterEngine::CreationParameters& creationParams = AdblockP
     lus::FilterEngine::CreationParameters()); | 213   const AdblockPlus::FilterEngine::CreationParameters& creationParams = AdblockP
     lus::FilterEngine::CreationParameters()); | 
| 225 | 214 | 
| 226 class NoopWebRequest : public AdblockPlus::IWebRequest | 215 class NoopWebRequest : public AdblockPlus::IWebRequest | 
| 227 { | 216 { | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 280   } | 269   } | 
| 281 | 270 | 
| 282   void TearDown() override | 271   void TearDown() override | 
| 283   { | 272   { | 
| 284     if (platform) | 273     if (platform) | 
| 285       platform.reset(); | 274       platform.reset(); | 
| 286   } | 275   } | 
| 287 }; | 276 }; | 
| 288 | 277 | 
| 289 #endif | 278 #endif | 
| OLD | NEW | 
|---|