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: Created Feb. 28, 2017, 10:21 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..87a4d4dfd60ff43a142411116bff42e47a4af868 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 isConnectionAllowed = params.isConnectionAllowed;
Oleksandr 2017/03/16 14:19:53 The naming here is highly confusing, IMO. How abou
sergei 2017/03/16 16:25:22 No objections, fixed.
+ if (isConnectionAllowed)
+ jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool
+ {
+ sync->Wait();
+ return jsEngine->IsConnectionAllowed();
+ });
+ jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowed](JsValueList& params)
{
filterEngine->firstRun = params.size() && params[0]->AsBool();
+ if (isConnectionAllowed)
+ {
+ std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
+ jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAllowed]()->bool
+ {
+ auto filterEngine = weakFilterEngine.lock();
+ if (!filterEngine)
+ return false;
+ return isConnectionAllowed(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)
Oleksandr 2017/03/16 14:19:53 Nit: this doesn't look related, is it?
sergei 2017/03/16 16:25:22 It's related, now we can call SetPref(nullptr) and
+ 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