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

Unified Diff: src/FilterEngine.cpp

Issue 29377570: Issue 4931 - add possibility to not send data depending on connection properties (Closed)
Patch Set: address comment Created March 16, 2017, 2:38 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/prefs.js ('k') | src/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
diff --git a/src/FilterEngine.cpp b/src/FilterEngine.cpp
index fd4ff4d3634dbd141d13d847b36aea9910bcb5a9..e6d07db54177b77e52877c563dbf70724082d36c 100644
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -178,9 +178,27 @@ void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
{
FilterEnginePtr filterEngine(new FilterEngine(jsEngine));
auto sync = std::make_shared<Sync>();
- jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync](JsValueList& params)
+ auto isConnectionAllowedCallback = params.isConnectionAllowedCallback;
+ if (isConnectionAllowedCallback)
+ jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool
+ {
+ sync->Wait();
+ return jsEngine->IsConnectionAllowed();
+ });
+ jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](JsValueList& params)
{
filterEngine->firstRun = params.size() && params[0]->AsBool();
+ if (isConnectionAllowedCallback)
+ {
+ std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
+ jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAllowedCallback]()->bool
+ {
+ auto filterEngine = weakFilterEngine.lock();
+ if (!filterEngine)
+ return false;
+ return isConnectionAllowedCallback(filterEngine->GetAllowedConnectionType().get());
+ });
+ }
sync->Set();
onCreated(filterEngine);
jsEngine->RemoveEventCallback("_init");
@@ -427,7 +445,8 @@ void FilterEngine::SetPref(const std::string& pref, JsValuePtr value)
JsValuePtr func = jsEngine->Evaluate("API.setPref");
JsValueList params;
params.push_back(jsEngine->NewValue(pref));
- params.push_back(value);
+ if (value)
+ params.push_back(value);
func->Call(params);
}
@@ -494,6 +513,19 @@ void FilterEngine::RemoveFilterChangeCallback()
jsEngine->RemoveEventCallback("filterChange");
}
+void FilterEngine::SetAllowedConnectionType(const std::string* value)
+{
+ SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : nullptr);
+}
+
+std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType()
+{
+ auto prefValue = GetPref("allowed_connection_type");
+ if (prefValue->IsUndefined())
+ return nullptr;
+ return std::unique_ptr<std::string>(new std::string(prefValue->AsString()));
+}
+
void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, JsValueList& params)
{
std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
« no previous file with comments | « lib/prefs.js ('k') | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld