diff options
author | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 17:28:39 +0000 |
---|---|---|
committer | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 17:28:39 +0000 |
commit | f65e97e447b789af3a8dc653d8801e8c6f24f935 (patch) | |
tree | 40a67136a65931462cbf1a39fc03844b43117d11 /net/url_request | |
parent | fb4341cd131ff6143ac8cf579d0eee4eb0c6bf3e (diff) | |
download | chromium_src-f65e97e447b789af3a8dc653d8801e8c6f24f935.zip chromium_src-f65e97e447b789af3a8dc653d8801e8c6f24f935.tar.gz chromium_src-f65e97e447b789af3a8dc653d8801e8c6f24f935.tar.bz2 |
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
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_request_job.cc | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 31a0d50..1332669 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -36,9 +36,7 @@ URLRequestJob::URLRequestJob(URLRequest* request, deferred_redirect_status_code_(-1), network_delegate_(network_delegate), weak_factory_(this) { - base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); - if (power_monitor) - power_monitor->AddObserver(this); + base::PowerMonitor::AddObserver(this); } void URLRequestJob::SetUpload(UploadDataStream* upload) { @@ -246,11 +244,7 @@ void URLRequestJob::OnSuspend() { void URLRequestJob::NotifyURLRequestDestroyed() { } -URLRequestJob::~URLRequestJob() { - base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); - if (power_monitor) - power_monitor->RemoveObserver(this); -} +URLRequestJob::~URLRequestJob() { base::PowerMonitor::RemoveObserver(this); } void URLRequestJob::NotifyCertificateRequested( SSLCertRequestInfo* cert_request_info) { |