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

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

Issue 11043057: First run page triggering (Closed)
Left Patch Set: Created July 11, 2013, 9:49 a.m.
Right Patch Set: Minor refactoring. Renaming and a small cleanup. Created July 26, 2013, 12:05 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 | « html/static/js/IESettings.js ('k') | src/plugin/AdblockPlusClient.h » ('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"
11 #include "../shared/CriticalSection.h"
11 #include "Debug.h" 12 #include "Debug.h"
12 #include "Updater.h" 13 #include "Updater.h"
13 14
14 namespace 15 namespace
15 { 16 {
16 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
17 18
18 void WriteStrings(Communication::OutputBuffer& response, 19 void WriteStrings(Communication::OutputBuffer& response,
19 const std::vector<std::string>& strings) 20 const std::vector<std::string>& strings)
20 { 21 {
(...skipping 10 matching lines...) Expand all
31 response << count; 32 response << count;
32 for (int32_t i = 0; i < count; i++) 33 for (int32_t i = 0; i < count; i++)
33 { 34 {
34 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 35 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
35 response << subscription->GetProperty("url")->AsString() 36 response << subscription->GetProperty("url")->AsString()
36 << subscription->GetProperty("title")->AsString() 37 << subscription->GetProperty("title")->AsString()
37 << subscription->GetProperty("specialization")->AsString() 38 << subscription->GetProperty("specialization")->AsString()
38 << subscription->IsListed(); 39 << subscription->IsListed();
39 } 40 }
40 } 41 }
42
43 CriticalSection firstRunLock;
44 bool firstRunActionExecuted = false;
41 45
42 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) 46 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
43 { 47 {
44 Communication::OutputBuffer response; 48 Communication::OutputBuffer response;
45 49
46 Communication::ProcType procedure; 50 Communication::ProcType procedure;
47 request >> procedure; 51 request >> procedure;
48 switch (procedure) 52 switch (procedure)
49 { 53 {
50 case Communication::PROC_MATCHES: 54 case Communication::PROC_MATCHES:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 142 }
139 case Communication::PROC_REMOVE_FILTER: 143 case Communication::PROC_REMOVE_FILTER:
140 { 144 {
141 std::string text; 145 std::string text;
142 request >> text; 146 request >> text;
143 filterEngine->GetFilter(text)->RemoveFromList(); 147 filterEngine->GetFilter(text)->RemoveFromList();
144 break; 148 break;
145 } 149 }
146 case Communication::PROC_SET_PREF: 150 case Communication::PROC_SET_PREF:
147 { 151 {
148 std::string prefName = ""; 152 std::string prefName;
149 std::string prefValue = "";
150 request >> prefName; 153 request >> prefName;
151 request >> prefValue; 154
152 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValue(pr efValue)); 155 Communication::ValueType valueType = request.GetType();
156 switch (valueType)
157 {
158 case Communication::TYPE_STRING:
159 {
160 std::string prefValue;
161 request >> prefValue;
162 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
163 break;
164 }
165 case Communication::TYPE_INT64:
166 {
167 int64_t prefValue;
168 request >> prefValue;
169 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
170 break;
171 }
172 case Communication::TYPE_INT32:
173 {
174 int prefValue;
175 request >> prefValue;
176 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
177 break;
178 }
179 case Communication::TYPE_BOOL:
180 {
181 bool prefValue;
182 request >> prefValue;
183 filterEngine->SetPref(prefName, filterEngine->GetJsEngine()->NewValu e(prefValue));
184 break;
185 }
186 default:
187 break;
188 }
153 break; 189 break;
154 } 190 }
155 case Communication::PROC_GET_PREF: 191 case Communication::PROC_GET_PREF:
156 { 192 {
157 std::string name; 193 std::string name;
158 request >> name; 194 request >> name;
159 195
160 AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref(name); 196 AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref(name);
161 if ((valuePtr->IsNull()) || (!valuePtr->IsString())) 197 if (valuePtr->IsNull() || valuePtr->IsUndefined())
162 response << 0; 198 {
199 // Report no success
200 response << false;
201 break;
202 }
203
204 // Report success
205 response << true;
206
207 if (valuePtr->IsBool())
208 {
209 response << valuePtr->AsBool();
210 }
211 else if (valuePtr->IsNumber())
212 {
213 response << valuePtr->AsInt();
214 }
215 else if (valuePtr->IsString())
216 {
217 response << valuePtr->AsString();
218 }
219 break;
220 }
221 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED:
222 {
223 CriticalSection::Lock lock(firstRunLock);
224 if (!firstRunActionExecuted && filterEngine->IsFirstRun())
225 {
226 response << true;
227 firstRunActionExecuted = true;
228 }
163 else 229 else
164 { 230 {
165 response << 1; 231 response << false;
166 response << valuePtr->AsString(); 232 }
167 } 233 break;
168 break; 234 }
169 }
170 case Communication::PROC_GET_IS_FIRST_RUN:
171 {
Wladimir Palant 2013/07/11 11:58:10 Wrong indentation?
172 response << filterEngine->IsFirstRun();
173 break;
174 }
175 235
176 } 236 }
177 return response; 237 return response;
178 } 238 }
179 239
180 DWORD WINAPI ClientThread(LPVOID param) 240 DWORD WINAPI ClientThread(LPVOID param)
181 { 241 {
182 std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(pa ram)); 242 std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(pa ram));
183 243
184 try 244 try
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 337 }
278 catch (std::runtime_error e) 338 catch (std::runtime_error e)
279 { 339 {
280 DebugException(e); 340 DebugException(e);
281 return 1; 341 return 1;
282 } 342 }
283 } 343 }
284 344
285 return 0; 345 return 0;
286 } 346 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld