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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29377064: Issue 4944 - Make creation of FilterEngine asynchronous. (Closed)
Left Patch Set: Created Feb. 28, 2017, 2:21 p.m.
Right Patch Set: rebase and address comments Created March 16, 2017, 3:47 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 | « shell/src/Main.cpp ('k') | test/FilterEngine.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-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
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 }; 167 };
168 } 168 }
169 169
170 FilterEngine::FilterEngine(const JsEnginePtr& jsEngine) 170 FilterEngine::FilterEngine(const JsEnginePtr& jsEngine)
171 : jsEngine(jsEngine), firstRun(false), updateCheckId(0) 171 : jsEngine(jsEngine), firstRun(false), updateCheckId(0)
172 { 172 {
173 } 173 }
174 174
175 void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine, 175 void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
176 const FilterEngine::OnCreatedCallback& onCreated, 176 const FilterEngine::OnCreatedCallback& onCreated,
177 const FilterEngine::CreateParameters& params) 177 const FilterEngine::CreationParameters& params)
178 { 178 {
179 FilterEnginePtr filterEngine(new FilterEngine(jsEngine)); 179 FilterEnginePtr filterEngine(new FilterEngine(jsEngine));
180 auto sync = std::make_shared<Sync>(); 180 auto sync = std::make_shared<Sync>();
181 jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync]( JsValueList& params) 181 jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync]( JsValueList& params)
182 { 182 {
183 filterEngine->firstRun = params.size() && params[0]->AsBool(); 183 filterEngine->firstRun = params.size() && params[0]->AsBool();
184 sync->Set(); 184 sync->Set();
185 onCreated(filterEngine); 185 onCreated(filterEngine);
186 jsEngine->RemoveEventCallback("_init"); 186 jsEngine->RemoveEventCallback("_init");
187 }); 187 });
188 188
189 // Lock the JS engine while we are loading scripts, no timeouts should fire 189 // Lock the JS engine while we are loading scripts, no timeouts should fire
190 // until we are done. 190 // until we are done.
191 const JsContext context(jsEngine); 191 const JsContext context(jsEngine);
192 192
193 // Set the preconfigured prefs 193 // Set the preconfigured prefs
194 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject(); 194 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject();
195 for (FilterEngine::Prefs::const_iterator it = params.preconfiguredPrefs.begin( ); 195 for (FilterEngine::Prefs::const_iterator it = params.preconfiguredPrefs.begin( );
196 it != params.preconfiguredPrefs.end(); it++) 196 it != params.preconfiguredPrefs.end(); it++)
197 { 197 {
198 preconfiguredPrefsObject->SetProperty(it->first, it->second); 198 preconfiguredPrefsObject->SetProperty(it->first, it->second);
199 } 199 }
200 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject); 200 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject);
201 // Load adblockplus scripts 201 // Load adblockplus scripts
202 for (int i = 0; !jsSources[i].empty(); i += 2) 202 for (int i = 0; !jsSources[i].empty(); i += 2)
203 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); 203 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
204 } 204 }
205 205
206 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine, 206 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine,
207 const FilterEngine::CreateParameters& params) 207 const FilterEngine::CreationParameters& params)
208 { 208 {
209 FilterEnginePtr retValue; 209 FilterEnginePtr retValue;
210 Sync sync; 210 Sync sync;
211 CreateAsync(jsEngine, [&retValue, &sync](const FilterEnginePtr& filterEngine) 211 CreateAsync(jsEngine, [&retValue, &sync](const FilterEnginePtr& filterEngine)
212 { 212 {
213 retValue = filterEngine; 213 retValue = filterEngine;
214 sync.Set(); 214 sync.Set();
215 }, params); 215 }, params);
216 sync.Wait(); 216 sync.Wait();
217 return retValue; 217 return retValue;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 552 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
553 if (filter) 553 if (filter)
554 { 554 {
555 return filter; 555 return filter;
556 } 556 }
557 currentUrl = parentUrl; 557 currentUrl = parentUrl;
558 } 558 }
559 while (urlIterator != documentUrls.end()); 559 while (urlIterator != documentUrls.end());
560 return FilterPtr(); 560 return FilterPtr();
561 } 561 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld