Chromium Code Reviews| Index: chrome/browser/system_monitor/image_capture_device_browser_mac.mm |
| diff --git a/chrome/browser/system_monitor/image_capture_device_browser_mac.mm b/chrome/browser/system_monitor/image_capture_device_browser_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc16d8acaf7dd56f4e86cd9a7a77f36e8cd14fae |
| --- /dev/null |
| +++ b/chrome/browser/system_monitor/image_capture_device_browser_mac.mm |
| @@ -0,0 +1,133 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/system_monitor/image_capture_device_browser_mac.h" |
| + |
| +#import "chrome/browser/system_monitor/image_capture_camera.h" |
| +#include "base/file_util.h" |
| +#include "base/system_monitor/system_monitor.h" |
| +#include "chrome/browser/system_monitor/disk_info_mac.h" |
| +#include "chrome/browser/system_monitor/media_storage_util.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace { |
| + |
| +chrome::ImageCaptureDeviceBrowser* g_image_capture_device_browser = NULL; |
| + |
| +} // namespace |
| + |
| +// This class is the surface for the Mac ICDeviceBrowser ImageCaptureCore API. |
| +// Owned by the ChromeBrowserParts and has browser process lifetime. Upon |
| +// creation, it gets a list of attached media volumes (asynchronously) which |
| +// it will eventually forward to the SystemMonitor as removable storage |
| +// notifications. It will also set up an ImageCaptureCore listener to be |
| +// told when new devices/volumes are discovered and existing ones are removed. |
| +@interface ImageCaptureDeviceBrowserMac |
| + : NSObject<ICDeviceBrowserDelegate> { |
| + @private |
| + scoped_nsobject<ICDeviceBrowser> deviceBrowser_; |
| + scoped_nsobject<NSMutableArray> cameras_; |
| +} |
| + |
| +- (void)close; |
| + |
| +// The UUIDs passed here are available in the device attach notifications |
| +// given through SystemMonitor. They're gotten by cracking the device ID |
| +// and taking the unique ID output. |
| +- (ImageCaptureCameraInterface*)cameraInterfaceForUUID:(const std::string&)uuid; |
| + |
| +@end |
| + |
| +@implementation ImageCaptureDeviceBrowserMac |
| + |
| +- (id)init { |
| + if ((self = [super init])) { |
| + cameras_.reset([[NSMutableArray alloc] init]); |
| + |
| + deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); |
| + [deviceBrowser_ setDelegate:self]; |
| + deviceBrowser_.get().browsedDeviceTypeMask = |
| + [deviceBrowser_ browsedDeviceTypeMask] | |
| + ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal; |
| + [deviceBrowser_ start]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)close { |
| + [deviceBrowser_ setDelegate:nil]; |
| + [deviceBrowser_ stop]; |
| + deviceBrowser_.reset(); |
| + cameras_.reset(); |
| +} |
| + |
| +- (ImageCaptureCameraInterface*) |
| + cameraInterfaceForUUID:(const std::string&)uuid { |
| + for (ICCameraDevice* camera in cameras_.get()) { |
| + NSString* camera_id = [camera UUIDString]; |
| + if (base::SysNSStringToUTF8(camera_id) == uuid) { |
| + return [[[ImageCaptureCameraInterface alloc] |
| + initWithCameraDevice:camera] autorelease]; |
| + } |
| + } |
| + return nil; |
| +} |
| + |
| +- (void)deviceBrowser:(ICDeviceBrowser*)browser |
| + didAddDevice:(ICDevice*)addedDevice |
| + moreComing:(BOOL)moreComing { |
| + if (!(addedDevice.type & ICDeviceTypeCamera)) |
| + return; |
| + |
| + ICCameraDevice* cameraDevice = |
| + base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice); |
| + |
| + [cameras_ addObject:addedDevice]; |
| + |
| + base::SystemMonitor::Get()->ProcessRemovableStorageAttached( |
| + chrome::MediaStorageUtil::MakeDeviceId( |
| + chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, |
| + base::SysNSStringToUTF8([cameraDevice UUIDString])), |
| + base::SysNSStringToUTF16([cameraDevice name]), |
| + base::SysNSStringToUTF8([cameraDevice mountPoint])); |
| +} |
| + |
| +- (void)deviceBrowser:(ICDeviceBrowser*)browser |
| + didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { |
|
sail
2012/12/14 19:27:32
one argument per line
Greg Billock
2012/12/14 22:03:56
Done.
|
| + if (!(device.type & ICDeviceTypeCamera)) |
| + return; |
| + |
| + ICCameraDevice* cameraDevice = |
| + base::mac::ObjCCastStrict<ICCameraDevice>(device); |
|
sail
2012/12/14 19:27:32
It looks like you don't need this cast anymore. Yo
Greg Billock
2012/12/14 22:03:56
Done.
|
| + |
| + [cameras_ removeObject:device]; |
| + |
| + base::SystemMonitor::Get()->ProcessRemovableStorageDetached( |
| + chrome::MediaStorageUtil::MakeDeviceId( |
| + chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, |
| + base::SysNSStringToUTF8([cameraDevice UUIDString]))); |
| +} |
| + |
| +@end // ImageCaptureDeviceBrowserMac |
| + |
| +namespace chrome { |
| + |
| +ImageCaptureDeviceBrowser::ImageCaptureDeviceBrowser() { |
| + device_browser_.reset([[ImageCaptureDeviceBrowserMac alloc] init]); |
| + g_image_capture_device_browser = this; |
| +} |
| + |
| +ImageCaptureDeviceBrowser::~ImageCaptureDeviceBrowser() { |
| + g_image_capture_device_browser = NULL; |
| + [device_browser_ close]; |
| +} |
| + |
| +// static |
| +ImageCaptureCameraInterface* ImageCaptureDeviceBrowser::cameraInterfaceForUUID( |
| + const std::string& uuid) { |
| + return [g_image_capture_device_browser->device_browser_ |
| + cameraInterfaceForUUID:uuid]; |
| +} |
| + |
| +} // namespace chrome |