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

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 29731562: Issue 6477 - separate done and error callbacks in IFileSystem::Read (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git@c0a6434596a83383e37678ef3b6ecef00ed6a261
Patch Set: Created March 23, 2018, 10:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 } 195 }
196 } 196 }
197 197
198 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl) 198 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl)
199 : scheduler(scheduler), syncImpl(std::move(syncImpl)) 199 : scheduler(scheduler), syncImpl(std::move(syncImpl))
200 { 200 {
201 } 201 }
202 202
203 void DefaultFileSystem::Read(const std::string& fileName, 203 void DefaultFileSystem::Read(const std::string& fileName,
204 const ReadCallback& callback) const 204 const ReadCallback& doneCallback,
205 const Callback& errorCallback) const
205 { 206 {
206 scheduler([this, fileName, callback] 207 scheduler([this, fileName, doneCallback, errorCallback]
207 { 208 {
208 std::string error; 209 std::string error;
209 try 210 try
210 { 211 {
211 auto data = syncImpl->Read(Resolve(fileName)); 212 doneCallback(syncImpl->Read(Resolve(fileName)));
212 callback(std::move(data), error);
213 return; 213 return;
214 } 214 }
215 catch (std::exception& e) 215 catch (std::exception& e)
216 { 216 {
217 error = e.what(); 217 error = e.what();
218 } 218 }
219 catch (...) 219 catch (...)
220 { 220 {
221 error = "Unknown error while reading from " + fileName + " as " + Resolve (fileName); 221 error = "Unknown error while reading from " + fileName + " as " + Resolve (fileName);
222 } 222 }
223 callback(IOBuffer(), error); 223
224 try
225 {
226 errorCallback(error);
227 }
228 catch (...)
229 {
230 // there is no way to catch an exception thrown from the error callback.
231 }
224 }); 232 });
225 } 233 }
226 234
227 void DefaultFileSystem::Write(const std::string& fileName, 235 void DefaultFileSystem::Write(const std::string& fileName,
228 const IOBuffer& data, 236 const IOBuffer& data,
229 const Callback& callback) 237 const Callback& callback)
230 { 238 {
231 scheduler([this, fileName, data, callback] 239 scheduler([this, fileName, data, callback]
232 { 240 {
233 std::string error; 241 std::string error;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName); 321 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName);
314 } 322 }
315 callback(StatResult(), error); 323 callback(StatResult(), error);
316 }); 324 });
317 } 325 }
318 326
319 std::string DefaultFileSystem::Resolve(const std::string& fileName) const 327 std::string DefaultFileSystem::Resolve(const std::string& fileName) const
320 { 328 {
321 return syncImpl->Resolve(fileName); 329 return syncImpl->Resolve(fileName);
322 } 330 }
OLDNEW
« no previous file with comments | « src/DefaultFileSystem.h ('k') | src/FileSystemJsObject.cpp » ('j') | src/FileSystemJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld