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

Side by Side Diff: src/engine/Main.cpp

Issue 11557015: Tooltip notification. Check for update fixes. (Closed)
Patch Set: Created Sept. 5, 2013, 10:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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"
11 #include "../shared/CriticalSection.h" 11 #include "../shared/CriticalSection.h"
12 #include "Debug.h" 12 #include "Debug.h"
13 #include "Updater.h" 13 #include "Updater.h"
14 14
Felix Dahlke 2013/09/11 15:22:59 Super nit, but I think a single empty line between
15
16
15 namespace 17 namespace
16 { 18 {
17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 19 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
18 std::auto_ptr<Updater> updater; 20 std::auto_ptr<Updater> updater;
19 int activeConnections = 0; 21 int activeConnections = 0;
20 CriticalSection activeConnectionsLock; 22 CriticalSection activeConnectionsLock;
23 HWND callbackWindow;
21 24
22 void WriteStrings(Communication::OutputBuffer& response, 25 void WriteStrings(Communication::OutputBuffer& response,
23 const std::vector<std::string>& strings) 26 const std::vector<std::string>& strings)
24 { 27 {
25 int32_t count = static_cast<int32_t>(strings.size()); 28 int32_t count = static_cast<int32_t>(strings.size());
26 response << count; 29 response << count;
27 for (int32_t i = 0; i < count; i++) 30 for (int32_t i = 0; i < count; i++)
28 response << strings[i]; 31 response << strings[i];
29 } 32 }
30 33
31 void WriteSubscriptions(Communication::OutputBuffer& response, 34 void WriteSubscriptions(Communication::OutputBuffer& response,
32 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 35 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
33 { 36 {
34 int32_t count = static_cast<int32_t>(subscriptions.size()); 37 int32_t count = static_cast<int32_t>(subscriptions.size());
35 response << count; 38 response << count;
36 for (int32_t i = 0; i < count; i++) 39 for (int32_t i = 0; i < count; i++)
37 { 40 {
38 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 41 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
39 response << subscription->GetProperty("url")->AsString() 42 response << subscription->GetProperty("url")->AsString()
40 << subscription->GetProperty("title")->AsString() 43 << subscription->GetProperty("title")->AsString()
41 << subscription->GetProperty("specialization")->AsString() 44 << subscription->GetProperty("specialization")->AsString()
42 << subscription->IsListed(); 45 << subscription->IsListed();
43 } 46 }
44 } 47 }
45 48
46 bool updateAvailable; 49 bool updateAvailable;
50 volatile bool checkingForUpdate = false;
Felix Dahlke 2013/09/11 15:22:59 Why use the volatile keyword here? I doubt it's wh
47 void UpdateCallback(const std::string res) 51 void UpdateCallback(const std::string res)
48 { 52 {
53 checkingForUpdate = false;
Wladimir Palant 2013/09/11 13:07:06 This needs to be set when the function is finished
49 if (updateAvailable) 54 if (updateAvailable)
55 {
56 if (callbackWindow != 0)
57 {
58 SendMessage(callbackWindow, WM_DOWNLOADING_UPDATE, 0, 0);
59 callbackWindow = 0;
60 }
50 return; 61 return;
62 }
51 Dictionary* dictionary = Dictionary::GetInstance(); 63 Dictionary* dictionary = Dictionary::GetInstance();
Wladimir Palant 2013/09/11 13:07:06 The dictionary is no longer being used.
52 if (res.length() == 0) 64 if (res.length() == 0)
53 { 65 {
54 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); 66 if (callbackWindow != 0)
55 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); 67 {
56 MessageBoxW(NULL, upToDateText.c_str(), upToDateTitle.c_str(), MB_OK); 68 SendMessage(callbackWindow, WM_ALREADY_UP_TO_DATE, 0, 0);
69 }
57 } 70 }
58 else 71 else
59 { 72 {
60 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); 73 if (callbackWindow != 0)
61 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); 74 {
62 ReplaceString(errorText, L"?1?", ToUtf16String(res)); 75 SendMessage(callbackWindow, WM_UPDATE_CHECK_ERROR, 0, 0);
63 MessageBoxW(NULL, errorText.c_str(), errorTitle.c_str(), MB_OK); 76 }
64 } 77 }
78 callbackWindow = 0;
65 return; 79 return;
66 } 80 }
67 81
68 82
69 CriticalSection firstRunLock; 83 CriticalSection firstRunLock;
70 bool firstRunActionExecuted = false; 84 bool firstRunActionExecuted = false;
71 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) 85 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
72 { 86 {
73 Communication::OutputBuffer response; 87 Communication::OutputBuffer response;
74 88
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 250 }
237 else 251 else
238 { 252 {
239 // Report failure 253 // Report failure
240 response << false; 254 response << false;
241 } 255 }
242 break; 256 break;
243 } 257 }
244 case Communication::PROC_CHECK_FOR_UPDATES: 258 case Communication::PROC_CHECK_FOR_UPDATES:
245 { 259 {
260 request >> (int32_t&)callbackWindow;
246 updateAvailable = false; 261 updateAvailable = false;
Wladimir Palant 2013/09/11 13:07:06 Setting updateAvailable definitely belongs into th
247 filterEngine->ForceUpdateCheck(UpdateCallback); 262 if (!checkingForUpdate)
263 {
264 checkingForUpdate = true;
Wladimir Palant 2013/09/11 13:07:06 This is a race condition - another PROC_CHECK_FOR_
265 filterEngine->ForceUpdateCheck(UpdateCallback);
266 }
248 break; 267 break;
249 } 268 }
250 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED: 269 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED:
251 { 270 {
252 CriticalSection::Lock lock(firstRunLock); 271 CriticalSection::Lock lock(firstRunLock);
253 if (!firstRunActionExecuted && filterEngine->IsFirstRun()) 272 if (!firstRunActionExecuted && filterEngine->IsFirstRun())
254 { 273 {
255 response << true; 274 response << true;
256 firstRunActionExecuted = true; 275 firstRunActionExecuted = true;
257 } 276 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 425 }
407 catch (std::runtime_error e) 426 catch (std::runtime_error e)
408 { 427 {
409 DebugException(e); 428 DebugException(e);
410 return 1; 429 return 1;
411 } 430 }
412 } 431 }
413 432
414 return 0; 433 return 0;
415 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld