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: Addressing comments Created Sept. 16, 2013, 1:49 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
15 namespace 15 namespace
16 { 16 {
17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
18 std::auto_ptr<Updater> updater; 18 std::auto_ptr<Updater> updater;
19 int activeConnections = 0; 19 int activeConnections = 0;
20 CriticalSection activeConnectionsLock; 20 CriticalSection activeConnectionsLock;
21 HWND callbackWindow;
21 22
22 void WriteStrings(Communication::OutputBuffer& response, 23 void WriteStrings(Communication::OutputBuffer& response,
23 const std::vector<std::string>& strings) 24 const std::vector<std::string>& strings)
24 { 25 {
25 int32_t count = static_cast<int32_t>(strings.size()); 26 int32_t count = static_cast<int32_t>(strings.size());
26 response << count; 27 response << count;
27 for (int32_t i = 0; i < count; i++) 28 for (int32_t i = 0; i < count; i++)
28 response << strings[i]; 29 response << strings[i];
29 } 30 }
30 31
31 void WriteSubscriptions(Communication::OutputBuffer& response, 32 void WriteSubscriptions(Communication::OutputBuffer& response,
32 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 33 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
33 { 34 {
34 int32_t count = static_cast<int32_t>(subscriptions.size()); 35 int32_t count = static_cast<int32_t>(subscriptions.size());
35 response << count; 36 response << count;
36 for (int32_t i = 0; i < count; i++) 37 for (int32_t i = 0; i < count; i++)
37 { 38 {
38 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 39 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
39 response << subscription->GetProperty("url")->AsString() 40 response << subscription->GetProperty("url")->AsString()
40 << subscription->GetProperty("title")->AsString() 41 << subscription->GetProperty("title")->AsString()
41 << subscription->GetProperty("specialization")->AsString() 42 << subscription->GetProperty("specialization")->AsString()
42 << subscription->IsListed(); 43 << subscription->IsListed();
43 } 44 }
44 } 45 }
45 46
46 bool updateAvailable; 47 bool updateAvailable;
48 bool checkingForUpdate = false;
47 void UpdateCallback(const std::string res) 49 void UpdateCallback(const std::string res)
48 { 50 {
51 UINT message;
49 if (updateAvailable) 52 if (updateAvailable)
50 return;
51 Dictionary* dictionary = Dictionary::GetInstance();
52 if (res.length() == 0)
53 { 53 {
54 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); 54 message = WM_DOWNLOADING_UPDATE;
55 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title");
56 MessageBoxW(NULL, upToDateText.c_str(), upToDateTitle.c_str(), MB_OK);
57 } 55 }
58 else 56 else if (res.length() == 0)
59 { 57 {
60 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); 58 message = WM_ALREADY_UP_TO_DATE;
61 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); 59 }
62 ReplaceString(errorText, L"?1?", ToUtf16String(res)); 60 else
63 MessageBoxW(NULL, errorText.c_str(), errorTitle.c_str(), MB_OK); 61 {
62 message = WM_UPDATE_CHECK_ERROR;
63 }
64 if (callbackWindow)
65 {
66 SendMessage(callbackWindow, message, 0, 0);
67 checkingForUpdate = false;
Wladimir Palant 2013/09/19 08:59:16 I would normally protect every access to the varia
68 callbackWindow = 0;
64 } 69 }
65 return; 70 return;
66 } 71 }
67 72
68 73
69 CriticalSection firstRunLock; 74 CriticalSection firstRunLock;
75 CriticalSection updateCheckLock;
70 bool firstRunActionExecuted = false; 76 bool firstRunActionExecuted = false;
71 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) 77 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
72 { 78 {
73 Communication::OutputBuffer response; 79 Communication::OutputBuffer response;
74 80
75 Communication::ProcType procedure; 81 Communication::ProcType procedure;
76 request >> procedure; 82 request >> procedure;
77 switch (procedure) 83 switch (procedure)
78 { 84 {
79 case Communication::PROC_MATCHES: 85 case Communication::PROC_MATCHES:
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 242 }
237 else 243 else
238 { 244 {
239 // Report failure 245 // Report failure
240 response << false; 246 response << false;
241 } 247 }
242 break; 248 break;
243 } 249 }
244 case Communication::PROC_CHECK_FOR_UPDATES: 250 case Communication::PROC_CHECK_FOR_UPDATES:
245 { 251 {
246 updateAvailable = false; 252 request >> (int32_t&)callbackWindow;
247 filterEngine->ForceUpdateCheck(UpdateCallback); 253 CriticalSection::Lock lock(updateCheckLock);
254 if (!checkingForUpdate)
255 {
256 updateAvailable = false;
257 checkingForUpdate = true;
258 filterEngine->ForceUpdateCheck(UpdateCallback);
259 }
248 break; 260 break;
249 } 261 }
250 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED: 262 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED:
251 { 263 {
252 CriticalSection::Lock lock(firstRunLock); 264 CriticalSection::Lock lock(firstRunLock);
253 if (!firstRunActionExecuted && filterEngine->IsFirstRun()) 265 if (!firstRunActionExecuted && filterEngine->IsFirstRun())
254 { 266 {
255 response << true; 267 response << true;
256 firstRunActionExecuted = true; 268 firstRunActionExecuted = true;
257 } 269 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 418 }
407 catch (std::runtime_error e) 419 catch (std::runtime_error e)
408 { 420 {
409 DebugException(e); 421 DebugException(e);
410 return 1; 422 return 1;
411 } 423 }
412 } 424 }
413 425
414 return 0; 426 return 0;
415 } 427 }
OLDNEW
« no previous file with comments | « locales/en.ini ('k') | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/NotificationMessage.h » ('J')

Powered by Google App Engine
This is Rietveld