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_ENUMERATE_MODULES_MODEL_WIN_H_ | 5 #ifndef CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ |
6 #define CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ | 6 #define CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/callback.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/observer_list.h" |
15 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
16 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "url/gurl.h" | 20 #include "url/gurl.h" |
19 | 21 |
20 class EnumerateModulesModel; | 22 class EnumerateModulesModel; |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 class FilePath; | 25 class FilePath; |
24 class ListValue; | 26 class ListValue; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // The duplicate count within each category of modules. | 110 // The duplicate count within each category of modules. |
109 int duplicate_count; | 111 int duplicate_count; |
110 // Whether this module has been normalized (necessary before checking it | 112 // Whether this module has been normalized (necessary before checking it |
111 // against blacklist). | 113 // against blacklist). |
112 bool normalized; | 114 bool normalized; |
113 }; | 115 }; |
114 | 116 |
115 // A vector typedef of all modules enumerated. | 117 // A vector typedef of all modules enumerated. |
116 typedef std::vector<Module> ModulesVector; | 118 typedef std::vector<Module> ModulesVector; |
117 | 119 |
118 // A structure we populate with the blacklist entries. | |
119 struct BlacklistEntry { | |
120 const char* filename; | |
121 const char* location; | |
122 const char* desc_or_signer; | |
123 const char* version_from; // Version where conflict started. | |
124 const char* version_to; // First version that works. | |
125 OperatingSystem os; // Bitmask, representing what OS this entry applies to. | |
126 RecommendedAction help_tip; | |
127 }; | |
128 | |
129 // A static function that normalizes the module information in the |module| | 120 // A static function that normalizes the module information in the |module| |
130 // struct. Module information needs to be normalized before comparing against | 121 // struct. Module information needs to be normalized before comparing against |
131 // the blacklist. This is because the same module can be described in many | 122 // the blacklist. This is because the same module can be described in many |
132 // different ways, ie. file paths can be presented in long/short name form, | 123 // different ways, ie. file paths can be presented in long/short name form, |
133 // and are not case sensitive on Windows. Also, the version string returned | 124 // and are not case sensitive on Windows. Also, the version string returned |
134 // can include appended text, which we don't want to use during comparison | 125 // can include appended text, which we don't want to use during comparison |
135 // against the blacklist. | 126 // against the blacklist. |
136 static void NormalizeModule(Module* module); | 127 static void NormalizeModule(Module* module); |
137 | 128 |
138 // A static function that checks whether |module| has been |blacklisted|. | |
139 static ModuleStatus Match(const Module& module, | |
140 const BlacklistEntry& blacklisted); | |
141 | |
142 explicit ModuleEnumerator(EnumerateModulesModel* observer); | 129 explicit ModuleEnumerator(EnumerateModulesModel* observer); |
143 | 130 |
144 // Start scanning the loaded module list (if a scan is not already in | 131 // Start scanning the loaded module list (if a scan is not already in |
145 // progress). This function does not block while reading the module list | 132 // progress). This function does not block while reading the module list |
146 // (unless we are in limited_mode, see below), and will notify when done | 133 // (unless we are in limited_mode, see below), and will notify when done |
147 // through the MODULE_LIST_ENUMERATED notification. | 134 // through the MODULE_LIST_ENUMERATED notification. |
148 // The process will also send MODULE_INCOMPATIBILITY_BADGE_CHANGE to let | 135 // The process will also send MODULE_INCOMPATIBILITY_BADGE_CHANGE to let |
149 // observers know when it is time to update the wrench menu badge. | 136 // observers know when it is time to update the wrench menu badge. |
150 // When in |limited_mode|, this function will not leverage the File thread | 137 // When in |limited_mode|, this function will not leverage the File thread |
151 // to run asynchronously and will therefore block until scanning is done | 138 // to run asynchronously and will therefore block until scanning is done |
152 // (and will also not send out any notifications). | 139 // (and will also not send out any notifications). |
153 void ScanNow(ModulesVector* list, bool limited_mode); | 140 void ScanNow(ModulesVector* list, bool limited_mode); |
154 | 141 |
155 private: | 142 private: |
156 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); | 143 FRIEND_TEST_ALL_PREFIXES(EnumerateModulesTest, CollapsePath); |
157 | 144 |
158 friend class base::RefCountedThreadSafe<ModuleEnumerator>; | 145 friend class base::RefCountedThreadSafe<ModuleEnumerator>; |
159 ~ModuleEnumerator(); | 146 ~ModuleEnumerator(); |
160 | 147 |
161 // The (currently) hard coded blacklist of known bad modules. | |
162 static const BlacklistEntry kModuleBlacklist[]; | |
163 | |
164 // This function does the actual file scanning work on the FILE thread (or | 148 // This function does the actual file scanning work on the FILE thread (or |
165 // block the main thread when in limited_mode). It enumerates all loaded | 149 // block the main thread when in limited_mode). It enumerates all loaded |
166 // modules in the process and other modules of interest, such as the | 150 // modules in the process and other modules of interest, such as the |
167 // registered Winsock LSP modules and stores them in |enumerated_modules_|. | 151 // registered Winsock LSP modules and stores them in |enumerated_modules_|. |
168 // It then normalizes the module info and matches them against a blacklist | 152 // It then normalizes the module info and matches them against a blacklist |
169 // of known bad modules. Finally, it calls ReportBack to let the observer | 153 // of known bad modules. Finally, it calls ReportBack to let the observer |
170 // know we are done. | 154 // know we are done. |
171 void ScanImpl(); | 155 void ScanImpl(); |
172 | 156 |
173 // Enumerate all modules loaded into the Chrome process. | 157 // Enumerate all modules loaded into the Chrome process. |
(...skipping 24 matching lines...) Expand all Loading... |
198 // we can use for comparison against our blacklist (which uses only env vars). | 182 // we can use for comparison against our blacklist (which uses only env vars). |
199 // NOTE: The vector will not contain an exhaustive list of environment | 183 // NOTE: The vector will not contain an exhaustive list of environment |
200 // variables, only the ones currently found on the blacklist or ones that are | 184 // variables, only the ones currently found on the blacklist or ones that are |
201 // likely to appear there. | 185 // likely to appear there. |
202 void PreparePathMappings(); | 186 void PreparePathMappings(); |
203 | 187 |
204 // For a given |module|, collapse the path from c:\windows to %systemroot%, | 188 // For a given |module|, collapse the path from c:\windows to %systemroot%, |
205 // based on the |path_mapping_| vector. | 189 // based on the |path_mapping_| vector. |
206 void CollapsePath(Module* module); | 190 void CollapsePath(Module* module); |
207 | 191 |
208 // Takes each module in the |enumerated_modules_| vector and matches it | |
209 // against a fixed blacklist of bad and suspected bad modules. | |
210 void MatchAgainstBlacklist(); | |
211 | |
212 // This function executes on the UI thread when the scanning and matching | 192 // This function executes on the UI thread when the scanning and matching |
213 // process is done. It notifies the observer. | 193 // process is done. It notifies the observer. |
214 void ReportBack(); | 194 void ReportBack(); |
215 | 195 |
216 // Given a filename, returns the Subject (who signed it) retrieved from | 196 // Given a filename, returns the Subject (who signed it) retrieved from |
217 // the digital signature (Authenticode). | 197 // the digital signature (Authenticode). |
218 base::string16 GetSubjectNameFromDigitalSignature( | 198 base::string16 GetSubjectNameFromDigitalSignature( |
219 const base::FilePath& filename); | 199 const base::FilePath& filename); |
220 | 200 |
| 201 // Reports (via UMA) a handful of high-level metrics regarding third party |
| 202 // modules in this process. Called by ScanImpl after modules have been |
| 203 // enmerated and processed. |
| 204 void ReportThirdPartyMetrics(); |
| 205 |
221 // The typedef for the vector that maps a regular file path to %env_var%. | 206 // The typedef for the vector that maps a regular file path to %env_var%. |
222 typedef std::vector< std::pair<base::string16, base::string16> > PathMapping; | 207 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; |
223 | 208 |
224 // 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 |
225 // where people keep there files, c:\windows vs. d:\windows, etc. | 210 // where people keep there files, c:\windows vs. d:\windows, etc. |
226 PathMapping path_mapping_; | 211 PathMapping path_mapping_; |
227 | 212 |
228 // The vector containing all the enumerated modules (loaded and modules of | 213 // The vector containing all the enumerated modules (loaded and modules of |
229 // interest). | 214 // interest). |
230 ModulesVector* enumerated_modules_; | 215 ModulesVector* enumerated_modules_; |
231 | 216 |
232 // The observer, who needs to be notified when we are done. | 217 // The observers, who need to be notified when the scan is complete. |
233 EnumerateModulesModel* observer_; | 218 EnumerateModulesModel* observer_; |
234 | 219 |
235 // See limited_mode below. | 220 // See limited_mode below. |
236 bool limited_mode_; | 221 bool limited_mode_; |
237 | 222 |
238 // The thread that we need to call back on to report that we are done. | 223 // The thread that we need to call back on to report that we are done. |
239 content::BrowserThread::ID callback_thread_id_; | 224 content::BrowserThread::ID callback_thread_id_; |
240 | 225 |
241 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); | 226 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); |
242 }; | 227 }; |
(...skipping 14 matching lines...) Expand all Loading... |
257 class EnumerateModulesModel { | 242 class EnumerateModulesModel { |
258 public: | 243 public: |
259 // UMA histogram constants. | 244 // UMA histogram constants. |
260 enum UmaModuleConflictHistogramOptions { | 245 enum UmaModuleConflictHistogramOptions { |
261 ACTION_BUBBLE_SHOWN = 0, | 246 ACTION_BUBBLE_SHOWN = 0, |
262 ACTION_BUBBLE_LEARN_MORE, | 247 ACTION_BUBBLE_LEARN_MORE, |
263 ACTION_MENU_LEARN_MORE, | 248 ACTION_MENU_LEARN_MORE, |
264 ACTION_BOUNDARY, // Must be the last value. | 249 ACTION_BOUNDARY, // Must be the last value. |
265 }; | 250 }; |
266 | 251 |
| 252 // Observer class used to receive the list of modules when enumeration is |
| 253 // finished. |
| 254 class Observer { |
| 255 public: |
| 256 // Invoked when EnumerateModulesModel has completed a scan of modules. |
| 257 virtual void OnScanCompleted(bool limited_mode) {} |
| 258 |
| 259 // Invoked when a user has acknowledge incompatible modules found in a |
| 260 // module scan. |
| 261 virtual void OnConflictsAcknowledged() {} |
| 262 |
| 263 protected: |
| 264 virtual ~Observer() = default; |
| 265 }; |
| 266 |
| 267 EnumerateModulesModel(); |
| 268 virtual ~EnumerateModulesModel(); |
| 269 |
| 270 // Returns the singleton instance of this class. |
267 static EnumerateModulesModel* GetInstance(); | 271 static EnumerateModulesModel* GetInstance(); |
268 | 272 |
| 273 // Adds an |observer| to the enumerator. May only be called from the UI thread |
| 274 // and callbacks will also occur on the UI thread. |
| 275 void AddObserver(Observer* observer) { |
| 276 observers_.AddObserver(observer); |
| 277 } |
| 278 |
| 279 // Removes an |observer| from the enumerator. May only be called from the UI |
| 280 // thread and callbacks will also occur on the UI thread. |
| 281 void RemoveObserver(Observer* observer) { |
| 282 observers_.RemoveObserver(observer); |
| 283 } |
| 284 |
269 // Returns true if we should show the conflict notification. The conflict | 285 // Returns true if we should show the conflict notification. The conflict |
270 // notification is only shown once during the lifetime of the process. | 286 // notification is only shown once during the lifetime of the process. |
271 bool ShouldShowConflictWarning() const; | 287 bool ShouldShowConflictWarning() const; |
272 | 288 |
273 // Called when the user has acknowledged the conflict notification. | 289 // Called when the user has acknowledged the conflict notification. |
274 void AcknowledgeConflictNotification(); | 290 void AcknowledgeConflictNotification(); |
275 | 291 |
276 // Returns the number of suspected bad modules found in the last scan. | 292 // Returns the number of suspected bad modules found in the last scan. |
277 // Returns 0 if no scan has taken place yet. | 293 // Returns 0 if no scan has taken place yet. |
278 int suspected_bad_modules_detected() const { | 294 int suspected_bad_modules_detected() const { |
(...skipping 18 matching lines...) Expand all Loading... |
297 } | 313 } |
298 | 314 |
299 // Checks to see if a scanning task should be started and sets one off, if so. | 315 // Checks to see if a scanning task should be started and sets one off, if so. |
300 void MaybePostScanningTask(); | 316 void MaybePostScanningTask(); |
301 | 317 |
302 // Asynchronously start the scan for the loaded module list, except when in | 318 // Asynchronously start the scan for the loaded module list, except when in |
303 // limited_mode (in which case it blocks). | 319 // limited_mode (in which case it blocks). |
304 void ScanNow(); | 320 void ScanNow(); |
305 | 321 |
306 // Gets the whole module list as a ListValue. | 322 // Gets the whole module list as a ListValue. |
307 base::ListValue* GetModuleList() const; | 323 base::ListValue* GetModuleList(); |
308 | 324 |
309 // Gets the Help Center URL for the first *notable* conflict module that we've | 325 // Returns the site to which the user should be taken when the conflict bubble |
310 // elected to notify the user about. | 326 // or app menu item is clicked. For now this is simply chrome://conflicts, |
311 GURL GetFirstNotableConflict(); | 327 // which contains detailed information about conflicts. Returns an empty URL |
| 328 // if there are no conficts. |
| 329 GURL GetConflictUrl(); |
312 | 330 |
313 private: | 331 private: |
314 friend struct base::DefaultSingletonTraits<EnumerateModulesModel>; | |
315 friend class ModuleEnumerator; | 332 friend class ModuleEnumerator; |
316 | 333 |
317 EnumerateModulesModel(); | |
318 virtual ~EnumerateModulesModel(); | |
319 | |
320 // Called on the UI thread when the helper class is done scanning. | 334 // Called on the UI thread when the helper class is done scanning. |
321 void DoneScanning(); | 335 void DoneScanning(); |
322 | 336 |
323 // Constructs a Help Center article URL for help with a particular module. | 337 // Used to protect state that can be accessed from both the UI and FILE |
324 // The module must have the SEE_LINK attribute for |recommended_action| set, | 338 // threads. |
325 // otherwise this returns a blank string. | 339 base::Lock lock_; |
326 GURL ConstructHelpCenterUrl(const ModuleEnumerator::Module& module) const; | |
327 | 340 |
328 // The vector containing all the modules enumerated. Will be normalized and | 341 // The vector containing all the modules enumerated. Will be normalized and |
329 // any bad modules will be marked. | 342 // any bad modules will be marked. Under lock_. |
330 ModuleEnumerator::ModulesVector enumerated_modules_; | 343 ModuleEnumerator::ModulesVector enumerated_modules_; |
331 | 344 |
332 // The object responsible for enumerating the modules on the File thread. | 345 // The object responsible for enumerating the modules on the File thread. |
333 scoped_refptr<ModuleEnumerator> module_enumerator_; | 346 scoped_refptr<ModuleEnumerator> module_enumerator_; |
334 | 347 |
335 // When this singleton object is constructed we go and fire off this timer to | 348 // When MaybePostScanningTask is called this timer is set to start scanning |
336 // start scanning for modules after a certain amount of time has passed. | 349 // modules after a certain amount of time has passed. |
337 base::OneShotTimer check_modules_timer_; | 350 base::OneShotTimer check_modules_timer_; |
338 | 351 |
339 // While normally |false|, this mode can be set to indicate that the scanning | 352 // While normally |false|, this mode can be set to indicate that the scanning |
340 // process should not rely on certain services normally available to Chrome, | 353 // process should not rely on certain services normally available to Chrome, |
341 // such as the resource bundle and the notification system, not to mention | 354 // such as the resource bundle and the notification system, not to mention |
342 // having multiple threads. This mode is useful during diagnostics, which | 355 // having multiple threads. This mode is useful during diagnostics, which |
343 // runs without firing up all necessary Chrome services first. | 356 // runs without firing up all necessary Chrome services first. |
344 bool limited_mode_; | 357 bool limited_mode_; |
345 | 358 |
346 // True if we are currently scanning for modules. | 359 // True if we are currently scanning for modules. Under lock_. |
347 bool scanning_; | 360 bool scanning_; |
348 | 361 |
349 // Whether the conflict notification has been acknowledged by the user. | 362 // Whether the conflict notification has been acknowledged by the user. |
350 bool conflict_notification_acknowledged_; | 363 bool conflict_notification_acknowledged_; |
351 | 364 |
352 // The number of confirmed bad modules (not including suspected bad ones) | 365 // The number of confirmed bad modules (not including suspected bad ones) |
353 // found during last scan. | 366 // found during last scan. |
354 int confirmed_bad_modules_detected_; | 367 int confirmed_bad_modules_detected_; |
355 | 368 |
356 // The number of bad modules the user needs to be aggressively notified about. | 369 // The number of bad modules the user needs to be aggressively notified about. |
357 int modules_to_notify_about_; | 370 int modules_to_notify_about_; |
358 | 371 |
359 // The number of suspected bad modules (not including confirmed bad ones) | 372 // The number of suspected bad modules (not including confirmed bad ones) |
360 // found during last scan. | 373 // found during last scan. |
361 int suspected_bad_modules_detected_; | 374 int suspected_bad_modules_detected_; |
362 | 375 |
| 376 base::ObserverList<Observer> observers_; |
| 377 |
363 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); | 378 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); |
364 }; | 379 }; |
365 | 380 |
366 #endif // CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ | 381 #endif // CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ |
OLD | NEW |