| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // enumeration is complete. |observer| must outlive the ModuleEnumerator. | 148 // enumeration is complete. |observer| must outlive the ModuleEnumerator. |
| 149 explicit ModuleEnumerator(EnumerateModulesModel* observer); | 149 explicit ModuleEnumerator(EnumerateModulesModel* observer); |
| 150 | 150 |
| 151 ~ModuleEnumerator(); | 151 ~ModuleEnumerator(); |
| 152 | 152 |
| 153 // Start scanning the loaded module list (if a scan is not already in | 153 // Start scanning the loaded module list (if a scan is not already in |
| 154 // progress). This function does not block while reading the module list and | 154 // progress). This function does not block while reading the module list and |
| 155 // will notify when done by calling the DoneScanning method of |observer_|. | 155 // will notify when done by calling the DoneScanning method of |observer_|. |
| 156 void ScanNow(ModulesVector* list); | 156 void ScanNow(ModulesVector* list); |
| 157 | 157 |
| 158 // Sets |per_module_delay_| to zero, causing the modules to be inspected |
| 159 // in realtime. |
| 160 void SetPerModuleDelayToZero(); |
| 161 |
| 158 private: | 162 private: |
| 159 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); | 163 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); |
| 160 | 164 |
| 161 // This function does the actual file scanning work in the blocking pool. It | 165 // This function enumerates all modules in the blocking pool. Once the list of |
| 162 // enumerates all loaded modules in the process and other modules of interest, | 166 // module filenames is populated it posts a delayed task to call |
| 163 // such as the registered Winsock LSP modules and stores them in | 167 // ScanImplDelay for the first module. |
| 164 // |enumerated_modules_|. It then normalizes the module info and matches them | 168 void ScanImplStart(); |
| 165 // against a blacklist of known bad modules. Finally, notifies the observer | |
| 166 // that the enumeration is complete by invoking DoneScanning. | |
| 167 void ScanImpl(); | |
| 168 | 169 |
| 169 // Enumerate all modules loaded into the Chrome process. | 170 // Immediately posts a CONTINUE_ON_SHUTDOWN task to ScanImplModule for the |
| 171 // given module. This ping-ponging is because the blocking pool does not |
| 172 // offer a delayed CONTINUE_ON_SHUTDOWN task. |
| 173 // TODO(chrisha): When the new scheduler enables delayed CONTINUE_ON_SHUTDOWN |
| 174 // tasks, simplify this logic. |
| 175 void ScanImplDelay(size_t index); |
| 176 |
| 177 // Inspects the module in |enumerated_modules_| at the given |index|. Gets |
| 178 // module information, normalizes it, and collapses the path. This is an |
| 179 // expensive operation and non-critical. Posts a delayed task to ScanImplDelay |
| 180 // for the next module. When all modules are finished forwards directly to |
| 181 // ScanImplFinish. |
| 182 void ScanImplModule(size_t index); |
| 183 |
| 184 // Collects metrics and notifies the observer that the enumeration is complete |
| 185 // by invoking DoneScanning on the UI thread. |
| 186 void ScanImplFinish(); |
| 187 |
| 188 // Enumerate all modules loaded into the Chrome process. Creates empty |
| 189 // entries in |enumerated_modules_| with a populated |location| field. |
| 170 void EnumerateLoadedModules(); | 190 void EnumerateLoadedModules(); |
| 171 | 191 |
| 172 // Enumerate all registered Windows shell extensions. | 192 // Enumerate all registered Windows shell extensions. Creates empty |
| 193 // entries in |enumerated_modules_| with a populated |location| field. |
| 173 void EnumerateShellExtensions(); | 194 void EnumerateShellExtensions(); |
| 174 | 195 |
| 175 // Enumerate all registered Winsock LSP modules. | 196 // Enumerate all registered Winsock LSP modules. Creates empty |
| 197 // entries in |enumerated_modules_| with a populated |location| field. |
| 176 void EnumerateWinsockModules(); | 198 void EnumerateWinsockModules(); |
| 177 | 199 |
| 178 // Reads the registered shell extensions found under |parent| key in the | 200 // Reads the registered shell extensions found under |parent| key in the |
| 179 // registry. | 201 // registry. Creates empty entries in |enumerated_modules_| with a populated |
| 202 // |location| field. |
| 180 void ReadShellExtensions(HKEY parent); | 203 void ReadShellExtensions(HKEY parent); |
| 181 | 204 |
| 182 // Given a |module|, initializes the structure and loads additional | 205 // Given a |module|, initializes the structure and loads additional |
| 183 // information using the location field of the module. | 206 // information using the location field of the module. |
| 184 void PopulateModuleInformation(Module* module); | 207 void PopulateModuleInformation(Module* module); |
| 185 | 208 |
| 186 // Checks the module list to see if a |module| of the same type, location | 209 // Checks the module list to see if a |module| of the same type, location |
| 187 // and name has been added before and if so, increments its duplication | 210 // and name has been added before and if so, increments its duplication |
| 188 // counter. If it doesn't appear in the list, it is added. | 211 // counter. If it doesn't appear in the list, it is added. |
| 189 void AddToListWithoutDuplicating(const Module&); | 212 void AddToListWithoutDuplicating(const Module&); |
| 190 | 213 |
| 191 // Builds up a vector of path values mapping to environment variable, | 214 // Builds up a vector of path values mapping to environment variable, |
| 192 // with pairs like [c:\windows\, %systemroot%]. This is later used to | 215 // with pairs like [c:\windows\, %systemroot%]. This is later used to |
| 193 // collapse paths like c:\windows\system32 into %systemroot%\system32, which | 216 // collapse paths like c:\windows\system32 into %systemroot%\system32, which |
| 194 // we can use for comparison against our blacklist (which uses only env vars). | 217 // we can use for comparison against our blacklist (which uses only env vars). |
| 195 // NOTE: The vector will not contain an exhaustive list of environment | 218 // NOTE: The vector will not contain an exhaustive list of environment |
| 196 // variables, only the ones currently found on the blacklist or ones that are | 219 // variables, only the ones currently found on the blacklist or ones that are |
| 197 // likely to appear there. | 220 // likely to appear there. |
| 198 void PreparePathMappings(); | 221 void PreparePathMappings(); |
| 199 | 222 |
| 200 // For a given |module|, collapse the path from c:\windows to %systemroot%, | 223 // For a given |module|, collapse the path from c:\windows to %systemroot%, |
| 201 // based on the |path_mapping_| vector. | 224 // based on the |path_mapping_| vector. |
| 202 void CollapsePath(Module* module); | 225 void CollapsePath(Module* module); |
| 203 | 226 |
| 204 // Reports (via UMA) a handful of high-level metrics regarding third party | 227 // Reports (via UMA) a handful of high-level metrics regarding third party |
| 205 // modules in this process. Called by ScanImpl after modules have been | 228 // modules in this process. Called by ScanImplFinish. |
| 206 // enumerated and processed. | |
| 207 void ReportThirdPartyMetrics(); | 229 void ReportThirdPartyMetrics(); |
| 208 | 230 |
| 209 // The typedef for the vector that maps a regular file path to %env_var%. | 231 // The typedef for the vector that maps a regular file path to %env_var%. |
| 210 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; | 232 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; |
| 211 | 233 |
| 212 // The vector of paths to %env_var%, used to account for differences in | 234 // The vector of paths to %env_var%, used to account for differences in |
| 213 // where people keep there files, c:\windows vs. d:\windows, etc. | 235 // where people keep there files, c:\windows vs. d:\windows, etc. |
| 214 PathMapping path_mapping_; | 236 PathMapping path_mapping_; |
| 215 | 237 |
| 216 // The vector containing all the enumerated modules (loaded and modules of | 238 // The vector containing all the enumerated modules (loaded and modules of |
| 217 // interest). | 239 // interest). |
| 218 ModulesVector* enumerated_modules_; | 240 ModulesVector* enumerated_modules_; |
| 219 | 241 |
| 220 // The observer, which needs to be notified when the scan is complete. | 242 // The observer, which needs to be notified when the scan is complete. |
| 221 EnumerateModulesModel* observer_; | 243 EnumerateModulesModel* observer_; |
| 222 | 244 |
| 245 // The delay that is observed between module inspection tasks. This is |
| 246 // currently 1 second, which means it takes several minutes to iterate over |
| 247 // all modules on average. |
| 248 base::TimeDelta per_module_delay_; |
| 249 |
| 250 // The amount of time taken for on-disk module inspection. Reported in |
| 251 // ScanImplFinish. |
| 252 base::TimeDelta enumeration_inspection_time_; |
| 253 |
| 254 // The total amount of time taken for module enumeration. Reported in |
| 255 // ScanImplFinish. |
| 256 base::TimeDelta enumeration_total_time_; |
| 257 |
| 223 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); | 258 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); |
| 224 }; | 259 }; |
| 225 | 260 |
| 226 // This is a singleton class that enumerates all modules loaded into Chrome, | 261 // This is a singleton class that enumerates all modules loaded into Chrome, |
| 227 // both currently loaded modules (called DLLs on Windows) and modules 'of | 262 // both currently loaded modules (called DLLs on Windows) and modules 'of |
| 228 // interest', such as WinSock LSP modules. This class also marks each module | 263 // interest', such as WinSock LSP modules. This class also marks each module |
| 229 // as benign or suspected bad or outright bad, using a supplied blacklist that | 264 // as benign or suspected bad or outright bad, using a supplied blacklist that |
| 230 // is currently hard-coded. | 265 // is currently hard-coded. |
| 231 // | 266 // |
| 232 // To use this class, grab the singleton pointer and call ScanNow(). | 267 // To use this class, grab the singleton pointer and call ScanNow(). |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 int suspected_bad_modules_detected() const; | 323 int suspected_bad_modules_detected() const; |
| 289 | 324 |
| 290 // Returns the number of confirmed bad modules found in the last scan. | 325 // Returns the number of confirmed bad modules found in the last scan. |
| 291 // Returns 0 if no scan has taken place yet. | 326 // Returns 0 if no scan has taken place yet. |
| 292 int confirmed_bad_modules_detected() const; | 327 int confirmed_bad_modules_detected() const; |
| 293 | 328 |
| 294 // Returns how many modules to notify the user about. | 329 // Returns how many modules to notify the user about. |
| 295 int modules_to_notify_about() const; | 330 int modules_to_notify_about() const; |
| 296 | 331 |
| 297 // Checks to see if a scanning task should be started and sets one off, if so. | 332 // Checks to see if a scanning task should be started and sets one off, if so. |
| 333 // This will cause ScanNow to be invoked in background mode. |
| 298 void MaybePostScanningTask(); | 334 void MaybePostScanningTask(); |
| 299 | 335 |
| 300 // Asynchronously start the scan for the loaded module list. | 336 // Asynchronously start the scan for the loaded module list. If |
| 301 void ScanNow(); | 337 // |background_mode| is true the scan will happen slowly over a process of |
| 338 // minutes, spread across dozens or even hundreds of delayed tasks. Otherwise |
| 339 // the processing will occur in a single task. |
| 340 void ScanNow(bool background_mode); |
| 302 | 341 |
| 303 // Gets the whole module list as a ListValue. | 342 // Gets the whole module list as a ListValue. |
| 304 base::ListValue* GetModuleList(); | 343 base::ListValue* GetModuleList(); |
| 305 | 344 |
| 306 // Returns the site to which the user should be taken when the conflict bubble | 345 // Returns the site to which the user should be taken when the conflict bubble |
| 307 // or app menu item is clicked. For now this is simply chrome://conflicts, | 346 // or app menu item is clicked. For now this is simply chrome://conflicts, |
| 308 // which contains detailed information about conflicts. Returns an empty URL | 347 // which contains detailed information about conflicts. Returns an empty URL |
| 309 // if there are no conficts. May only be called on UI thread. | 348 // if there are no conficts. May only be called on UI thread. |
| 310 GURL GetConflictUrl(); | 349 GURL GetConflictUrl(); |
| 311 | 350 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // The number of suspected bad modules (not including confirmed bad ones) | 386 // The number of suspected bad modules (not including confirmed bad ones) |
| 348 // found during last scan. Only modified on the UI thread. | 387 // found during last scan. Only modified on the UI thread. |
| 349 int suspected_bad_modules_detected_; | 388 int suspected_bad_modules_detected_; |
| 350 | 389 |
| 351 base::ObserverList<Observer> observers_; | 390 base::ObserverList<Observer> observers_; |
| 352 | 391 |
| 353 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); | 392 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); |
| 354 }; | 393 }; |
| 355 | 394 |
| 356 #endif // CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ | 395 #endif // CHROME_BROWSER_WIN_ENUMERATE_MODULES_MODEL_H_ |
| OLD | NEW |