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

Unified Diff: src/FilterEngine.cpp

Issue 10800079: Implemented update checking functionality (Closed)
Patch Set: Created June 5, 2013, 6:47 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 | « libadblockplus.gyp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
===================================================================
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -130,17 +130,17 @@ bool Subscription::IsUpdating()
}
bool Subscription::operator==(const Subscription& subscription) const
{
return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsString();
}
FilterEngine::FilterEngine(JsEnginePtr jsEngine)
- : jsEngine(jsEngine), initialized(false), firstRun(false)
+ : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0)
{
jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone,
this, std::tr1::placeholders::_1));
{
// Lock the JS engine while we are loading scripts, no timeouts should fire
// until we are done.
const JsContext context(jsEngine);
@@ -250,8 +250,30 @@ JsValuePtr FilterEngine::GetPref(const s
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);
func->Call(params);
}
+
+void FilterEngine::ForceUpdateCheck(FilterEngine::UpdaterCallback callback)
+{
+ std::string eventName = "updateCheckDone";
+ eventName += ++updateCheckId;
+
+ jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateCheckDone,
+ this, eventName, callback, std::tr1::placeholders::_1));
+
+ JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck");
+ JsValueList params;
+ params.push_back(jsEngine->NewValue(eventName));
+ func->Call(params);
+}
+
+void FilterEngine::UpdateCheckDone(const std::string& eventName, FilterEngine::UpdaterCallback callback, JsValueList& params)
+{
+ jsEngine->RemoveEventCallback(eventName);
+
+ std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
+ callback(error);
+}
« no previous file with comments | « libadblockplus.gyp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld