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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/AdblockPlusClient.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <functional> 2 #include <functional>
3 #include <vector> 3 #include <vector>
4 #include <Windows.h> 4 #include <Windows.h>
5 5
6 #include "../shared/AutoHandle.h" 6 #include "../shared/AutoHandle.h"
7 #include "../shared/Communication.h" 7 #include "../shared/Communication.h"
8 #include "../shared/Dictionary.h" 8 #include "../shared/Dictionary.h"
9 #include "../shared/Utils.h" 9 #include "../shared/Utils.h"
10 #include "../shared/Version.h" 10 #include "../shared/Version.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 case Communication::PROC_REMOVE_FILTER: 139 case Communication::PROC_REMOVE_FILTER:
140 { 140 {
141 std::string text; 141 std::string text;
142 request >> text; 142 request >> text;
143 filterEngine->GetFilter(text)->RemoveFromList(); 143 filterEngine->GetFilter(text)->RemoveFromList();
144 break; 144 break;
145 } 145 }
146 case Communication::PROC_SET_PREF: 146 case Communication::PROC_SET_PREF:
147 { 147 {
148 std::string prefName = ""; 148 std::string prefName;
149 std::string prefValue = "";
150 request >> prefName; 149 request >> prefName;
151 request >> prefValue; 150
152 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(pr efValue)); 151 Communication::ValueType valueType = request.GetType();
152 switch (valueType)
153 {
154 case Communication::TYPE_STRING:
155 {
156 std::string prefValue;
157 request >> prefValue;
158 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
159 break;
160 }
161 case Communication::TYPE_INT64:
162 {
163 int64_t prefValue;
164 request >> prefValue;
165 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
166 break;
167 }
168 case Communication::TYPE_INT32:
169 {
170 int prefValue;
171 request >> prefValue;
172 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
173 break;
174 }
175 case Communication::TYPE_BOOL:
176 {
177 bool prefValue;
178 request >> prefValue;
179 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
180 break;
181 }
182 default:
183 break;
184 }
153 break; 185 break;
154 } 186 }
155 case Communication::PROC_GET_PREF: 187 case Communication::PROC_GET_PREF:
156 { 188 {
157 std::string name; 189 std::string name;
158 request >> name; 190 request >> name;
159 191
160 AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref(name); 192 AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref(name);
161 if ((valuePtr->IsNull()) || (!valuePtr->IsString())) 193 if (valuePtr->IsNull() || valuePtr->IsUndefined())
162 response << 0;
163 else
164 { 194 {
165 response << 1; 195 // Report no success
196 response << false;
197 break;
198 }
199
200 // Report success
201 response << true;
202
203 if (valuePtr->IsBool())
204 {
205 response << valuePtr->AsBool();
206 }
207 else if (valuePtr->IsNumber())
208 {
209 response << valuePtr->AsInt();
210 }
211 else if (valuePtr->IsString())
212 {
166 response << valuePtr->AsString(); 213 response << valuePtr->AsString();
167 } 214 }
168 break; 215 break;
169 } 216 }
170 217
171 } 218 }
172 return response; 219 return response;
173 } 220 }
174 221
175 DWORD WINAPI ClientThread(LPVOID param) 222 DWORD WINAPI ClientThread(LPVOID param)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 319 }
273 catch (std::runtime_error e) 320 catch (std::runtime_error e)
274 { 321 {
275 DebugException(e); 322 DebugException(e);
276 return 1; 323 return 1;
277 } 324 }
278 } 325 }
279 326
280 return 0; 327 return 0;
281 } 328 }
OLDNEW
« 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