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_threadsafe.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 void ReportThirdPartyMetrics(); | |
202 | |
221 // 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%. |
222 typedef std::vector< std::pair<base::string16, base::string16> > PathMapping; | 204 typedef std::vector<std::pair<base::string16, base::string16>> PathMapping; |
223 | 205 |
224 // The vector of paths to %env_var%, used to account for differences in | 206 // 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. | 207 // where people keep there files, c:\windows vs. d:\windows, etc. |
226 PathMapping path_mapping_; | 208 PathMapping path_mapping_; |
227 | 209 |
228 // The vector containing all the enumerated modules (loaded and modules of | 210 // The vector containing all the enumerated modules (loaded and modules of |
229 // interest). | 211 // interest). |
230 ModulesVector* enumerated_modules_; | 212 ModulesVector* enumerated_modules_; |
231 | 213 |
232 // The observer, who needs to be notified when we are done. | 214 // The observers, who need to be notified when the scan is complete. |
233 EnumerateModulesModel* observer_; | 215 EnumerateModulesModel* observer_; |
234 | 216 |
235 // See limited_mode below. | 217 // See limited_mode below. |
236 bool limited_mode_; | 218 bool limited_mode_; |
237 | 219 |
238 // The thread that we need to call back on to report that we are done. | 220 // The thread that we need to call back on to report that we are done. |
239 content::BrowserThread::ID callback_thread_id_; | 221 content::BrowserThread::ID callback_thread_id_; |
240 | 222 |
241 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); | 223 DISALLOW_COPY_AND_ASSIGN(ModuleEnumerator); |
242 }; | 224 }; |
(...skipping 14 matching lines...) Expand all Loading... | |
257 class EnumerateModulesModel { | 239 class EnumerateModulesModel { |
258 public: | 240 public: |
259 // UMA histogram constants. | 241 // UMA histogram constants. |
260 enum UmaModuleConflictHistogramOptions { | 242 enum UmaModuleConflictHistogramOptions { |
261 ACTION_BUBBLE_SHOWN = 0, | 243 ACTION_BUBBLE_SHOWN = 0, |
262 ACTION_BUBBLE_LEARN_MORE, | 244 ACTION_BUBBLE_LEARN_MORE, |
263 ACTION_MENU_LEARN_MORE, | 245 ACTION_MENU_LEARN_MORE, |
264 ACTION_BOUNDARY, // Must be the last value. | 246 ACTION_BOUNDARY, // Must be the last value. |
265 }; | 247 }; |
266 | 248 |
249 // Observer class used to receive the list of modules when enumeration is | |
250 // finished. | |
251 class Observer { | |
252 public: | |
253 Observer() {} | |
254 virtual ~Observer() {} | |
255 | |
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 private: | |
264 DISALLOW_COPY_AND_ASSIGN(Observer); | |
265 }; | |
266 | |
267 static EnumerateModulesModel* GetInstance(); | 267 static EnumerateModulesModel* GetInstance(); |
268 | 268 |
269 // Adds an |observer| to the enumerator. May be called from any thread. The | |
270 // callback will be invoked on the thread on which AddObserver was called. | |
271 void AddObserver(Observer* observer) { | |
grt (UTC plus 2)
2016/06/16 18:27:53
are observers always added/removed on the UI threa
chrisha
2016/06/17 20:48:03
They are indeed. Moved to the normal variant.
| |
272 observers_->AddObserver(observer); | |
273 } | |
274 | |
275 // Removes an |observer| from the enumerator. May be called from any thread. | |
276 void RemoveObserver(Observer* observer) { | |
277 observers_->RemoveObserver(observer); | |
278 } | |
279 | |
269 // Returns true if we should show the conflict notification. The conflict | 280 // Returns true if we should show the conflict notification. The conflict |
270 // notification is only shown once during the lifetime of the process. | 281 // notification is only shown once during the lifetime of the process. |
271 bool ShouldShowConflictWarning() const; | 282 bool ShouldShowConflictWarning() const; |
272 | 283 |
273 // Called when the user has acknowledged the conflict notification. | 284 // Called when the user has acknowledged the conflict notification. |
274 void AcknowledgeConflictNotification(); | 285 void AcknowledgeConflictNotification(); |
275 | 286 |
276 // Returns the number of suspected bad modules found in the last scan. | 287 // Returns the number of suspected bad modules found in the last scan. |
277 // Returns 0 if no scan has taken place yet. | 288 // Returns 0 if no scan has taken place yet. |
278 int suspected_bad_modules_detected() const { | 289 int suspected_bad_modules_detected() const { |
(...skipping 20 matching lines...) Expand all Loading... | |
299 // Checks to see if a scanning task should be started and sets one off, if so. | 310 // Checks to see if a scanning task should be started and sets one off, if so. |
300 void MaybePostScanningTask(); | 311 void MaybePostScanningTask(); |
301 | 312 |
302 // Asynchronously start the scan for the loaded module list, except when in | 313 // Asynchronously start the scan for the loaded module list, except when in |
303 // limited_mode (in which case it blocks). | 314 // limited_mode (in which case it blocks). |
304 void ScanNow(); | 315 void ScanNow(); |
305 | 316 |
306 // Gets the whole module list as a ListValue. | 317 // Gets the whole module list as a ListValue. |
307 base::ListValue* GetModuleList() const; | 318 base::ListValue* GetModuleList() const; |
308 | 319 |
309 // Gets the Help Center URL for the first *notable* conflict module that we've | 320 // The user will be taken to this site when the conflict bubble or app menu |
310 // elected to notify the user about. | 321 // item is clicked. For now this simply opens chrome://conflicts, which |
311 GURL GetFirstNotableConflict(); | 322 // contains detailed information about conflicts. Returns an empty URL if |
323 // there are no conficts. | |
324 GURL GetConflictUrl(); | |
312 | 325 |
313 private: | 326 private: |
314 friend struct base::DefaultSingletonTraits<EnumerateModulesModel>; | 327 friend struct base::DefaultSingletonTraits<EnumerateModulesModel>; |
315 friend class ModuleEnumerator; | 328 friend class ModuleEnumerator; |
316 | 329 |
317 EnumerateModulesModel(); | 330 EnumerateModulesModel(); |
318 virtual ~EnumerateModulesModel(); | 331 virtual ~EnumerateModulesModel(); |
319 | 332 |
320 // Called on the UI thread when the helper class is done scanning. | 333 // Called on the UI thread when the helper class is done scanning. |
321 void DoneScanning(); | 334 void DoneScanning(); |
322 | 335 |
323 // Constructs a Help Center article URL for help with a particular module. | |
324 // The module must have the SEE_LINK attribute for |recommended_action| set, | |
325 // otherwise this returns a blank string. | |
326 GURL ConstructHelpCenterUrl(const ModuleEnumerator::Module& module) const; | |
327 | |
328 // The vector containing all the modules enumerated. Will be normalized and | 336 // The vector containing all the modules enumerated. Will be normalized and |
329 // any bad modules will be marked. | 337 // any bad modules will be marked. |
330 ModuleEnumerator::ModulesVector enumerated_modules_; | 338 ModuleEnumerator::ModulesVector enumerated_modules_; |
331 | 339 |
332 // The object responsible for enumerating the modules on the File thread. | 340 // The object responsible for enumerating the modules on the File thread. |
333 scoped_refptr<ModuleEnumerator> module_enumerator_; | 341 scoped_refptr<ModuleEnumerator> module_enumerator_; |
334 | 342 |
335 // When this singleton object is constructed we go and fire off this timer to | 343 // When this singleton object is constructed we go and fire off this timer to |
336 // start scanning for modules after a certain amount of time has passed. | 344 // start scanning for modules after a certain amount of time has passed. |
337 base::OneShotTimer check_modules_timer_; | 345 base::OneShotTimer check_modules_timer_; |
(...skipping 15 matching lines...) Expand all Loading... | |
353 // found during last scan. | 361 // found during last scan. |
354 int confirmed_bad_modules_detected_; | 362 int confirmed_bad_modules_detected_; |
355 | 363 |
356 // The number of bad modules the user needs to be aggressively notified about. | 364 // The number of bad modules the user needs to be aggressively notified about. |
357 int modules_to_notify_about_; | 365 int modules_to_notify_about_; |
358 | 366 |
359 // The number of suspected bad modules (not including confirmed bad ones) | 367 // The number of suspected bad modules (not including confirmed bad ones) |
360 // found during last scan. | 368 // found during last scan. |
361 int suspected_bad_modules_detected_; | 369 int suspected_bad_modules_detected_; |
362 | 370 |
371 scoped_refptr<base::ObserverListThreadSafe<Observer>> observers_; | |
372 | |
363 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); | 373 DISALLOW_COPY_AND_ASSIGN(EnumerateModulesModel); |
364 }; | 374 }; |
365 | 375 |
366 #endif // CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ | 376 #endif // CHROME_BROWSER_ENUMERATE_MODULES_MODEL_WIN_H_ |
OLD | NEW |