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

Unified Diff: src/engine/main.cpp

Issue 11013110: Cleanup (Closed)
Patch Set: SetPref/GetPref type safety. Comments addressed. Created July 22, 2013, 12:42 a.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.h » ('j') | src/plugin/AdblockPlusClient.cpp » ('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
@@ -145,11 +145,43 @@
}
case Communication::PROC_SET_PREF:
{
- std::string prefName = "";
- std::string prefValue = "";
+ std::string prefName;
request >> prefName;
- request >> prefValue;
- filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(prefValue));
+
+ Communication::ValueType valueType = request.GetType();
+ switch (valueType)
+ {
+ case Communication::TYPE_STRING:
+ {
+ std::string prefValue;
+ request >> prefValue;
+ filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(prefValue));
+ break;
+ }
+ case Communication::TYPE_INT64:
+ {
+ int64_t prefValue;
+ request >> prefValue;
+ filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(prefValue));
+ break;
+ }
+ case Communication::TYPE_INT32:
+ {
+ int prefValue;
+ request >> prefValue;
+ filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(prefValue));
+ break;
+ }
+ case Communication::TYPE_BOOL:
+ {
+ bool prefValue;
+ request >> prefValue;
+ filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(prefValue));
+ break;
+ }
+ default:
+ break;
+ }
break;
}
case Communication::PROC_GET_PREF:
@@ -158,11 +190,26 @@
request >> name;
AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref(name);
- if ((valuePtr->IsNull()) || (!valuePtr->IsString()))
- response << 0;
- else
+ if (valuePtr->IsNull() || valuePtr->IsUndefined())
{
- response << 1;
+ // Report no success
+ response << false;
+ break;
+ }
+
+ // Report success
+ response << true;
+
+ if (valuePtr->IsBool())
+ {
+ response << valuePtr->AsBool();
+ }
+ else if (valuePtr->IsNumber())
+ {
+ response << valuePtr->AsInt();
+ }
+ else if (valuePtr->IsString())
+ {
response << valuePtr->AsString();
}
break;
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/AdblockPlusClient.cpp » ('J')

Powered by Google App Engine
This is Rietveld