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

Unified Diff: src/FilterEngine.cpp

Issue 10420020: Made sure FilterEngine instances are always initialized (Closed)
Patch Set: Created May 16, 2013, 2:27 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/init.js ('k') | src/GlobalJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
===================================================================
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -16,16 +16,17 @@
*/
#include <algorithm>
#include <cctype>
#include <functional>
#include <string>
#include <AdblockPlus.h>
+#include "Thread.h"
using namespace AdblockPlus;
extern std::string jsSources[];
Filter::Filter(JsValuePtr value)
: JsValue(value)
{
@@ -127,25 +128,31 @@ bool Subscription::IsUpdating()
return result->AsBool();
}
bool Subscription::operator==(const Subscription& subscription) const
{
return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsString();
}
-FilterEngine::FilterEngine(JsEnginePtr jsEngine) : jsEngine(jsEngine)
+FilterEngine::FilterEngine(JsEnginePtr jsEngine)
+ : jsEngine(jsEngine), initialized(false)
{
+ jsEngine->SetInitCallback(std::tr1::bind(&FilterEngine::InitDone, this));
for (int i = 0; !jsSources[i].empty(); i += 2)
jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
+
+ // TODO: This should really be implemented via a conditional variable
+ while (!initialized)
+ ::Sleep(10);
}
-bool FilterEngine::IsInitialized() const
+void FilterEngine::InitDone()
{
- return jsEngine->Evaluate("_abpInitialized")->AsBool();
+ initialized = true;
}
FilterPtr FilterEngine::GetFilter(const std::string& text)
{
JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText");
JsValueList params;
params.push_back(jsEngine->NewValue(text));
return FilterPtr(new Filter(func->Call(params)));
« no previous file with comments | « lib/init.js ('k') | src/GlobalJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld