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

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 29361582: Issue 4613 - fix leak of Thread (Closed)
Patch Set: Created Nov. 3, 2016, 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
« no previous file with comments | « no previous file | src/GlobalJsObject.cpp » ('j') | src/Thread.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus/FileSystem.h> 18 #include <AdblockPlus/FileSystem.h>
19 #include <stdexcept> 19 #include <stdexcept>
20 #include <sstream> 20 #include <sstream>
21 #include <vector> 21 #include <vector>
22 #include <thread>
sergei 2016/11/21 10:03:59 Sorry, overlooked, it's not used, so I won't inclu
22 23
23 #include <AdblockPlus/JsValue.h> 24 #include <AdblockPlus/JsValue.h>
24 #include "FileSystemJsObject.h" 25 #include "FileSystemJsObject.h"
25 #include "JsContext.h" 26 #include "JsContext.h"
26 #include "Thread.h" 27 #include "Thread.h"
27 #include "Utils.h" 28 #include "Utils.h"
28 29
29 using namespace AdblockPlus; 30 using namespace AdblockPlus;
30 31
31 namespace 32 namespace
32 { 33 {
33 class IoThread : public Thread 34 class IoThread : public Thread
34 { 35 {
35 public: 36 public:
36 IoThread(JsEnginePtr jsEngine, JsValuePtr callback) 37 IoThread(JsEnginePtr jsEngine, JsValuePtr callback)
37 : jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()), 38 : Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()),
38 callback(callback) 39 callback(callback)
39 { 40 {
40 } 41 }
41 42
42 protected: 43 protected:
43 JsEnginePtr jsEngine; 44 JsEnginePtr jsEngine;
44 FileSystemPtr fileSystem; 45 FileSystemPtr fileSystem;
45 JsValuePtr callback; 46 JsValuePtr callback;
46 }; 47 };
47 48
(...skipping 24 matching lines...) Expand all
72 error = "Unknown error while reading from " + path; 73 error = "Unknown error while reading from " + path;
73 } 74 }
74 75
75 const JsContext context(jsEngine); 76 const JsContext context(jsEngine);
76 JsValuePtr result = jsEngine->NewObject(); 77 JsValuePtr result = jsEngine->NewObject();
77 result->SetProperty("content", content); 78 result->SetProperty("content", content);
78 result->SetProperty("error", error); 79 result->SetProperty("error", error);
79 JsValueList params; 80 JsValueList params;
80 params.push_back(result); 81 params.push_back(result);
81 callback->Call(params); 82 callback->Call(params);
82 delete this;
83 } 83 }
84 84
85 private: 85 private:
86 std::string path; 86 std::string path;
87 }; 87 };
88 88
89 class WriteThread : public IoThread 89 class WriteThread : public IoThread
90 { 90 {
91 public: 91 public:
92 WriteThread(JsEnginePtr jsEngine, JsValuePtr callback, 92 WriteThread(JsEnginePtr jsEngine, JsValuePtr callback,
(...skipping 18 matching lines...) Expand all
111 catch (...) 111 catch (...)
112 { 112 {
113 error = "Unknown error while writing to " + path; 113 error = "Unknown error while writing to " + path;
114 } 114 }
115 115
116 const JsContext context(jsEngine); 116 const JsContext context(jsEngine);
117 JsValuePtr errorValue = jsEngine->NewValue(error); 117 JsValuePtr errorValue = jsEngine->NewValue(error);
118 JsValueList params; 118 JsValueList params;
119 params.push_back(errorValue); 119 params.push_back(errorValue);
120 callback->Call(params); 120 callback->Call(params);
121 delete this;
122 } 121 }
123 122
124 private: 123 private:
125 std::string path; 124 std::string path;
126 std::string content; 125 std::string content;
127 }; 126 };
128 127
129 class MoveThread : public IoThread 128 class MoveThread : public IoThread
130 { 129 {
131 public: 130 public:
(...skipping 17 matching lines...) Expand all
149 catch (...) 148 catch (...)
150 { 149 {
151 error = "Unknown error while moving " + fromPath + " to " + toPath; 150 error = "Unknown error while moving " + fromPath + " to " + toPath;
152 } 151 }
153 152
154 const JsContext context(jsEngine); 153 const JsContext context(jsEngine);
155 JsValuePtr errorValue = jsEngine->NewValue(error); 154 JsValuePtr errorValue = jsEngine->NewValue(error);
156 JsValueList params; 155 JsValueList params;
157 params.push_back(errorValue); 156 params.push_back(errorValue);
158 callback->Call(params); 157 callback->Call(params);
159 delete this;
160 } 158 }
161 159
162 private: 160 private:
163 std::string fromPath; 161 std::string fromPath;
164 std::string toPath; 162 std::string toPath;
165 }; 163 };
166 164
167 class RemoveThread : public IoThread 165 class RemoveThread : public IoThread
168 { 166 {
169 public: 167 public:
(...skipping 17 matching lines...) Expand all
187 catch (...) 185 catch (...)
188 { 186 {
189 error = "Unknown error while removing " + path; 187 error = "Unknown error while removing " + path;
190 } 188 }
191 189
192 const JsContext context(jsEngine); 190 const JsContext context(jsEngine);
193 JsValuePtr errorValue = jsEngine->NewValue(error); 191 JsValuePtr errorValue = jsEngine->NewValue(error);
194 JsValueList params; 192 JsValueList params;
195 params.push_back(errorValue); 193 params.push_back(errorValue);
196 callback->Call(params); 194 callback->Call(params);
197 delete this;
198 } 195 }
199 196
200 private: 197 private:
201 std::string path; 198 std::string path;
202 }; 199 };
203 200
204 201
205 class StatThread : public IoThread 202 class StatThread : public IoThread
206 { 203 {
207 public: 204 public:
(...skipping 24 matching lines...) Expand all
232 JsValuePtr result = jsEngine->NewObject(); 229 JsValuePtr result = jsEngine->NewObject();
233 result->SetProperty("exists", statResult.exists); 230 result->SetProperty("exists", statResult.exists);
234 result->SetProperty("isFile", statResult.isFile); 231 result->SetProperty("isFile", statResult.isFile);
235 result->SetProperty("isDirectory", statResult.isDirectory); 232 result->SetProperty("isDirectory", statResult.isDirectory);
236 result->SetProperty("lastModified", statResult.lastModified); 233 result->SetProperty("lastModified", statResult.lastModified);
237 result->SetProperty("error", error); 234 result->SetProperty("error", error);
238 235
239 JsValueList params; 236 JsValueList params;
240 params.push_back(result); 237 params.push_back(result);
241 callback->Call(params); 238 callback->Call(params);
242 delete this;
243 } 239 }
244 240
245 private: 241 private:
246 std::string path; 242 std::string path;
247 }; 243 };
248 244
249 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) 245 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments)
250 { 246 {
251 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 247 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
252 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 248 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 353 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
358 { 354 {
359 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 355 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
360 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 356 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
361 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 357 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
362 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 358 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
363 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 359 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
364 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); 360 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
365 return obj; 361 return obj;
366 } 362 }
OLDNEW
« no previous file with comments | « no previous file | src/GlobalJsObject.cpp » ('j') | src/Thread.cpp » ('J')

Powered by Google App Engine
This is Rietveld