Attempting to resolve a race condition with PowerMonitor.
ThreadSanitizer caught multiple instances where PowerMonitor::Get or PowerMonitor::Add/RemoveObserver were being called concurrently with the PowerMonitor constructor in the main thread. These functions access a process-global PowerMontior instance (g_power_monitor), which was not thread safe.
This change adds locks around PowerMonitor creation and deletion, and forces Add/RemoveObserver to be called in a threadsafe manner. It also removes the need to call PowerMonitor::Get.
BUG=268924
Review URL: https://codereview.chromium.org/179923006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262018 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: f65e97e447b789af3a8dc653d8801e8c6f24f935
6 files changed