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

Delta Between Two Patch Sets: src/engine/main.cpp

Issue 11013110: Cleanup (Closed)
Left Patch Set: More refactoring. Removing main thread, tab counting. Implementing SetPref and GetPref. Addressing … Created July 9, 2013, 12:59 p.m.
Right Patch Set: More beautification and addressing comments Created July 29, 2013, 12:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « adblockplus.gyp ('k') | src/plugin/AdblockPlus.rc » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 = "";
Wladimir Palant 2013/07/11 12:53:10 Please don't initialize these variables, their ini
150 request >> prefName; 149 request >> prefName;
151 request >> prefValue; 150
Wladimir Palant 2013/07/11 12:53:10 These lines can be merged: request >> prefName >>
152 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(pr efValue)); 151 Communication::ValueType valueType = request.GetType();
Wladimir Palant 2013/07/11 12:53:10 What about preferences with non-string values? Thi
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())
Wladimir Palant 2013/07/11 12:53:10 I think checking valuePtr->IsString() is sufficien
162 response << 0; 194 {
Wladimir Palant 2013/07/11 12:53:10 Please don't use an integer as a boolean, this sho
195 // Report no success
196 response << false;
197 break;
198 }
199
200
201 if (valuePtr->IsBool())
202 {
203 response << true;
204 response << valuePtr->AsBool();
205 }
206 else if (valuePtr->IsNumber())
207 {
208 response << true;
209 response << valuePtr->AsInt();
210 }
211 else if (valuePtr->IsString())
212 {
213 response << true;
214 response << valuePtr->AsString();
215 }
163 else 216 else
164 { 217 {
165 response << 1; 218 // Report failure
166 response << valuePtr->AsString(); 219 response << false;
Wladimir Palant 2013/07/11 12:53:10 These two lines can be merged: response << true
167 } 220 }
168 break; 221 break;
169 } 222 }
170 223
171 } 224 }
172 return response; 225 return response;
173 } 226 }
174 227
175 DWORD WINAPI ClientThread(LPVOID param) 228 DWORD WINAPI ClientThread(LPVOID param)
176 { 229 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 325 }
273 catch (std::runtime_error e) 326 catch (std::runtime_error e)
274 { 327 {
275 DebugException(e); 328 DebugException(e);
276 return 1; 329 return 1;
277 } 330 }
278 } 331 }
279 332
280 return 0; 333 return 0;
281 } 334 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld