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

Delta Between Two Patch Sets: src/plugin/AdblockPlusClient.cpp

Issue 11013110: Cleanup (Closed)
Left Patch Set: Refactoring CallAdblockPlusEngine Created July 24, 2013, 9:09 a.m.
Right Patch Set: More beautification and addressing comments Created July 29, 2013, 12:13 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/plugin/AdblockPlusClient.h ('k') | src/plugin/AdblockPlusTab.h » ('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 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginSettings.h" 3 #include "PluginSettings.h"
4 #include "PluginSystem.h" 4 #include "PluginSystem.h"
5 #include "PluginFilter.h" 5 #include "PluginFilter.h"
6 #include "PluginClientFactory.h" 6 #include "PluginClientFactory.h"
7 #include "PluginMutex.h" 7 #include "PluginMutex.h"
8 #include "PluginClass.h" 8 #include "PluginClass.h"
9 9
10 #include "AdblockPlusClient.h" 10 #include "AdblockPlusClient.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 description.title = ToUtf16String(title); 96 description.title = ToUtf16String(title);
97 std::string specialization; 97 std::string specialization;
98 message >> specialization; 98 message >> specialization;
99 description.specialization = ToUtf16String(specialization); 99 description.specialization = ToUtf16String(specialization);
100 message >> description.listed; 100 message >> description.listed;
101 result.push_back(description); 101 result.push_back(description);
102 } 102 }
103 return result; 103 return result;
104 } 104 }
105 105
106 bool CallEngine(Communication::OutputBuffer& message, Communication::InputBuff er* inputBuffer = NULL) 106 bool CallEngine(Communication::OutputBuffer& message, Communication::InputBuff er& inputBuffer = Communication::InputBuffer())
Felix Dahlke 2013/07/25 13:52:33 Since we always read the data anyway, I think we s
107 { 107 {
108 try 108 try
109 { 109 {
110 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); 110 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe();
111 pipe->WriteMessage(message); 111 pipe->WriteMessage(message);
112 if (inputBuffer != NULL) 112 inputBuffer = pipe->ReadMessage();
Felix Dahlke 2013/07/25 13:52:33 if (inputBuffer) does the same.
113 {
114 *inputBuffer = pipe->ReadMessage();
115 }
116 else
117 {
118 pipe->ReadMessage();
119 }
120 } 113 }
121 catch (const std::exception& e) 114 catch (const std::exception& e)
122 { 115 {
123 DEBUG_GENERAL(e.what()); 116 DEBUG_GENERAL(e.what());
124 return false; 117 return false;
125 } 118 }
126 return true; 119 return true;
127 } 120 }
128 121
129 bool CallEngine(Communication::ProcType proc, Communication::InputBuffer* inpu tBuffer = NULL) 122 bool CallEngine(Communication::ProcType proc, Communication::InputBuffer& inpu tBuffer = Communication::InputBuffer())
130 { 123 {
131 Communication::OutputBuffer message; 124 Communication::OutputBuffer message;
132 message << proc; 125 message << proc;
133 return CallEngine(message, inputBuffer); 126 return CallEngine(message, inputBuffer);
134 } 127 }
135 } 128 }
136 129
137 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 130 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
138 131
139 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() 132 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase()
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 m_criticalSectionFilter.Unlock(); 215 m_criticalSectionFilter.Unlock();
223 return isHidden; 216 return isHidden;
224 } 217 }
225 218
226 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) 219 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
227 { 220 {
228 Communication::OutputBuffer request; 221 Communication::OutputBuffer request;
229 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); 222 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);
230 223
231 Communication::InputBuffer response; 224 Communication::InputBuffer response;
232 if (!CallEngine(request, &response)) return false;; 225 if (!CallEngine(request, response))
Felix Dahlke 2013/07/25 13:52:33 One semicolon will do :)
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
226 return false;
233 227
234 bool isWhitelisted; 228 bool isWhitelisted;
235 response >> isWhitelisted; 229 response >> isWhitelisted;
236 return isWhitelisted; 230 return isWhitelisted;
237 } 231 }
238 232
239 int CAdblockPlusClient::GetIEVersion() 233 int CAdblockPlusClient::GetIEVersion()
240 { 234 {
241 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer 235 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
242 HKEY hKey; 236 HKEY hKey;
(...skipping 13 matching lines...) Expand all
256 RegCloseKey(hKey); 250 RegCloseKey(hKey);
257 return (int)(version[0] - 48); 251 return (int)(version[0] - 48);
258 } 252 }
259 253
260 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 254 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain)
261 { 255 {
262 Communication::OutputBuffer request; 256 Communication::OutputBuffer request;
263 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 257 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain);
264 258
265 Communication::InputBuffer response; 259 Communication::InputBuffer response;
266 if (!CallEngine(request, &response)) return false;; 260 if (!CallEngine(request, response))
Felix Dahlke 2013/07/25 13:52:33 As above, one semicolon will do.
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
261 return false;
267 262
268 bool match; 263 bool match;
269 response >> match; 264 response >> match;
270 return match; 265 return match;
271 } 266 }
272 267
273 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain) 268 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain)
274 { 269 {
275 Communication::OutputBuffer request; 270 Communication::OutputBuffer request;
276 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); 271 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain);
277 272
278 Communication::InputBuffer response; 273 Communication::InputBuffer response;
279 if (!CallEngine(request, &response)) return std::vector<std::wstring>(); 274 if (!CallEngine(request, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
275 return std::vector<std::wstring>();
280 return ReadStrings(response); 276 return ReadStrings(response);
281 } 277 }
282 278
283 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 279 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
284 { 280 {
285 Communication::InputBuffer response; 281 Communication::InputBuffer response;
286 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, &response)) retur n std::vector<SubscriptionDescription>(); 282 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
283 return std::vector<SubscriptionDescription>();
287 return ReadSubscriptions(response); 284 return ReadSubscriptions(response);
288 } 285 }
289 286
290 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( ) 287 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( )
291 { 288 {
292 Communication::InputBuffer response; 289 Communication::InputBuffer response;
293 if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, &response)) return s td::vector<SubscriptionDescription>(); 290 if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
291 return std::vector<SubscriptionDescription>();
294 return ReadSubscriptions(response); 292 return ReadSubscriptions(response);
295 } 293 }
296 294
297 void CAdblockPlusClient::SetSubscription(const std::wstring& url) 295 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
298 { 296 {
299 Communication::OutputBuffer request; 297 Communication::OutputBuffer request;
300 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); 298 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url);
301 CallEngine(request); 299 CallEngine(request);
302 } 300 }
303 301
304 void CAdblockPlusClient::UpdateAllSubscriptions() 302 void CAdblockPlusClient::UpdateAllSubscriptions()
305 { 303 {
306 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); 304 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
307 } 305 }
308 306
309 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() 307 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
310 { 308 {
311 Communication::InputBuffer response; 309 Communication::InputBuffer response;
312 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS)) return std::vector <std::wstring>(); 310 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
311 return std::vector<std::wstring>();
313 return ReadStrings(response); 312 return ReadStrings(response);
314 } 313 }
315 314
316 void CAdblockPlusClient::AddFilter(const std::wstring& text) 315 void CAdblockPlusClient::AddFilter(const std::wstring& text)
317 { 316 {
318 Communication::OutputBuffer request; 317 Communication::OutputBuffer request;
319 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); 318 request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
320 CallEngine(request); 319 CallEngine(request);
321 } 320 }
322 321
(...skipping 28 matching lines...) Expand all
351 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue) 350 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue)
352 { 351 {
353 return GetPref(name, std::wstring(defaultValue)); 352 return GetPref(name, std::wstring(defaultValue));
354 } 353 }
355 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue) 354 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue)
356 { 355 {
357 Communication::OutputBuffer request; 356 Communication::OutputBuffer request;
358 request << Communication::PROC_GET_PREF << ToUtf8String(name); 357 request << Communication::PROC_GET_PREF << ToUtf8String(name);
359 358
360 Communication::InputBuffer response; 359 Communication::InputBuffer response;
361 if (!CallEngine(request, &response)) return defaultValue; 360 if (!CallEngine(request, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
361 return defaultValue;
362 bool success; 362 bool success;
363 response >> success; 363 response >> success;
364 if (success) 364 if (success)
365 { 365 {
366 std::string value; 366 std::string value;
367 response >> value; 367 response >> value;
368 return ToUtf16String(value); 368 return ToUtf16String(value);
369 } 369 }
370 else 370 else
371 return defaultValue; 371 return defaultValue;
372 } 372 }
373 373
374 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) 374 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue)
375 { 375 {
376 Communication::OutputBuffer request; 376 Communication::OutputBuffer request;
377 request << Communication::PROC_GET_PREF << ToUtf8String(name); 377 request << Communication::PROC_GET_PREF << ToUtf8String(name);
378 378
379 Communication::InputBuffer response; 379 Communication::InputBuffer response;
380 if (!CallEngine(request, &response)) return defaultValue; 380 if (!CallEngine(request, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
381 return defaultValue;
381 bool success; 382 bool success;
382 response >> success; 383 response >> success;
383 if (success) 384 if (success)
384 { 385 {
385 bool value; 386 bool value;
386 response >> value; 387 response >> value;
387 return value; 388 return value;
388 } 389 }
389 else 390 else
390 return defaultValue; 391 return defaultValue;
391 } 392 }
392 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue) 393 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue)
393 { 394 {
394 Communication::OutputBuffer request; 395 Communication::OutputBuffer request;
395 request << Communication::PROC_GET_PREF << ToUtf8String(name); 396 request << Communication::PROC_GET_PREF << ToUtf8String(name);
396 397
397 Communication::InputBuffer response; 398 Communication::InputBuffer response;
398 if (!CallEngine(request, &response)) return defaultValue; 399 if (!CallEngine(request, response))
Wladimir Palant 2013/07/26 16:45:37 Style nit: please put the return statement on the
399 bool success; 400 return defaultValue;
Wladimir Palant 2013/07/26 16:45:37 Wrong indentation?
401 bool success;
400 response >> success; 402 response >> success;
401 if (success) 403 if (success)
402 { 404 {
403 int64_t value; 405 int64_t value;
404 response >> value; 406 response >> value;
405 return value; 407 return value;
406 } 408 }
407 else 409 else
408 return defaultValue; 410 return defaultValue;
409 } 411 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld