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

Side by Side Diff: src/FilterEngine.cpp

Issue 5163715573841920: Issue 768 - Switch from TR1 to C++11 (Closed)
Patch Set: Created July 11, 2014, 2:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 bool Subscription::operator==(const Subscription& subscription) const 132 bool Subscription::operator==(const Subscription& subscription) const
133 { 133 {
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); 134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring();
135 } 135 }
136 136
137 FilterEngine::FilterEngine(JsEnginePtr jsEngine) 137 FilterEngine::FilterEngine(JsEnginePtr jsEngine)
138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) 138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0)
139 { 139 {
140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, 140 jsEngine->SetEventCallback("init", std::bind(&FilterEngine::InitDone,
141 this, std::tr1::placeholders::_1)); 141 this, std::placeholders::_1));
142 142
143 { 143 {
144 // Lock the JS engine while we are loading scripts, no timeouts should fire 144 // Lock the JS engine while we are loading scripts, no timeouts should fire
145 // until we are done. 145 // until we are done.
146 const JsContext context(jsEngine); 146 const JsContext context(jsEngine);
147 for (int i = 0; !jsSources[i].empty(); i += 2) 147 for (int i = 0; !jsSources[i].empty(); i += 2)
148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); 148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
149 } 149 }
150 150
151 // TODO: This should really be implemented via a conditional variable 151 // TODO: This should really be implemented via a conditional variable
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 params.push_back(jsEngine->NewValue(url)); 293 params.push_back(jsEngine->NewValue(url));
294 return func->Call(params)->AsString(); 294 return func->Call(params)->AsString();
295 } 295 }
296 296
297 297
298 void FilterEngine::ForceUpdateCheck(FilterEngine::UpdaterCallback callback) 298 void FilterEngine::ForceUpdateCheck(FilterEngine::UpdaterCallback callback)
299 { 299 {
300 std::string eventName = "updateCheckDone"; 300 std::string eventName = "updateCheckDone";
301 eventName += ++updateCheckId; 301 eventName += ++updateCheckId;
302 302
303 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, 303 jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone ,
304 this, eventName, callback, std::tr1::placeholders::_1)); 304 this, eventName, callback, std::placeholders::_1));
305 305
306 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); 306 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck");
307 JsValueList params; 307 JsValueList params;
308 params.push_back(jsEngine->NewValue(eventName)); 308 params.push_back(jsEngine->NewValue(eventName));
309 func->Call(params); 309 func->Call(params);
310 } 310 }
311 311
312 void FilterEngine::UpdateCheckDone(const std::string& eventName, FilterEngine::U pdaterCallback callback, JsValueList& params) 312 void FilterEngine::UpdateCheckDone(const std::string& eventName, FilterEngine::U pdaterCallback callback, JsValueList& params)
313 { 313 {
314 jsEngine->RemoveEventCallback(eventName); 314 jsEngine->RemoveEventCallback(eventName);
315 315
316 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); 316 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : "");
317 callback(error); 317 callback(error);
318 } 318 }
319 319
320 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) 320 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback)
321 { 321 {
322 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged, 322 jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChan ged,
323 this, callback, std::tr1::placeholders::_1)); 323 this, callback, std::placeholders::_1));
324 } 324 }
325 325
326 void FilterEngine::RemoveFilterChangeCallback() 326 void FilterEngine::RemoveFilterChangeCallback()
327 { 327 {
328 jsEngine->RemoveEventCallback("filterChange"); 328 jsEngine->RemoveEventCallback("filterChange");
329 } 329 }
330 330
331 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) 331 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params)
332 { 332 {
333 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); 333 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : "");
334 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); 334 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
335 callback(action, item); 335 callback(action, item);
336 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld