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

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

Issue 11013110: Cleanup (Closed)
Left Patch Set: More refactoring. Removing main thread, tab counting. Implementing SetPref and GetPref. Addressing … Created July 9, 2013, 12:59 p.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:
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginConfiguration.h ('k') | src/plugin/PluginDebug.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
(no file at all)
1 #include "PluginStdAfx.h"
2
3 #include "PluginConfiguration.h"
4 #include "PluginClient.h"
5 #include "PluginIniFile.h"
6 #include "PluginSettings.h"
7 #include "PluginSystem.h"
8 #include "PluginHttpRequest.h"
9
10
11 CPluginConfiguration::CPluginConfiguration() : m_pluginInfoPanel(0)
12 {
13 Invalidate();
14 }
15
16
17 void CPluginConfiguration::Invalidate()
18 {
19 m_isValid = false;
20 m_isValidUserId = false;
21 m_isValidPluginActivated = false;
22 m_isValidPluginActivateEnabled = false;
23 m_isValidPluginExpired = false;
24 m_isValidPluginInfoPanel = false;
25 m_isValidDictionary = false;
26 #ifdef SUPPORT_FILTER
27 m_isValidFilter = false;
28 #endif
29 #ifdef SUPPORT_WHITELIST
30 m_isValidWhiteList = false;
31 #endif
32 #ifdef SUPPORT_CONFIG
33 m_isValidConfig = false;
34 #endif
35 }
36
37
38 bool CPluginConfiguration::Download()
39 {
40 return true;
41 // The following code in this method is kepy for reference only. Remove it whe n the
42 // functionality has been implemented elsewhere (if not removed completely)
43 CPluginSystem* system = CPluginSystem::GetInstance();
44
45 bool isOk = true;
46
47 m_isValid = false;
48
49 CPluginHttpRequest httpRequest(USERS_SCRIPT_SETTINGS);
50
51 CPluginSettings* settings = CPluginSettings::GetInstance();
52
53 settings->RefreshTab();
54
55 DEBUG_GENERAL("*** Downloading settings");
56
57 Invalidate();
58
59 httpRequest.AddPluginId();
60
61 httpRequest.Add("enabled", settings->GetPluginEnabled() ? "true":"false");
62 httpRequest.Add("lang", settings->GetString(SETTING_LANGUAGE, "err"));
63 httpRequest.Add("ie", system->GetBrowserVersion());
64 httpRequest.Add("ielang", system->GetBrowserLanguage());
65
66 httpRequest.AddOsInfo();
67
68 httpRequest.Add("errors", settings->GetErrorList());
69
70 httpRequest.Add("dicv", settings->GetValue(SETTING_DICTIONARY_VERSION, 0));
71
72 #ifdef SUPPORT_CONFIG
73 httpRequest.Add("configv", settings->GetValue(SETTING_CONFIG_VERSION, 0));
74 #endif
75
76 if (!isOk)
77 {
78 return false;
79 }
80
81 if (!httpRequest.Send(false))
82 {
83 DEBUG_ERROR("Configuration::Download - Failed downloading settings");
84 return false;
85 }
86
87 if (!httpRequest.IsValidResponse())
88 {
89 DEBUG_ERROR("Configuration::Download - Invalid settings response");
90 DEBUG_ERROR("Configuration::Download\n\n" + httpRequest.GetResponseText() + "\n");
91 return false;
92 }
93
94 const std::auto_ptr<CPluginIniFile>& iniFile = httpRequest.GetResponseFile();
95
96 // Unpack settings
97 CPluginIniFile::TSectionData settingsData = iniFile->GetSectionData("Settings" );
98 CPluginIniFile::TSectionData::iterator it;
99
100 it = settingsData.find("userid");
101 if (it != settingsData.end())
102 {
103 m_userId = it->second;
104 DEBUG_SETTINGS("Settings::Configuration user id:" + it->second);
105 }
106
107 it = settingsData.find("dictionary");
108 if (it != settingsData.end())
109 {
110 m_dictionaryUrl = it->second;
111 DEBUG_SETTINGS("Settings::Configuration dictionary url:" + it->second);
112 }
113
114 it = settingsData.find("dictionaryv");
115 if (it != settingsData.end())
116 {
117 m_dictionaryVersion = atoi(it->second);
118 DEBUG_SETTINGS("Settings::Configuration dictionary version:" + it->second);
119 }
120
121 m_isValidUserId =
122 settingsData.find("userid") != settingsData.end();
123
124 m_isValidDictionary =
125 settingsData.find("dictionary") != settingsData.end() &&
126 settingsData.find("dictionaryv") != settingsData.end();
127
128 it = settingsData.find("plugininfopanel");
129 if (it != settingsData.end())
130 {
131 m_isValidPluginInfoPanel = true;
132 m_pluginInfoPanel = atoi(it->second);
133 DEBUG_SETTINGS("Settings::Configuration plugin info panel:" + it->second);
134 }
135
136 #ifdef SUPPORT_CONFIG
137
138 it = settingsData.find("configurl");
139 if (it != settingsData.end())
140 {
141 m_isValidConfig = true;
142 m_configUrl = it->second;
143
144 DEBUG_SETTINGS("Settings::Configuration file url:" + it->second);
145 }
146
147 it = settingsData.find("configversion");
148 if (it != settingsData.end())
149 {
150 m_configVersion = atoi(it->second);
151
152 DEBUG_SETTINGS("Settings::Configuration file version:" + it->second);
153 }
154 else
155 {
156 m_isValidConfig = false;
157 }
158
159 #endif // SUPPORT_CONFIG
160
161 it = settingsData.find("registration");
162 if (it != settingsData.end())
163 {
164 m_isPluginRegistered = it->second == "true";
165 DEBUG_SETTINGS("Settings::Configuration registration detected:" + it->second );
166 }
167
168 m_adBlockLimit = -1;
169 it = settingsData.find("adblocklimit");
170 if (it != settingsData.end())
171 {
172 m_adBlockLimit = atoi(it->second);
173 DEBUG_SETTINGS("Settings::Configuration adblocklimit detected:" + it->second );
174 }
175
176 m_isValid = isOk;
177
178 return isOk;
179 }
180
181
182 bool CPluginConfiguration::IsValid() const
183 {
184 // Since we don't need the settings to be of any specific kind, we just assume they are always valid
185 // This file will be refactored in future.
186 return true;
187 }
188
189
190 bool CPluginConfiguration::IsValidUserId() const
191 {
192 return m_isValidUserId;
193 }
194
195
196
197 bool CPluginConfiguration::IsValidPluginExpired() const
198 {
199 return m_isValidPluginExpired;
200 }
201
202
203 bool CPluginConfiguration::IsPluginActivated() const
204 {
205 return m_isPluginActivated;
206 }
207
208 bool CPluginConfiguration::IsPluginRegistered() const
209 {
210 return m_isPluginRegistered;
211 }
212
213 int CPluginConfiguration::GetAdBlockLimit() const
214 {
215 return m_adBlockLimit;
216 }
217
218
219 bool CPluginConfiguration::IsPluginActivateEnabled() const
220 {
221 return m_isPluginActivateEnabled;
222 }
223
224
225 bool CPluginConfiguration::IsPluginExpired() const
226 {
227 return m_isPluginExpired;
228 }
229
230
231 bool CPluginConfiguration::IsValidPluginInfoPanel() const
232 {
233 return m_isValidPluginInfoPanel;
234 }
235
236 #ifdef SUPPORT_WHITELIST
237
238 bool CPluginConfiguration::IsValidWhiteList() const
239 {
240 return m_isValidWhiteList;
241 }
242
243 #endif // SUPPORT_WHITELIST
244
245 #ifdef SUPPORT_FILTER
246
247 bool CPluginConfiguration::IsValidFilter() const
248 {
249 // We don't use configuration for now, so filters are always valid
250 // return m_isValidFilter;
251 return true;
252 }
253
254 #endif // SUPPORT_FILTER
255
256 #ifdef SUPPORT_CONFIG
257
258 bool CPluginConfiguration::IsValidConfig() const
259 {
260 return m_isValidConfig;
261 }
262
263 #endif // SUPPORT_CONFIG
264
265 CString CPluginConfiguration::GetUserId() const
266 {
267 return m_userId;
268 }
269
270
271 int CPluginConfiguration::GetPluginInfoPanel() const
272 {
273 return m_pluginInfoPanel;
274 }
275
276
277 int CPluginConfiguration::GetDictionaryVersion() const
278 {
279 return m_dictionaryVersion;
280 }
281
282
283 CString CPluginConfiguration::GetDictionaryUrl() const
284 {
285 return m_dictionaryUrl;
286 }
287
288
289 #ifdef SUPPORT_WHITELIST
290
291
292 #endif // SUPPORT_WHITELIST
293
294 #ifdef SUPPORT_CONFIG
295
296 CString CPluginConfiguration::GetConfigUrl() const
297 {
298 return m_configUrl;
299 }
300
301 int CPluginConfiguration::GetConfigVersion() const
302 {
303 return m_configVersion;
304 }
305
306 #endif // SUPPORT_CONFIG
307
308
309 #ifdef PRODUCT_AIDOINLINE
310 CString CPluginConfiguration::GetCollectedStatus() const
311 {
312 return m_collectedStatus;
313 }
314 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld