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

Unified Diff: src/engine/main.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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | src/shared/Communication.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/engine/main.cpp
===================================================================
--- a/src/engine/main.cpp
+++ b/src/engine/main.cpp
@@ -47,89 +47,100 @@ namespace
<< subscription->IsListed();
}
}
Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
{
Communication::OutputBuffer response;
- std::string procedureName;
- request >> procedureName;
- if (procedureName == "Matches")
+ Communication::ProcType procedure;
+ request >> procedure;
+ switch (procedure)
{
- std::string url;
- std::string type;
- std::string documentUrl;
- request >> url >> type >> documentUrl;
- response << filterEngine->Matches(url, type, documentUrl);
- }
- else if (procedureName == "GetElementHidingSelectors")
- {
- std::string domain;
- request >> domain;
- WriteStrings(response, filterEngine->GetElementHidingSelectors(domain));
- }
- else if (procedureName == "FetchAvailableSubscriptions")
- {
- WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions());
- }
- else if (procedureName == "GetListedSubscriptions")
- {
- WriteSubscriptions(response, filterEngine->GetListedSubscriptions());
- }
- else if (procedureName == "SetSubscription")
- {
- std::string url;
- request >> url;
+ case Communication::PROC_MATCHES:
+ {
+ std::string url;
+ std::string type;
+ std::string documentUrl;
+ request >> url >> type >> documentUrl;
+ response << filterEngine->Matches(url, type, documentUrl);
+ break;
+ }
+ case Communication::PROC_GET_ELEMHIDE_SELECTORS:
+ {
+ std::string domain;
+ request >> domain;
+ WriteStrings(response, filterEngine->GetElementHidingSelectors(domain));
+ break;
+ }
+ case Communication::PROC_AVAILABLE_SUBSCRIPTIONS:
+ {
+ WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions());
+ break;
+ }
+ case Communication::PROC_LISTED_SUBSCRIPTIONS:
+ {
+ WriteSubscriptions(response, filterEngine->GetListedSubscriptions());
+ break;
+ }
+ case Communication::PROC_SET_SUBSCRIPTION:
+ {
+ std::string url;
+ request >> url;
- std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
- for (size_t i = 0, count = subscriptions.size(); i < count; i++)
- subscriptions[i]->RemoveFromList();
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
+ for (size_t i = 0, count = subscriptions.size(); i < count; i++)
+ subscriptions[i]->RemoveFromList();
- filterEngine->GetSubscription(url)->AddToList();
- }
- else if (procedureName == "UpdateAllSubscriptions")
- {
- std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
- for (size_t i = 0, count = subscriptions.size(); i < count; i++)
- subscriptions[i]->UpdateFilters();
- }
- else if (procedureName == "GetExceptionDomains")
- {
- std::vector<AdblockPlus::FilterPtr> filters = filterEngine->GetListedFilters();
- std::vector<std::string> domains;
- for (size_t i = 0, count = filters.size(); i < count; i++)
+ filterEngine->GetSubscription(url)->AddToList();
+ break;
+ }
+ case Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS:
{
- AdblockPlus::FilterPtr filter = filters[i];
- if (filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
+ for (size_t i = 0, count = subscriptions.size(); i < count; i++)
+ subscriptions[i]->UpdateFilters();
+ break;
+ }
+ case Communication::PROC_GET_EXCEPTION_DOMAINS:
+ {
+ std::vector<AdblockPlus::FilterPtr> filters = filterEngine->GetListedFilters();
+ std::vector<std::string> domains;
+ for (size_t i = 0, count = filters.size(); i < count; i++)
{
- std::string text = filter->GetProperty("text")->AsString();
+ AdblockPlus::FilterPtr filter = filters[i];
+ if (filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
+ {
+ std::string text = filter->GetProperty("text")->AsString();
- //@@||example.com^$document
- const char prefix[] = "@@||";
- const char suffix[] = "^$document";
- const int prefixLen = strlen(prefix);
- const int suffixLen = strlen(suffix);
- if (!text.compare(0, prefixLen, prefix) &&
- !text.compare(text.size() - suffixLen, suffixLen, suffix))
- {
- domains.push_back(text.substr(prefixLen, text.size() - prefixLen - suffixLen));
+ //@@||example.com^$document
+ const char prefix[] = "@@||";
+ const char suffix[] = "^$document";
+ const int prefixLen = strlen(prefix);
+ const int suffixLen = strlen(suffix);
+ if (!text.compare(0, prefixLen, prefix) &&
+ !text.compare(text.size() - suffixLen, suffixLen, suffix))
+ {
+ domains.push_back(text.substr(prefixLen, text.size() - prefixLen - suffixLen));
+ }
}
}
+
+ WriteStrings(response, domains);
+ break;
}
+ case Communication::PROC_ADD_FILTER:
+ {
+ std::string text;
+ request >> text;
- WriteStrings(response, domains);
- }
- else if (procedureName == "AddFilter")
- {
- std::string text;
- request >> text;
-
- filterEngine->GetFilter(text)->AddToList();
+ filterEngine->GetFilter(text)->AddToList();
+ break;
+ }
}
return response;
}
DWORD WINAPI ClientThread(LPVOID param)
{
std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(param));
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | src/shared/Communication.h » ('J')

Powered by Google App Engine
This is Rietveld