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

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 10874009: Use a proper enum type for procedures that can be called (Closed)
Patch Set: Created June 3, 2013, 1:53 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 #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 "PluginDictionary.h" 7 #include "PluginDictionary.h"
8 #include "PluginHttpRequest.h" 8 #include "PluginHttpRequest.h"
9 #include "PluginMutex.h" 9 #include "PluginMutex.h"
10 #include "PluginClass.h" 10 #include "PluginClass.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return (int)(version[0] - 48); 234 return (int)(version[0] - 48);
235 } 235 }
236 236
237 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB uffer& message) 237 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB uffer& message)
238 { 238 {
239 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); 239 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe();
240 pipe->WriteMessage(message); 240 pipe->WriteMessage(message);
241 return pipe->ReadMessage(); 241 return pipe->ReadMessage();
242 } 242 }
243 243
244 Communication::InputBuffer CallAdblockPlusEngineProcedure(const std::string& pro c) 244 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::ProcTyp e proc)
245 { 245 {
246 Communication::OutputBuffer message; 246 Communication::OutputBuffer message;
247 message << proc; 247 message << proc;
248 return CallAdblockPlusEngineProcedure(message); 248 return CallAdblockPlusEngineProcedure(message);
249 } 249 }
250 250
251 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain) 251 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain)
252 { 252 {
253 Communication::OutputBuffer request; 253 Communication::OutputBuffer request;
254 request << std::string("Matches") << url << contentType << domain; 254 request << Communication::PROC_MATCHES << url << contentType << domain;
255 255
256 try 256 try
257 { 257 {
258 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 258 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
259 259
260 bool match; 260 bool match;
261 response >> match; 261 response >> match;
262 return match; 262 return match;
263 } 263 }
264 catch (const std::exception& e) 264 catch (const std::exception& e)
265 { 265 {
266 DEBUG_GENERAL(e.what()); 266 DEBUG_GENERAL(e.what());
267 return false; 267 return false;
268 } 268 }
269 } 269 }
270 270
271 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std ::string& domain) 271 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std ::string& domain)
272 { 272 {
273 Communication::OutputBuffer request; 273 Communication::OutputBuffer request;
274 request << std::string("GetElementHidingSelectors") << domain; 274 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << domain;
275 275
276 try 276 try
277 { 277 {
278 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 278 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
279 return ReadStrings(response); 279 return ReadStrings(response);
280 } 280 }
281 catch (const std::exception& e) 281 catch (const std::exception& e)
282 { 282 {
283 DEBUG_GENERAL(e.what()); 283 DEBUG_GENERAL(e.what());
284 return std::vector<std::string>(); 284 return std::vector<std::string>();
285 } 285 }
286 } 286 }
287 287
288 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 288 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
289 { 289 {
290 try 290 try
291 { 291 {
292 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("FetchA vailableSubscriptions"); 292 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_AVAILABLE_SUBSCRIPTIONS);
293 return ReadSubscriptions(response); 293 return ReadSubscriptions(response);
294 } 294 }
295 catch (const std::exception& e) 295 catch (const std::exception& e)
296 { 296 {
297 DEBUG_GENERAL(e.what()); 297 DEBUG_GENERAL(e.what());
298 return std::vector<SubscriptionDescription>(); 298 return std::vector<SubscriptionDescription>();
299 } 299 }
300 } 300 }
301 301
302 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( ) 302 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( )
303 { 303 {
304 try 304 try
305 { 305 {
306 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("GetLis tedSubscriptions"); 306 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_LISTED_SUBSCRIPTIONS);
307 return ReadSubscriptions(response); 307 return ReadSubscriptions(response);
308 } 308 }
309 catch (const std::exception& e) 309 catch (const std::exception& e)
310 { 310 {
311 DEBUG_GENERAL(e.what()); 311 DEBUG_GENERAL(e.what());
312 return std::vector<SubscriptionDescription>(); 312 return std::vector<SubscriptionDescription>();
313 } 313 }
314 } 314 }
315 315
316 void CAdblockPlusClient::SetSubscription(std::string url) 316 void CAdblockPlusClient::SetSubscription(std::string url)
317 { 317 {
318 Communication::OutputBuffer request; 318 Communication::OutputBuffer request;
319 request << std::string("SetSubscription") << url; 319 request << Communication::PROC_SET_SUBSCRIPTION << url;
320 320
321 try 321 try
322 { 322 {
323 CallAdblockPlusEngineProcedure(request); 323 CallAdblockPlusEngineProcedure(request);
324 } 324 }
325 catch (const std::exception& e) 325 catch (const std::exception& e)
326 { 326 {
327 DEBUG_GENERAL(e.what()); 327 DEBUG_GENERAL(e.what());
328 } 328 }
329 } 329 }
330 330
331 void CAdblockPlusClient::UpdateAllSubscriptions() 331 void CAdblockPlusClient::UpdateAllSubscriptions()
332 { 332 {
333 try 333 try
334 { 334 {
335 CallAdblockPlusEngineProcedure("UpdateAllSubscriptions"); 335 CallAdblockPlusEngineProcedure(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS) ;
336 } 336 }
337 catch (const std::exception& e) 337 catch (const std::exception& e)
338 { 338 {
339 DEBUG_GENERAL(e.what()); 339 DEBUG_GENERAL(e.what());
340 } 340 }
341 } 341 }
342 342
343 std::vector<std::string> CAdblockPlusClient::GetExceptionDomains() 343 std::vector<std::string> CAdblockPlusClient::GetExceptionDomains()
344 { 344 {
345 try 345 try
346 { 346 {
347 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("GetExc eptionDomains"); 347 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_GET_EXCEPTION_DOMAINS);
348 return ReadStrings(response); 348 return ReadStrings(response);
349 } 349 }
350 catch (const std::exception& e) 350 catch (const std::exception& e)
351 { 351 {
352 DEBUG_GENERAL(e.what()); 352 DEBUG_GENERAL(e.what());
353 return std::vector<std::string>(); 353 return std::vector<std::string>();
354 } 354 }
355 } 355 }
356 356
357 void CAdblockPlusClient::AddFilter(const std::string& text) 357 void CAdblockPlusClient::AddFilter(const std::string& text)
358 { 358 {
359 Communication::OutputBuffer request; 359 Communication::OutputBuffer request;
360 request << std::string("AddFilter") << text; 360 request << Communication::PROC_ADD_FILTER << text;
361 361
362 try 362 try
363 { 363 {
364 CallAdblockPlusEngineProcedure(request); 364 CallAdblockPlusEngineProcedure(request);
365 } 365 }
366 catch (const std::exception& e) 366 catch (const std::exception& e)
367 { 367 {
368 DEBUG_GENERAL(e.what()); 368 DEBUG_GENERAL(e.what());
369 } 369 }
370 } 370 }
371 371
OLDNEW
« no previous file with comments | « src/engine/main.cpp ('k') | src/shared/Communication.h » ('j') | src/shared/Communication.h » ('J')

Powered by Google App Engine
This is Rietveld