Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/system_monitor/image_capture_device_browser_mac.h" | |
| 6 | |
| 7 #import "chrome/browser/system_monitor/image_capture_camera.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/system_monitor/system_monitor.h" | |
| 10 #include "chrome/browser/system_monitor/disk_info_mac.h" | |
| 11 #include "chrome/browser/system_monitor/media_storage_util.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 | |
| 14 | |
| 15 // This class is the surface for the Mac ICDeviceBrowser ImageCaptureCore API. | |
| 16 // Owned by the ChromeBrowserParts and has browser process lifetime. Upon | |
| 17 // creation, it gets a list of attached media volumes (asynchronously) which | |
| 18 // it will eventually forward to the SystemMonitor as removable storage | |
| 19 // notifications. It will also set up an ImageCaptureCore listener to be | |
| 20 // told when new devices/volumes are discovered and existing ones are removed. | |
| 21 @interface ImageCaptureDeviceBrowserMac | |
| 22 : NSObject<ICDeviceBrowserDelegate> { | |
| 23 @private | |
| 24 scoped_nsobject<ICDeviceBrowser> deviceBrowser_; | |
| 25 scoped_nsobject<NSMutableArray> cameras_; | |
| 26 } | |
| 27 | |
| 28 - (void)close; | |
| 29 | |
| 30 // The UUIDs passed here are available in the device attach notifications | |
| 31 // given through SystemMonitor. They're gotten by cracking the device ID | |
| 32 // and taking the unique ID output. | |
| 33 - (ImageCaptureCameraInterface*)cameraInterfaceForUUID:(const std::string&)uuid; | |
| 34 | |
| 35 @end | |
| 36 | |
| 37 @implementation ImageCaptureDeviceBrowserMac | |
|
sail
2012/12/14 01:26:32
I think SystemMonitorICDeviceBrowserMac would be a
| |
| 38 | |
| 39 - (id)init { | |
| 40 if ((self = [super init])) { | |
| 41 cameras_.reset([[NSMutableArray alloc] init]); | |
| 42 | |
| 43 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); | |
| 44 [deviceBrowser_ setDelegate:self]; | |
| 45 deviceBrowser_.get().browsedDeviceTypeMask = | |
| 46 [deviceBrowser_ browsedDeviceTypeMask] | | |
| 47 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal; | |
| 48 [deviceBrowser_ start]; | |
| 49 } | |
| 50 return self; | |
| 51 } | |
| 52 | |
| 53 - (void)close { | |
| 54 [deviceBrowser_ setDelegate:nil]; | |
| 55 [deviceBrowser_ stop]; | |
| 56 [deviceBrowser_ release]; | |
|
sail
2012/12/14 01:26:32
deviceBrowser_.reset()
Greg Billock
2012/12/14 18:59:11
Done.
| |
| 57 [cameras_ release]; | |
|
sail
2012/12/14 01:26:32
cameras_.reset()
Greg Billock
2012/12/14 18:59:11
Done.
| |
| 58 } | |
| 59 | |
| 60 - (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
| |
| 61 uuid { | |
| 62 for (ICCameraDevice* camera in cameras_.get()) { | |
| 63 NSString* camera_id = [camera UUIDString]; | |
| 64 if (base::SysNSStringToUTF8(camera_id) == uuid) { | |
| 65 return [[[ImageCaptureCameraInterface alloc] | |
| 66 initWithCameraDevice:camera] autorelease]; | |
| 67 } | |
| 68 } | |
| 69 return nil; | |
| 70 } | |
| 71 | |
| 72 // Device browser maintains list of cameras as key-value pairs, so delegate | |
| 73 // 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.
| |
| 74 - (void)deviceBrowser:(ICDeviceBrowser*)browser | |
| 75 didAddDevice:(ICDevice*)addedDevice | |
| 76 moreComing:(BOOL)moreComing { | |
| 77 if (!(addedDevice.type & ICDeviceTypeCamera)) | |
| 78 return; | |
| 79 | |
| 80 ICCameraDevice* cameraDevice = | |
| 81 base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice); | |
| 82 | |
| 83 [cameras_ addObject:addedDevice]; | |
| 84 | |
| 85 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.
| |
| 86 base::SysNSStringToUTF8([cameraDevice UUIDString]), | |
| 87 base::SysNSStringToUTF16([cameraDevice name]), | |
| 88 FilePath(base::SysNSStringToUTF8([cameraDevice mountPoint]))); | |
| 89 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | |
| 90 chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id()), | |
| 91 info.device_name(), info.mount_point().value()); | |
| 92 } | |
| 93 | |
| 94 - (void)deviceBrowser:(ICDeviceBrowser*)browser | |
| 95 didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { | |
| 96 if (!(device.type & ICDeviceTypeCamera)) | |
| 97 return; | |
| 98 | |
| 99 NSString* name = [device name]; | |
| 100 | |
| 101 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
| |
| 102 NSString* mountPoint = [cameraDevice mountPoint]; | |
| 103 NSString* uuid = [cameraDevice UUIDString]; | |
| 104 | |
| 105 [cameras_ removeObject:device]; | |
| 106 | |
| 107 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.
| |
| 108 base::SysNSStringToUTF8(uuid), | |
| 109 base::SysNSStringToUTF16(name), | |
| 110 FilePath(base::SysNSStringToUTF8(mountPoint))); | |
| 111 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( | |
| 112 chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id())); | |
| 113 } | |
| 114 | |
| 115 @end // ImageCaptureDeviceBrowserMac | |
| 116 | |
| 117 // ImageCaptureDeviceBrowser implementation | |
|
sail
2012/12/14 01:26:32
don't need this
Greg Billock
2012/12/14 18:59:11
Done.
| |
| 118 | |
| 119 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.
| |
| 120 | |
| 121 namespace chrome { | |
| 122 | |
| 123 ImageCaptureDeviceBrowser::ImageCaptureDeviceBrowser() { | |
| 124 device_browser_.reset([[ImageCaptureDeviceBrowserMac alloc] init]); | |
| 125 g_image_capture_device_browser = this; | |
| 126 } | |
| 127 | |
| 128 ImageCaptureDeviceBrowser::~ImageCaptureDeviceBrowser() { | |
| 129 g_image_capture_device_browser = NULL; | |
| 130 [device_browser_ close]; | |
| 131 } | |
| 132 | |
| 133 // static | |
| 134 ImageCaptureCameraInterface* ImageCaptureDeviceBrowser::cameraInterfaceForUUID( | |
| 135 const std::string& uuid) { | |
| 136 return [g_image_capture_device_browser->device_browser_ | |
| 137 cameraInterfaceForUUID:uuid]; | |
| 138 } | |
| 139 | |
| 140 } // namespace chrome | |
| 141 | |
| 142 | |
| OLD | NEW |