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

Delta Between Two Patch Sets: src/JsEngine.cpp

Issue 29377570: Issue 4931 - add possibility to not send data depending on connection properties (Closed)
Left Patch Set: Created Feb. 28, 2017, 2:22 p.m.
Right Patch Set: rebase Created March 16, 2017, 4:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/FilterEngine.cpp ('k') | src/WebRequestJsObject.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val) 223 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val)
224 { 224 {
225 if (!val) 225 if (!val)
226 throw std::runtime_error("WebRequest cannot be null"); 226 throw std::runtime_error("WebRequest cannot be null");
227 227
228 webRequest = val; 228 webRequest = val;
229 } 229 }
230 230
231 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll owedCallback& callback) 231 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll owedCallback& callback)
232 { 232 {
233 const JsLocker lock(shared_from_this()); 233 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
234 isConnectionAllowed = callback; 234 isConnectionAllowed = callback;
235 } 235 }
236 236
237 bool AdblockPlus::JsEngine::IsConnectionAllowed() 237 bool AdblockPlus::JsEngine::IsConnectionAllowed()
238 { 238 {
239 // The call of isConnectionAllowed can be very expensive and it makes a 239 // The call of isConnectionAllowed can be very expensive and it makes a
240 // little sense to block execution of JavaScript for it. Currently this 240 // little sense to block execution of JavaScript for it. Currently this
241 // method is called from a thread of web request, so let only this thread be 241 // method is called from a thread of web request, so let only this thread be
242 // blocked by the call of the callback. 242 // blocked by the call of the callback.
243 IsConnectionAllowedCallback localCopy; 243 IsConnectionAllowedCallback localCopy;
244 { 244 {
245 const JsLocker lock(shared_from_this()); 245 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
246 localCopy = isConnectionAllowed; 246 localCopy = isConnectionAllowed;
247 } 247 }
248 return !localCopy || localCopy(); 248 return !localCopy || localCopy();
249 } 249 }
250 250
251 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() 251 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem()
252 { 252 {
253 if (!logSystem) 253 if (!logSystem)
254 logSystem.reset(new DefaultLogSystem()); 254 logSystem.reset(new DefaultLogSystem());
255 return logSystem; 255 return logSystem;
256 } 256 }
257 257
258 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) 258 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
259 { 259 {
260 if (!val) 260 if (!val)
261 throw std::runtime_error("LogSystem cannot be null"); 261 throw std::runtime_error("LogSystem cannot be null");
262 262
263 logSystem = val; 263 logSystem = val;
264 } 264 }
265 265
266 266
267 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 267 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
268 AdblockPlus::JsValuePtr value) 268 AdblockPlus::JsValuePtr value)
269 { 269 {
270 auto global = GetGlobalObject(); 270 auto global = GetGlobalObject();
271 if (!global) 271 if (!global)
272 throw std::runtime_error("Global object cannot be null"); 272 throw std::runtime_error("Global object cannot be null");
273 global->SetProperty(name, value); 273 global->SetProperty(name, value);
274 } 274 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld