Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: content/browser/device_monitor_mac.mm

Issue 188383004: Mac AVFoundation: clean removal of device observers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/device_monitor_mac.mm
diff --git a/content/browser/device_monitor_mac.mm b/content/browser/device_monitor_mac.mm
index 34d1916008d3011391c44b976dabcf1c1ce1430b..62890285548ac6c1f193ab5976cbcb7000070e28 100644
--- a/content/browser/device_monitor_mac.mm
+++ b/content/browser/device_monitor_mac.mm
@@ -204,14 +204,14 @@ void QTKitMonitorImpl::OnDeviceChanged() {
ConsolidateDevicesListAndNotify(snapshot_devices);
}
-// Forward declaration for use by CrAVFoundationSuspendObserver.
+// Forward declaration for use by CrAVFoundationDeviceObserver.
class AVFoundationMonitorImpl;
} // namespace
// This class is a Key-Value Observer (KVO) shim. It is needed because C++
// classes cannot observe Key-Values directly.
-@interface CrAVFoundationSuspendObserver : NSObject {
+@interface CrAVFoundationDeviceObserver : NSObject {
@private
AVFoundationMonitorImpl* receiver_;
}
@@ -232,7 +232,7 @@ class AVFoundationMonitorImpl : public DeviceMonitorMacImpl {
virtual void OnDeviceChanged() OVERRIDE;
private:
- base::scoped_nsobject<CrAVFoundationSuspendObserver> suspend_observer_;
+ base::scoped_nsobject<CrAVFoundationDeviceObserver> suspend_observer_;
DISALLOW_COPY_AND_ASSIGN(AVFoundationMonitorImpl);
};
@@ -255,7 +255,7 @@ AVFoundationMonitorImpl::AVFoundationMonitorImpl(
usingBlock:^(NSNotification* notification) {
OnDeviceChanged();}];
suspend_observer_.reset(
- [[CrAVFoundationSuspendObserver alloc] initWithChangeReceiver:this]);
+ [[CrAVFoundationDeviceObserver alloc] initWithChangeReceiver:this]);
for (CrAVCaptureDevice* device in [AVCaptureDeviceGlue devices])
[suspend_observer_ startObserving:device];
}
@@ -292,7 +292,7 @@ void AVFoundationMonitorImpl::OnDeviceChanged() {
} // namespace
-@implementation CrAVFoundationSuspendObserver
+@implementation CrAVFoundationDeviceObserver
- (id)initWithChangeReceiver:(AVFoundationMonitorImpl*)receiver {
if ((self = [super init])) {
@@ -307,13 +307,19 @@ void AVFoundationMonitorImpl::OnDeviceChanged() {
[device addObserver:self
forKeyPath:@"suspended"
options:0
- context:nil];
+ context:device];
+ [device addObserver:self
+ forKeyPath:@"connected"
+ options:0
+ context:device];
}
- (void)stopObserving:(CrAVCaptureDevice*)device {
DCHECK(device != nil);
[device removeObserver:self
forKeyPath:@"suspended"];
+ [device removeObserver:self
+ forKeyPath:@"connected"];
}
- (void)observeValueForKeyPath:(NSString*)keyPath
@@ -322,9 +328,12 @@ void AVFoundationMonitorImpl::OnDeviceChanged() {
context:(void*)context {
if ([keyPath isEqual:@"suspended"])
receiver_->OnDeviceChanged();
+ if ([keyPath isEqual:@"connected"]) {
Robert Sesek 2014/03/06 17:08:20 nit: you don't have braces around the other if, so
mcasas 2014/03/06 17:21:58 Done. Apologies, forgot them after removing debug
+ [self stopObserving:(CrAVCaptureDevice*)context];
Robert Sesek 2014/03/06 17:08:20 static_cast
mcasas 2014/03/06 17:21:58 Done.
+ }
}
-@end // @implementation CrAVFoundationSuspendObserver
+@end // @implementation CrAVFoundationDeviceObserver
namespace content {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698