Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/BaseJsTest.h

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Updated patch after review. Created June 16, 2017, 9:52 p.m.
Right Patch Set: Rebase on master. Last changes. Created July 7, 2017, 1:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/Utils.cpp ('k') | test/BaseJsTest.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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::istream& 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::string& 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
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 result = Read(path); 191 auto data = Read(path);
192 std::stringstream stream; 192 callback(std::move(data), "");
193 stream << result->rdbuf(); 193 }).detach();
194 std::string content = stream.str(); 194 }
195 callback(std::move(content), ""); 195
196 }).detach(); 196 void Write(const std::string& path, const IOBuffer& content)
197 } 197 {
198 198 }
199 void Write(const std::string& path, std::istream& content) 199
200 { 200 void Write(const std::string& path, const IOBuffer& data,
201 }
202
203 void Write(const std::string& path, const std::string& data,
204 const Callback& callback) 201 const Callback& callback)
205 { 202 {
206 std::thread([this, path, data, callback] 203 std::thread([this, path, data, callback]
207 { 204 {
208 std::stringstream stream; 205 Write(path, data);
209 stream << data;
210 Write(path, stream);
211 callback(""); 206 callback("");
212 }).detach(); 207 }).detach();
213 } 208 }
214 209
215 void Move(const std::string& fromPath, const std::string& toPath) 210 void Move(const std::string& fromPath, const std::string& toPath)
216 { 211 {
217 } 212 }
218 213
219 void Move(const std::string& fromPath, const std::string& toPath, 214 void Move(const std::string& fromPath, const std::string& toPath,
220 const Callback& callback) 215 const Callback& callback)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 protected: 311 protected:
317 AdblockPlus::JsEnginePtr jsEngine; 312 AdblockPlus::JsEnginePtr jsEngine;
318 313
319 virtual void SetUp() 314 virtual void SetUp()
320 { 315 {
321 jsEngine = CreateJsEngine(); 316 jsEngine = CreateJsEngine();
322 } 317 }
323 }; 318 };
324 319
325 #endif 320 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld