On Tue, Nov 3, 2009 at 11:49 PM, Paweł Hajdan Jr. <phajdan...@chromium.org>wrote:
> I encountered another problem related to Singletons in unit tests. > PluginService is a Singleton, and it listens to extensions notifications. In > one of my tests when I was using the extensions notifications the > PluginService crashed because I passed NULL as the Extension* - because the > listener I was testing didn't even read that value, but PluginService did > (it was unexpected). > > I tried to fix the issue by adding a shadow AtExitManager to the test which > instantiated PluginService (resource_dispatcher_host_unittest.cc). And then > another crash appeared on Windows: NPAPI::PluginList is a LazyInstance, > which means that the shadow AtExitManager destroyed it, but it didn't > re-instantiate itself the next time it was used. > > Is there a big difference between a Singleton and LazyInstance? I was > thinking about making NPAPI::PluginList a Singleton instead... > It's fine to switch PluginList to Singleton instead of LazyInstance. The big benefit of LazyInstance is using it with TLS objects and not using up a slot unless the code runs. In this case, that's not the case since PluginList isn't stored per thread. > > By the way, I have a more general fix in the queue (an unwanted Singleton > detector). If you're interested, please star http://crbug.com/12710. It > seems that the most recent gtest (1.4.0) has necessary support. > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---