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

Unified Diff: src/JsEngine.cpp

Issue 29377570: Issue 4931 - add possibility to not send data depending on connection properties (Closed)
Patch Set: Created Feb. 28, 2017, 2:22 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/JsEngine.cpp
diff --git a/src/JsEngine.cpp b/src/JsEngine.cpp
index 2fc5159ccaa6138dc7738c52d52971347b71a3ca..ff7439a6483a5d16ec7872563573bc9ff5d17173 100644
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -228,6 +228,26 @@ void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val)
webRequest = val;
}
+void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callback)
+{
+ const JsLocker lock(shared_from_this());
+ isConnectionAllowed = callback;
+}
+
+bool AdblockPlus::JsEngine::IsConnectionAllowed()
+{
+ // The call of isConnectionAllowed can be very expensive and it makes a
+ // little sense to block execution of JavaScript for it. Currently this
+ // method is called from a thread of web request, so let only this thread be
+ // blocked by the call of the callback.
+ IsConnectionAllowedCallback localCopy;
+ {
+ const JsLocker lock(shared_from_this());
+ localCopy = isConnectionAllowed;
+ }
+ return !localCopy || localCopy();
+}
+
AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem()
{
if (!logSystem)
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/WebRequestJsObject.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld