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

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

Issue 10824027: Implement better marshaling (Closed)
Patch Set: Created May 31, 2013, 8:26 a.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 while ((pipe = OpenPipe(Communication::pipeName)) == INVALID_HANDLE_VALU E) 59 while ((pipe = OpenPipe(Communication::pipeName)) == INVALID_HANDLE_VALU E)
60 { 60 {
61 const int step = 10; 61 const int step = 10;
62 Sleep(step); 62 Sleep(step);
63 timeout -= step; 63 timeout -= step;
64 if (timeout <= 0) 64 if (timeout <= 0)
65 throw std::runtime_error("Unable to open Adblock Plus Engine pipe"); 65 throw std::runtime_error("Unable to open Adblock Plus Engine pipe");
66 } 66 }
67 } 67 }
68 68
69 DWORD mode = PIPE_READMODE_MESSAGE; 69 DWORD mode = PIPE_READMODE_MESSAGE;
70 if (!SetNamedPipeHandleState(pipe, &mode, 0, 0)) 70 if (!SetNamedPipeHandleState(pipe, &mode, 0, 0))
71 throw std::runtime_error("SetNamedPipeHandleState failed"); 71 throw std::runtime_error("SetNamedPipeHandleState failed");
72 72
73 return pipe; 73 return pipe;
74 } 74 }
75 catch(std::exception e) 75 catch(std::exception e)
76 { 76 {
77 DEBUG_GENERAL(e.what()); 77 DEBUG_GENERAL(e.what());
78 return INVALID_HANDLE_VALUE; 78 return INVALID_HANDLE_VALUE;
79 } 79 }
80 } 80 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 cbData = 50; 203 cbData = 50;
204 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a); 204 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a);
205 if (status != 0) 205 if (status != 0)
206 { 206 {
207 return 0; 207 return 0;
208 } 208 }
209 RegCloseKey(hKey); 209 RegCloseKey(hKey);
210 return (int)(version[0] - 48); 210 return (int)(version[0] - 48);
211 } 211 }
212 212
213 std::string CallAdblockPlusEngineProcedure(const std::vector<std::string>& args) 213 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB uffer& message)
214 { 214 {
215 AutoHandle pipe(OpenAdblockPlusEnginePipe()); 215 AutoHandle pipe(OpenAdblockPlusEnginePipe());
216 Communication::WriteMessage(pipe.get(), Communication::MarshalStrings(args)); 216 Communication::WriteMessage(pipe.get(), message);
217 return Communication::ReadMessage(pipe.get()); 217 return Communication::ReadMessage(pipe.get());
218 } 218 }
219 219
220 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain) 220 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain)
221 { 221 {
222 std::vector<std::string> args; 222 Communication::OutputBuffer request;
223 args.push_back("Matches"); 223 request << std::string("Matches") << url << contentType << domain;
224 args.push_back(url);
225 args.push_back(contentType);
226 args.push_back(domain);
227 224
228 try 225 try
229 { 226 {
230 std::string response = CallAdblockPlusEngineProcedure(args); 227 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
231 return response == "1"; 228
229 bool match;
230 response >> match;
231 return match;
232 } 232 }
233 catch (const std::exception& e) 233 catch (const std::exception& e)
234 { 234 {
235 DEBUG_GENERAL(e.what()); 235 DEBUG_GENERAL(e.what());
236 return false; 236 return false;
237 } 237 }
238 } 238 }
239 239
240 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(std::stri ng domain) 240 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std ::string& domain)
241 { 241 {
242 std::vector<std::string> args; 242 Communication::OutputBuffer request;
243 args.push_back("GetElementHidingSelectors"); 243 request << std::string("GetElementHidingSelectors") << domain;
244 args.push_back(domain);
245 244
246 try 245 try
247 { 246 {
248 std::string response = CallAdblockPlusEngineProcedure(args); 247 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
249 return Communication::UnmarshalStrings(response); 248
249 std::vector<std::string> selectors;
250 int32_t length;
251 response >> length;
252 for (int32_t i = 0; i < length; i++)
253 {
254 std::string selector;
255 response >> selector;
256 selectors.push_back(selector);
257 }
258 return selectors;
250 } 259 }
251 catch (const std::exception& e) 260 catch (const std::exception& e)
252 { 261 {
253 DEBUG_GENERAL(e.what()); 262 DEBUG_GENERAL(e.what());
254 return std::vector<std::string>(); 263 return std::vector<std::string>();
255 } 264 }
256 } 265 }
257 266
258 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::FetchAvailableSubs criptions() 267 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::FetchAvailableSubs criptions()
259 { 268 {
(...skipping 17 matching lines...) Expand all
277 { 286 {
278 //TODO: implement this 287 //TODO: implement this
279 return std::vector<AdblockPlus::SubscriptionPtr>(); 288 return std::vector<AdblockPlus::SubscriptionPtr>();
280 } 289 }
281 290
282 AdblockPlus::SubscriptionPtr CAdblockPlusClient::GetSubscription(std::string url ) 291 AdblockPlus::SubscriptionPtr CAdblockPlusClient::GetSubscription(std::string url )
283 { 292 {
284 //TODO: imlement this 293 //TODO: imlement this
285 return AdblockPlus::SubscriptionPtr(); 294 return AdblockPlus::SubscriptionPtr();
286 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld