Index: content/browser/renderer_host/media/media_stream_manager.cc |
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc |
index ea0d546b193f3d7f0eb3cb86db3a4fd03c449a05..af543fc26d562756c7c3a4a2aa2e42cfd572ab9f 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.cc |
+++ b/content/browser/renderer_host/media/media_stream_manager.cc |
@@ -361,7 +361,11 @@ |
base::Unretained(this))); |
} |
- base::PowerMonitor::AddObserver(this); |
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
+ // BrowserMainLoop always creates the PowerMonitor instance before creating |
+ // MediaStreamManager, but power_monitor may be NULL in unit tests. |
+ if (power_monitor) |
+ power_monitor->AddObserver(this); |
} |
MediaStreamManager::~MediaStreamManager() { |
@@ -369,7 +373,11 @@ |
DCHECK(requests_.empty()); |
DCHECK(!device_task_runner_); |
- base::PowerMonitor::RemoveObserver(this); |
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
+ // The PowerMonitor instance owned by BrowserMainLoops always outlives the |
+ // MediaStreamManager, but it may be NULL in unit tests. |
+ if (power_monitor) |
+ power_monitor->RemoveObserver(this); |
} |
VideoCaptureManager* MediaStreamManager::video_capture_manager() { |