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..983ed9b2a55ad2d8280b208c636e7e9bf7f99ec8 |
| --- /dev/null |
| +++ b/chrome/browser/system_monitor/image_capture_device_browser_mac.mm |
| @@ -0,0 +1,142 @@ |
| +// 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" |
| + |
| + |
| +// 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 |
|
sail
2012/12/14 01:26:32
I think SystemMonitorICDeviceBrowserMac would be a
|
| + |
| +- (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_ release]; |
|
sail
2012/12/14 01:26:32
deviceBrowser_.reset()
Greg Billock
2012/12/14 18:59:11
Done.
|
| + [cameras_ release]; |
|
sail
2012/12/14 01:26:32
cameras_.reset()
Greg Billock
2012/12/14 18:59:11
Done.
|
| +} |
| + |
| +- (ImageCaptureCameraInterface*)cameraInterfaceForUUID:(const std::string&) |
|
sail
2012/12/14 01:26:32
break line after )
Greg Billock
2012/12/14 18:59:11
Done. I'm finding the intuition on these hard, eve
|
| + 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; |
| +} |
| + |
| +// Device browser maintains list of cameras as key-value pairs, so delegate |
| +// must call willChangeValueForKey to modify list. |
|
sail
2012/12/14 01:26:32
this can be removed
Greg Billock
2012/12/14 18:59:11
Done.
|
| +- (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]; |
| + |
| + chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( |
|
sail
2012/12/14 01:26:32
this can be removed
Greg Billock
2012/12/14 18:59:11
Done.
|
| + base::SysNSStringToUTF8([cameraDevice UUIDString]), |
| + base::SysNSStringToUTF16([cameraDevice name]), |
| + FilePath(base::SysNSStringToUTF8([cameraDevice mountPoint]))); |
| + base::SystemMonitor::Get()->ProcessRemovableStorageAttached( |
| + chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id()), |
| + info.device_name(), info.mount_point().value()); |
| +} |
| + |
| +- (void)deviceBrowser:(ICDeviceBrowser*)browser |
| + didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { |
| + if (!(device.type & ICDeviceTypeCamera)) |
| + return; |
| + |
| + NSString* name = [device name]; |
| + |
| + ICCameraDevice* cameraDevice = (ICCameraDevice*)device; |
|
sail
2012/12/14 01:26:32
no C style casts
Greg Billock
2012/12/14 18:59:11
Fixed up this whole method to match.
On 2012/12/1
|
| + NSString* mountPoint = [cameraDevice mountPoint]; |
| + NSString* uuid = [cameraDevice UUIDString]; |
| + |
| + [cameras_ removeObject:device]; |
| + |
| + chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( |
|
sail
2012/12/14 01:26:32
this can be removed
Greg Billock
2012/12/14 18:59:11
Done.
|
| + base::SysNSStringToUTF8(uuid), |
| + base::SysNSStringToUTF16(name), |
| + FilePath(base::SysNSStringToUTF8(mountPoint))); |
| + base::SystemMonitor::Get()->ProcessRemovableStorageDetached( |
| + chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id())); |
| +} |
| + |
| +@end // ImageCaptureDeviceBrowserMac |
| + |
| +// ImageCaptureDeviceBrowser implementation |
|
sail
2012/12/14 01:26:32
don't need this
Greg Billock
2012/12/14 18:59:11
Done.
|
| + |
| +chrome::ImageCaptureDeviceBrowser* g_image_capture_device_browser = NULL; |
|
sail
2012/12/14 01:26:32
move this to an anonymous namespace above
Greg Billock
2012/12/14 18:59:11
Done.
|
| + |
| +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 |
| + |
| + |