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

Side by Side Diff: src/plugin/PluginClassThread.cpp

Issue 11013110: Cleanup (Closed)
Patch Set: Minor CallEngine refactoring Created July 26, 2013, 2:12 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
(Empty)
1 #include "PluginStdAfx.h"
2
3 #include <ctime>
4
5 #include "PluginClass.h"
6 #include "PluginSettings.h"
7 #include "PluginSystem.h"
8 #include "PluginConfiguration.h"
9 #ifdef SUPPORT_FILTER
10 #include "PluginFilter.h"
11 #endif
12 #ifdef SUPPORT_CONFIG
13 #include "PluginConfig.h"
14 #endif
15 #include "PluginMimeFilterClient.h"
16
17 #include "PluginClient.h"
18 #include "PluginClientFactory.h"
19 #include "PluginWbPassThrough.h"
20 #include "PluginHttpRequest.h"
21
22 #include "ProtocolImpl.h"
23 #include "ProtocolCF.h"
24
25 HANDLE CPluginClass::s_hMainThread = NULL;
26 bool CPluginClass::s_isMainThreadDone = false;
27
28
29 DWORD WINAPI CPluginClass::MainThreadProc(LPVOID pParam)
30 {
31
32 CPluginTab* tab = static_cast<CPluginTab*>(pParam);
33
34 // Force loading/creation of settings
35 CPluginSettings* settings = CPluginSettings::GetInstance();
36
37 CPluginSystem* system = CPluginSystem::GetInstance();
38
39 settings->SetMainThreadId();
40
41 CString debugText;
42
43 CString threadInfo;
44 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
45
46 debugText += L"=============================================================== =================";
47 debugText += L"\nMAIN THREAD " + threadInfo + L" Plugin version:" + CString(IE PLUGIN_VERSION);
48 debugText += L"\n============================================================= ===================";
49
50 debugText += L"\nPlugin version: " + CString(IEPLUGIN_VERSION);
51 debugText += L"\nBrowser version: " + system->GetBrowserVersion();
52 debugText += L"\nBrowser language: " + system->GetBrowserLanguage();
53
54 DWORD osVersion = ::GetVersion();
55
56 CString ver;
57 ver.Format(L"%d.%d", LOBYTE(LOWORD(osVersion)), HIBYTE(LOWORD(osVersion)));
58
59
60 debugText += L"\nWindows version: " + ver;
61
62 CString proxyName;
63 CString proxyBypass;
64
65 if (CPluginHttpRequest::GetProxySettings(proxyName, proxyBypass))
66 {
67 if (!proxyName.IsEmpty())
68 {
69 debugText += L"\nHTTP proxy name: " + proxyName;
70 }
71 if (!proxyBypass.IsEmpty())
72 {
73 debugText += L"\nHTTP proxy bypass: " + proxyBypass;
74 }
75 }
76
77 debugText += L"\n============================================================= ===================";
78
79 DEBUG_GENERAL(debugText)
80
81 HANDLE hMainThread = GetMainThreadHandle();
82
83 CPluginClient* client = CPluginClient::GetInstance();
84 client->SetLocalization();
85
86 DWORD nNextUserTimerBase = GetTickCount() / TIMER_INTERVAL_USER_REGISTRATION + 1;
87 DWORD nUserTimerBaseStep = 1;
88
89 bool isConfigutationLoaded = false;
90
91 std::auto_ptr<CPluginConfiguration> configuration = std::auto_ptr<CPluginConfi guration>(new CPluginConfiguration);
92
93 // --------------------------------------------------------------------
94 // Welcome / Info page
95 // --------------------------------------------------------------------
96
97 DEBUG_THREAD("Thread::Set welcome/info page");
98
99 if (!IsMainThreadDone(hMainThread))
100 {
101 WORD wInfo = 0;
102 WORD wInfoSettings = 0;
103
104 wInfo = wInfoSettings = settings->GetValue(SETTING_PLUGIN_INFO_PANEL, 0);
105 if (wInfo == 1)
106 {
107 DEBUG_GENERAL("*** Display welcome page")
108 }
109 else if (wInfo == 2)
110 {
111 DEBUG_GENERAL("*** Display update page")
112 }
113 else if (wInfo != 0)
114 {
115 DEBUG_GENERAL("*** Display info page")
116 }
117
118 if (wInfo != 0)
119 {
120 DEBUG_THREAD("Thread::Set info page (action)");
121
122 s_criticalSectionLocal.Lock();
123 {
124 ::PostMessage(tab->m_plugin->m_hPaneWnd, WM_LAUNCH_INFO, wInfo, NULL);
125 }
126 s_criticalSectionLocal.Unlock();
127
128 if (wInfoSettings == wInfo)
129 {
130 settings->Remove(SETTING_PLUGIN_INFO_PANEL);
131 settings->Write();
132 }
133 }
134 }
135
136 // --------------------------------------------------------------------
137 // Main loop
138 // --------------------------------------------------------------------
139
140 DWORD mainLoopIteration = 1;
141
142 while (!IsMainThreadDone(hMainThread))
143 {
144 CString sMainLoopIteration;
145 sMainLoopIteration.Format(L"%u", mainLoopIteration);
146
147 CString debugText;
148
149 debugText += L"------------------------------------------------------------- -------------------";
150 debugText += L"\nLoop iteration " + sMainLoopIteration;
151 debugText += L"\n----------------------------------------------------------- ---------------------";
152
153 DEBUG_GENERAL(debugText)
154
155 // --------------------------------------------------------------------
156 // Update settings
157 // --------------------------------------------------------------------
158
159 if (!IsMainThreadDone(hMainThread))
160 {
161 DEBUG_THREAD("Thread::Update settings");
162
163 if (configuration->IsValid())
164 {
165 bool isNewDictionaryVersion = false;
166 #ifdef SUPPORT_FILTER
167 bool isNewFilterVersion = false;
168 #endif
169 #ifdef SUPPORT_CONFIG
170 bool isNewConfig = false;
171 #endif
172
173 DEBUG_THREAD("Thread::Update settings (action)");
174
175 settings->ForceConfigurationUpdateOnStart(false);
176
177 if (configuration->IsValidPluginInfoPanel())
178 {
179 settings->SetValue(SETTING_PLUGIN_INFO_PANEL, configuration->GetPlug inInfoPanel());
180 }
181
182 #ifdef SUPPORT_FILTER
183 // Update filter URL list
184 if (configuration->IsValidFilter())
185 {
186 isNewFilterVersion = true;
187 }
188 #endif // SUPPORT_FILTER
189
190 settings->Write();
191
192 configuration->Invalidate();
193
194 #ifdef SUPPORT_FILTER
195 DEBUG_GENERAL("*** before isNewFilterVersion");
196
197 // Update filters, if needed (5 days * (random() * 0.4 + 0.8))
198 if (isNewFilterVersion)
199 {
200
201 DEBUG_GENERAL("*** before CheckFilterAndDownload");
202 settings->RefreshFilterlist();
203
204
205 settings->Write();
206
207 tab->OnUpdate();
208 }
209 #endif // SUPPORT_FILTER
210 }
211 }
212
213
214 // ----------------------------------------------------------------
215 // End loop
216 // ----------------------------------------------------------------
217
218 if (!IsMainThreadDone(hMainThread))
219 {
220 bool isDone = false;
221 DWORD sleepLoopIteration = 1;
222
223 // Sleep loop
224 while (!isDone && !IsMainThreadDone(hMainThread))
225 {
226 // Non-hanging sleep
227 Sleep(5000);
228
229 if (sleepLoopIteration++ % (TIMER_THREAD_SLEEP_USER_REGISTRATION) == 0 )
230 {
231 isDone = true;
232 }
233 }
234 }
235
236 mainLoopIteration++;
237 }
238
239 return 0;
240 }
241
242
243 HANDLE CPluginClass::GetMainThreadHandle()
244 {
245 HANDLE handle = NULL;
246
247 s_criticalSectionLocal.Lock();
248 {
249 handle = s_hMainThread;
250 }
251 s_criticalSectionLocal.Unlock();
252
253 return handle;
254 }
255
256
257 bool CPluginClass::IsMainThreadDone(HANDLE mainThread)
258 {
259 bool isDone = false;
260
261 s_criticalSectionLocal.Lock();
262 {
263 isDone = s_isMainThreadDone || mainThread != s_hMainThread;
264 }
265 s_criticalSectionLocal.Unlock();
266
267 return isDone;
268 }
OLDNEW

Powered by Google App Engine
This is Rietveld