OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ | 5 #ifndef CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ |
6 #define CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ | 6 #define CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // will notify when done by calling the DoneScanning method of |observer_|. | 134 // will notify when done by calling the DoneScanning method of |observer_|. |
135 void ScanNow(ModulesVector* list); | 135 void ScanNow(ModulesVector* list); |
136 | 136 |
137 // Sets |per_module_delay_| to zero, causing the modules to be inspected | 137 // Sets |per_module_delay_| to zero, causing the modules to be inspected |
138 // in realtime. | 138 // in realtime. |
139 void SetPerModuleDelayToZero(); | 139 void SetPerModuleDelayToZero(); |
140 | 140 |
141 private: | 141 private: |
142 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); | 142 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); |
143 | 143 |
144 // This function enumerates all modules in the blocking pool. Once the list of | 144 // This function posts a task to enumerate all modules asynchronously. Once |
145 // module filenames is populated it posts a delayed task to call | 145 // the list of module filenames is populated, a delayed task is posted to scan |
146 // ScanImplDelay for the first module. | 146 // the first module. |
147 void ScanImplStart(); | 147 void ScanImplStart(); |
148 | 148 |
149 // Immediately posts a CONTINUE_ON_SHUTDOWN task to ScanImplModule for the | |
150 // given module. This ping-ponging is because the blocking pool does not | |
151 // offer a delayed CONTINUE_ON_SHUTDOWN task. | |
152 // TODO(chrisha): When the new scheduler enables delayed CONTINUE_ON_SHUTDOWN | |
153 // tasks, simplify this logic. | |
154 void ScanImplDelay(size_t index); | |
155 | |
156 // Inspects the module in |enumerated_modules_| at the given |index|. Gets | 149 // Inspects the module in |enumerated_modules_| at the given |index|. Gets |
157 // module information, normalizes it, and collapses the path. This is an | 150 // module information, normalizes it, and collapses the path. This is an |
158 // expensive operation and non-critical. Posts a delayed task to ScanImplDelay | 151 // expensive operation and non-critical. Posts a delayed task to ScanImplDelay |
159 // for the next module. When all modules are finished forwards directly to | 152 // for the next module. When all modules are finished forwards directly to |
160 // ScanImplFinish. | 153 // ScanImplFinish. |
161 void ScanImplModule(size_t index); | 154 void ScanImplModule(size_t index); |
162 | 155 |
163 // Collects metrics and notifies the observer that the enumeration is complete | 156 // Collects metrics and notifies the observer that the enumeration is complete |
164 // by invoking DoneScanning on the UI thread. | 157 // by invoking DoneScanning on the UI thread. |
165 void ScanImplFinish(); | 158 void ScanImplFinish(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // based on the |path_mapping_| vector. | 196 // based on the |path_mapping_| vector. |
204 void CollapsePath(Module* module); | 197 void CollapsePath(Module* module); |
205 | 198 |
206 // Reports (via UMA) a handful of high-level metrics regarding third party | 199 // Reports (via UMA) a handful of high-level metrics regarding third party |
207 // modules in this process. Called by ScanImplFinish. | 200 // modules in this process. Called by ScanImplFinish. |
208 void ReportThirdPartyMetrics(); | 201 void ReportThirdPartyMetrics(); |
209 | 202 |
210 // The typedef for the vector that maps a regular file path to %env_var%. | 203 // The typedef for the vector that maps a regular file path to %env_var%. |
211 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; | 204 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; |
212 | 205 |
206 // The TaskRunner to perform work in the background. | |
207 const scoped_refptr<base::TaskRunner> background_task_runner_; | |
208 | |
213 // The vector of paths to %env_var%, used to account for differences in | 209 // The vector of paths to %env_var%, used to account for differences in |
214 // where people keep there files, c:\windows vs. d:\windows, etc. | 210 // where people keep there files, c:\windows vs. d:\windows, etc. |
215 PathMapping path_mapping_; | 211 PathMapping path_mapping_; |
216 | 212 |
217 // The vector containing all the enumerated modules (loaded and modules of | 213 // The vector containing all the enumerated modules (loaded and modules of |
218 // interest). | 214 // interest). |
219 ModulesVector* enumerated_modules_; | 215 ModulesVector* enumerated_modules_; |
220 | 216 |
221 // The observer, which needs to be notified when the scan is complete. | 217 // The observer, which needs to be notified when the scan is complete. |
222 EnumerateModulesModel* observer_; | 218 EnumerateModulesModel* observer_; |
(...skipping 18 matching lines...) Expand all Loading... | |
241 // both currently loaded modules (called DLLs on Windows) and modules 'of | 237 // both currently loaded modules (called DLLs on Windows) and modules 'of |
242 // interest', such as WinSock LSP modules. This class also marks each module | 238 // interest', such as WinSock LSP modules. This class also marks each module |
243 // as benign or suspected bad or outright bad, using a supplied blacklist that | 239 // as benign or suspected bad or outright bad, using a supplied blacklist that |
244 // is currently hard-coded. | 240 // is currently hard-coded. |
245 // | 241 // |
246 // To use this class, grab the singleton pointer and call ScanNow(). | 242 // To use this class, grab the singleton pointer and call ScanNow(). |
247 // Then wait to get notified through MODULE_LIST_ENUMERATED when the list is | 243 // Then wait to get notified through MODULE_LIST_ENUMERATED when the list is |
248 // ready. | 244 // ready. |
249 // | 245 // |
250 // The member functions of this class may only be used from the UI thread. The | 246 // The member functions of this class may only be used from the UI thread. The |
251 // bulk of the work is actually performed in the blocking pool with | 247 // bulk of the work is actually performed asynchronously in TaskScheduler with |
252 // CONTINUE_ON_SHUTDOWN semantics, as the WinCrypt functions can effectively | 248 // CONTINUE_ON_SHUTDOWN semantics, as the WinCrypt functions can effectively |
253 // block arbitrarily during shutdown. | 249 // block arbitrarily during shutdown. |
254 // | 250 // |
255 // TODO(chrisha): If this logic is ever extended to other platforms, then make | 251 // TODO(chrisha): If this logic is ever extended to other platforms, then make |
256 // this file generic for all platforms, and remove the precompiler logic in | 252 // this file generic for all platforms, and remove the precompiler logic in |
257 // app_menu_icon_controller.*. | 253 // app_menu_icon_controller.*. |
258 class EnumerateModulesModel { | 254 class EnumerateModulesModel { |
259 public: | 255 public: |
260 // UMA histogram constants. | 256 // UMA histogram constants. |
261 enum UmaModuleConflictHistogramOptions { | 257 enum UmaModuleConflictHistogramOptions { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 EnumerateModulesModel(); | 330 EnumerateModulesModel(); |
335 ~EnumerateModulesModel(); | 331 ~EnumerateModulesModel(); |
336 | 332 |
337 // Called on the UI thread when the helper class is done scanning. The | 333 // Called on the UI thread when the helper class is done scanning. The |
338 // ModuleEnumerator that calls this must not do any work after causing this | 334 // ModuleEnumerator that calls this must not do any work after causing this |
339 // function to be called, as the EnumerateModulesModel may delete the | 335 // function to be called, as the EnumerateModulesModel may delete the |
340 // ModuleEnumerator. | 336 // ModuleEnumerator. |
341 void DoneScanning(); | 337 void DoneScanning(); |
342 | 338 |
343 // The vector containing all the modules enumerated. Will be normalized and | 339 // The vector containing all the modules enumerated. Will be normalized and |
344 // any bad modules will be marked. Written to from the blocking pool by the | 340 // any bad modules will be marked. Written to from the background TaskRunner |
345 // |module_enumerator_|, read from on the UI thread by this class. | 341 // by |
342 // the |module_enumerator_|, read from on the UI thread by this class. | |
Finnur
2017/02/21 10:45:55
nit: These two lines can be consolidated.
fdoray
2017/02/22 18:53:06
Done.
| |
346 ModuleEnumerator::ModulesVector enumerated_modules_; | 343 ModuleEnumerator::ModulesVector enumerated_modules_; |
347 | 344 |
348 // The object responsible for enumerating the modules in the blocking pool. | 345 // The object responsible for enumerating the modules on a background |
349 // Only used from the UI thread. This ends up internally doing its work in the | 346 // TaskRunner. Only accessed from the UI thread. |
350 // blocking pool. | |
351 std::unique_ptr<ModuleEnumerator> module_enumerator_; | 347 std::unique_ptr<ModuleEnumerator> module_enumerator_; |
352 | 348 |
353 // Whether the conflict notification has been acknowledged by the user. Only | 349 // Whether the conflict notification has been acknowledged by the user. Only |
354 // modified on the UI thread. | 350 // modified on the UI thread. |
355 bool conflict_notification_acknowledged_; | 351 bool conflict_notification_acknowledged_; |
356 | 352 |
357 // The number of confirmed bad modules (not including suspected bad ones) | 353 // The number of confirmed bad modules (not including suspected bad ones) |
358 // found during last scan. Only modified on the UI thread. | 354 // found during last scan. Only modified on the UI thread. |
359 int confirmed_bad_modules_detected_; | 355 int confirmed_bad_modules_detected_; |
360 | 356 |
361 // The number of bad modules the user needs to be aggressively notified about. | 357 // The number of bad modules the user needs to be aggressively notified about. |
362 // Only modified on the UI thread. | 358 // Only modified on the UI thread. |
363 int modules_to_notify_about_; | 359 int modules_to_notify_about_; |
364 | 360 |
365 // The number of suspected bad modules (not including confirmed bad ones) | 361 // The number of suspected bad modules (not including confirmed bad ones) |
366 // found during last scan. Only modified on the UI thread. | 362 // found during last scan. Only modified on the UI thread. |
367 int suspected_bad_modules_detected_; | 363 int suspected_bad_modules_detected_; |
368 | 364 |
369 base::ObserverList<Observer> observers_; | 365 base::ObserverList<Observer> observers_; |
370 | 366 |
371 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); | 367 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); |
372 }; | 368 }; |
373 | 369 |
374 #endif // CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ | 370 #endif // CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ |
OLD | NEW |