OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/device_monitor_mac.h" | 5 #include "content/browser/device_monitor_mac.h" |
6 | 6 |
7 #import <QTKit/QTKit.h> | 7 #import <QTKit/QTKit.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 options:0 | 371 options:0 |
372 context:device]; | 372 context:device]; |
373 monitoredDevices_.insert(device); | 373 monitoredDevices_.insert(device); |
374 } | 374 } |
375 | 375 |
376 - (void)stopObserving:(CrAVCaptureDevice*)device { | 376 - (void)stopObserving:(CrAVCaptureDevice*)device { |
377 DCHECK(device != nil); | 377 DCHECK(device != nil); |
378 std::set<CrAVCaptureDevice*>::iterator found = | 378 std::set<CrAVCaptureDevice*>::iterator found = |
379 std::find(monitoredDevices_.begin(), monitoredDevices_.end(), device); | 379 std::find(monitoredDevices_.begin(), monitoredDevices_.end(), device); |
380 DCHECK(found != monitoredDevices_.end()); | 380 DCHECK(found != monitoredDevices_.end()); |
381 [device removeObserver:self | 381 // Every so seldom, |device| might be gone when getting here, in that case |
382 forKeyPath:@"suspended"]; | 382 // removing the observer causes a crash. Try to avoid it by checking sanity of |
383 [device removeObserver:self | 383 // the |device| via its -observationInfo. http://crbug.com/371271. |
384 forKeyPath:@"connected"]; | 384 if ([device observationInfo]) { |
| 385 [device removeObserver:self |
| 386 forKeyPath:@"suspended"]; |
| 387 [device removeObserver:self |
| 388 forKeyPath:@"connected"]; |
| 389 } |
385 monitoredDevices_.erase(found); | 390 monitoredDevices_.erase(found); |
386 } | 391 } |
387 | 392 |
388 - (void)observeValueForKeyPath:(NSString*)keyPath | 393 - (void)observeValueForKeyPath:(NSString*)keyPath |
389 ofObject:(id)object | 394 ofObject:(id)object |
390 change:(NSDictionary*)change | 395 change:(NSDictionary*)change |
391 context:(void*)context { | 396 context:(void*)context { |
392 if ([keyPath isEqual:@"suspended"]) | 397 if ([keyPath isEqual:@"suspended"]) |
393 receiver_->OnDeviceChanged(); | 398 receiver_->OnDeviceChanged(); |
394 if ([keyPath isEqual:@"connected"]) | 399 if ([keyPath isEqual:@"connected"]) |
(...skipping 27 matching lines...) Expand all Loading... |
422 } | 427 } |
423 | 428 |
424 void DeviceMonitorMac::NotifyDeviceChanged( | 429 void DeviceMonitorMac::NotifyDeviceChanged( |
425 base::SystemMonitor::DeviceType type) { | 430 base::SystemMonitor::DeviceType type) { |
426 DCHECK(thread_checker_.CalledOnValidThread()); | 431 DCHECK(thread_checker_.CalledOnValidThread()); |
427 // TODO(xians): Remove the global variable for SystemMonitor. | 432 // TODO(xians): Remove the global variable for SystemMonitor. |
428 base::SystemMonitor::Get()->ProcessDevicesChanged(type); | 433 base::SystemMonitor::Get()->ProcessDevicesChanged(type); |
429 } | 434 } |
430 | 435 |
431 } // namespace content | 436 } // namespace content |
OLD | NEW |