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

Unified Diff: src/FilterEngine.cpp

Issue 29409580: Issue 5013 - Make parameter const ref when applicable. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 11, 2017, 1:58 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
===================================================================
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -168,17 +168,17 @@
auto sync = std::make_shared<Sync>();
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)
+ jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](const 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();
@@ -427,47 +427,47 @@
}
JsValuePtr FilterEngine::GetPref(const std::string& pref) const
{
JsValuePtr func = jsEngine->Evaluate("API.getPref");
return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref)));
}
-void FilterEngine::SetPref(const std::string& pref, JsValuePtr value)
+void FilterEngine::SetPref(const std::string& pref, const JsValuePtr& value)
{
JsValuePtr func = jsEngine->Evaluate("API.setPref");
JsConstValueList params;
params.push_back(jsEngine->NewValue(pref));
if (value)
params.push_back(value);
func->Call(params);
}
std::string FilterEngine::GetHostFromURL(const std::string& url) const
{
JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl");
return func->Call(*jsEngine->NewValue(url)).AsString();
}
void FilterEngine::SetUpdateAvailableCallback(
- FilterEngine::UpdateAvailableCallback callback)
+ const FilterEngine::UpdateAvailableCallback& callback)
{
jsEngine->SetEventCallback("updateAvailable",
std::bind(&FilterEngine::UpdateAvailable, this, callback,
std::placeholders::_1));
}
void FilterEngine::RemoveUpdateAvailableCallback()
{
jsEngine->RemoveEventCallback("updateAvailable");
}
void FilterEngine::UpdateAvailable(
- FilterEngine::UpdateAvailableCallback callback, JsValueList& params) const
+ const FilterEngine::UpdateAvailableCallback& callback, const JsValueList& params) const
{
if (params.size() >= 1 && !params[0]->IsNull())
callback(params[0]->AsString());
}
void FilterEngine::ForceUpdateCheck(
const FilterEngine::UpdateCheckDoneCallback& callback)
{
@@ -479,25 +479,25 @@
jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone,
this, eventName, callback, std::placeholders::_1));
params.push_back(jsEngine->NewValue(eventName));
}
func->Call(params);
}
void FilterEngine::UpdateCheckDone(const std::string& eventName,
- FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params)
+ const FilterEngine::UpdateCheckDoneCallback& callback, const JsValueList& params)
{
jsEngine->RemoveEventCallback(eventName);
std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
callback(error);
}
-void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback callback)
+void FilterEngine::SetFilterChangeCallback(const FilterEngine::FilterChangeCallback& callback)
{
jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChanged,
this, callback, std::placeholders::_1));
}
void FilterEngine::RemoveFilterChangeCallback()
{
jsEngine->RemoveEventCallback("filterChange");
@@ -511,17 +511,17 @@
std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const
{
auto prefValue = GetPref("allowed_connection_type");
if (prefValue->AsString().empty())
return nullptr;
return std::unique_ptr<std::string>(new std::string(prefValue->AsString()));
}
-void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, JsValueList& params) const
+void FilterEngine::FilterChanged(const FilterEngine::FilterChangeCallback& callback, const JsValueList& params) const
{
std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
callback(action, item);
}
void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
const JsValueList& params) const

Powered by Google App Engine
This is Rietveld