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

Delta Between Two Patch Sets: src/plugin/PluginClassThread.cpp

Issue 11013110: Cleanup (Closed)
Left Patch Set: Created July 5, 2013, 3:28 a.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 | « src/plugin/PluginClass.cpp ('k') | src/plugin/PluginClientBase.cpp » ('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 "PluginStdAfx.h"
2
3 #include <ctime>
4
5 #include "PluginClass.h"
6 #include "PluginSettings.h"
7 #include "PluginSystem.h"
8 #ifdef SUPPORT_FILTER
9 #include "PluginFilter.h"
10 #endif
11 #ifdef SUPPORT_CONFIG
12 #include "PluginConfig.h"
13 #endif
14 #include "PluginMimeFilterClient.h"
15
16 #include "PluginClient.h"
17 #include "PluginClientFactory.h"
18 #include "PluginWbPassThrough.h"
19
20 #include "ProtocolImpl.h"
21 #include "ProtocolCF.h"
22
23 HANDLE CPluginClass::s_hMainThread = NULL;
24 bool CPluginClass::s_isMainThreadDone = false;
25
26
27 DWORD WINAPI CPluginClass::MainThreadProc(LPVOID pParam)
28 {
29
30 CPluginTab* tab = static_cast<CPluginTab*>(pParam);
31
32 // Force loading/creation of settings
33 CPluginSettings* settings = CPluginSettings::GetInstance();
34
35 CPluginSystem* system = CPluginSystem::GetInstance();
36
37 settings->SetMainThreadId();
38
39 CString debugText;
40
41 CString threadInfo;
42 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
43
44 debugText += L"=============================================================== =================";
45 debugText += L"\nMAIN THREAD " + threadInfo + L" Plugin version:" + CString(IE PLUGIN_VERSION);
46 debugText += L"\n============================================================= ===================";
47
48 debugText += L"\nPlugin version: " + CString(IEPLUGIN_VERSION);
49 debugText += L"\nBrowser version: " + system->GetBrowserVersion();
50 debugText += L"\nBrowser language: " + system->GetBrowserLanguage();
51
52 DWORD osVersion = ::GetVersion();
53
54 CString ver;
55 ver.Format(L"%d.%d", LOBYTE(LOWORD(osVersion)), HIBYTE(LOWORD(osVersion)));
56
57
58 debugText += L"\nWindows version: " + ver;
59 debugText += L"\n============================================================= ===================";
60
61 DEBUG_GENERAL(debugText)
62
63 HANDLE hMainThread = GetMainThreadHandle();
64
65 DWORD nNextUserTimerBase = GetTickCount() / TIMER_INTERVAL_USER_REGISTRATION + 1;
66 DWORD nUserTimerBaseStep = 1;
67
68 // --------------------------------------------------------------------
69 // Welcome / Info page
70 // --------------------------------------------------------------------
71
72 DEBUG_THREAD("Thread::Set welcome/info page");
73
74 if (!IsMainThreadDone(hMainThread))
75 {
76 WORD wInfo = 0;
77 WORD wInfoSettings = 0;
78
79
80 // TODO: Add First run page logic here
81 if (wInfo != 0)
82 {
83 DEBUG_THREAD("Thread::Set info page (action)");
84
85 s_criticalSectionLocal.Lock();
86 {
87 ::PostMessage(tab->m_plugin->m_hPaneWnd, WM_LAUNCH_INFO, wInfo, NULL);
88 }
89 s_criticalSectionLocal.Unlock();
90 }
91 }
92
93 // --------------------------------------------------------------------
94 // Main loop
95 // --------------------------------------------------------------------
96
97 DWORD mainLoopIteration = 1;
98
99 while (!IsMainThreadDone(hMainThread))
100 {
101 CString sMainLoopIteration;
102 sMainLoopIteration.Format(L"%u", mainLoopIteration);
103
104 CString debugText;
105
106 debugText += L"------------------------------------------------------------- -------------------";
107 debugText += L"\nLoop iteration " + sMainLoopIteration;
108 debugText += L"\n----------------------------------------------------------- ---------------------";
109
110 DEBUG_GENERAL(debugText)
111
112 // --------------------------------------------------------------------
113 // Update settings
114 // --------------------------------------------------------------------
115
116 if (!IsMainThreadDone(hMainThread))
117 {
118 DEBUG_THREAD("Thread::Update settings");
119
120 bool isNewDictionaryVersion = false;
121 #ifdef SUPPORT_FILTER
122 bool isNewFilterVersion = false;
123 #endif
124 #ifdef SUPPORT_CONFIG
125 bool isNewConfig = false;
126 #endif
127
128 DEBUG_THREAD("Thread::Update settings (action)");
129
130 // Update filters, if needed (5 days * (random() * 0.4 + 0.8))
131 settings->RefreshFilterlist();
Wladimir Palant 2013/07/05 09:26:45 We shouldn't do that here - the engine will refres
132 tab->OnUpdate();
133 }
134
135
136 // ----------------------------------------------------------------
137 // End loop
138 // ----------------------------------------------------------------
139
140 if (!IsMainThreadDone(hMainThread))
141 {
142 bool isDone = false;
143 DWORD sleepLoopIteration = 1;
144
145 // Sleep loop
146 while (!isDone && !IsMainThreadDone(hMainThread))
147 {
148 // Non-hanging sleep
149 Sleep(5000);
150
151 if (sleepLoopIteration++ % (TIMER_THREAD_SLEEP_USER_REGISTRATION) == 0 )
152 {
153 isDone = true;
154 }
155 }
156 }
157
158 mainLoopIteration++;
159 }
160
161 return 0;
162 }
163
164
165 HANDLE CPluginClass::GetMainThreadHandle()
166 {
167 HANDLE handle = NULL;
168
169 s_criticalSectionLocal.Lock();
170 {
171 handle = s_hMainThread;
172 }
173 s_criticalSectionLocal.Unlock();
174
175 return handle;
176 }
177
178
179 bool CPluginClass::IsMainThreadDone(HANDLE mainThread)
180 {
181 bool isDone = false;
182
183 s_criticalSectionLocal.Lock();
184 {
185 isDone = s_isMainThreadDone || mainThread != s_hMainThread;
186 }
187 s_criticalSectionLocal.Unlock();
188
189 return isDone;
190 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld