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

Unified Diff: src/FilterEngine.cpp

Issue 29435650: Issue 5182, 4688 - improve IsSubscriptionDowloadAllowedCallback and corresponding tests (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 10, 2017, 4:55 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
Index: src/FilterEngine.cpp
diff --git a/src/FilterEngine.cpp b/src/FilterEngine.cpp
index efd72dc861e2434f568d99104bebe0ecf1425338..19a045e7169216533beb3b4cccaf7c965e2724cb 100644
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -225,8 +225,8 @@ void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
// TODO: replace weakFilterEngine by this when it's possible to control the
// execution time of the asynchronous part below.
std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
- auto isConnectionAllowedCallback = params.isConnectionAllowedCallback;
- jsEngine->SetEventCallback("_isSubscriptionDownloadAllowed", [weakFilterEngine, isConnectionAllowedCallback](JsValueList&& params){
+ auto isSubscriptionDowloadAllowedCallback = params.isSubscriptionDowloadAllowedCallback;
+ jsEngine->SetEventCallback("_isSubscriptionDownloadAllowed", [weakFilterEngine, isSubscriptionDowloadAllowedCallback](JsValueList&& params){
auto filterEngine = weakFilterEngine.lock();
if (!filterEngine)
return;
@@ -238,7 +238,7 @@ void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
assert(areArgumentsValid && "Invalid argument: there should be two args and the second one should be a function");
if (!areArgumentsValid)
return;
- if (!isConnectionAllowedCallback)
+ if (!isSubscriptionDowloadAllowedCallback)
{
params[1].Call(jsEngine->NewValue(true));
return;
@@ -253,12 +253,8 @@ void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
auto jsParams = jsEngine->TakeJsValues(valuesID);
jsParams[1].Call(jsEngine->NewValue(isAllowed));
};
- std::shared_ptr<std::string> allowedConnectionType = params[0].IsString() ? std::make_shared<std::string>(params[0].AsString()) : nullptr;
- // temporary hack with thread:
- std::thread([isConnectionAllowedCallback, allowedConnectionType, callJsCallback]
- {
- callJsCallback(isConnectionAllowedCallback(allowedConnectionType.get()));
- }).detach();
+ std::string allowedConnectionType = params[0].IsString() ? params[0].AsString() : std::string();
+ isSubscriptionDowloadAllowedCallback(params[0].IsString() ? &allowedConnectionType : nullptr, callJsCallback);
});
}
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | test/BaseJsTest.h » ('j') | test/FilterEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld