Chromium Code Reviews| 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 "chrome/browser/system_monitor/image_capture_device_manager.h" | 5 #include "chrome/browser/system_monitor/image_capture_device_manager.h" |
| 6 | 6 |
| 7 #import <ImageCaptureCore/ImageCaptureCore.h> | 7 #import <ImageCaptureCore/ImageCaptureCore.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/system_monitor/system_monitor.h" | |
| 11 #include "chrome/browser/system_monitor/disk_info_mac.h" | |
| 12 #import "chrome/browser/system_monitor/image_capture_device.h" | 10 #import "chrome/browser/system_monitor/image_capture_device.h" |
| 13 #include "chrome/browser/system_monitor/media_storage_util.h" | 11 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 14 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 15 | 13 |
| 16 namespace { | 14 namespace { |
| 17 | 15 |
| 18 chrome::ImageCaptureDeviceManager* g_image_capture_device_manager = NULL; | 16 chrome::ImageCaptureDeviceManager* g_image_capture_device_manager = NULL; |
| 19 | 17 |
| 20 } // namespace | 18 } // namespace |
| 21 | 19 |
| 22 // This class is the surface for the Mac ICDeviceBrowser ImageCaptureCore API. | 20 // This class is the surface for the Mac ICDeviceBrowser ImageCaptureCore API. |
| 23 // Owned by the ChromeBrowserParts and has browser process lifetime. Upon | 21 // Owned by the ChromeBrowserParts and has browser process lifetime. Upon |
| 24 // creation, it gets a list of attached media volumes (asynchronously) which | 22 // creation, it gets a list of attached media volumes (asynchronously) which |
| 25 // it will eventually forward to the SystemMonitor as removable storage | 23 // it will eventually forward to RemovableStorageNotifications. It will also |
| 26 // notifications. It will also set up an ImageCaptureCore listener to be | 24 // set up an ImageCaptureCore listener to be told when new devices/volumes |
| 27 // told when new devices/volumes are discovered and existing ones are removed. | 25 // are discovered and existing ones are removed. |
| 28 @interface ImageCaptureDeviceManagerImpl | 26 @interface ImageCaptureDeviceManagerImpl |
| 29 : NSObject<ICDeviceBrowserDelegate> { | 27 : NSObject<ICDeviceBrowserDelegate> { |
| 30 @private | 28 @private |
| 31 scoped_nsobject<ICDeviceBrowser> deviceBrowser_; | 29 scoped_nsobject<ICDeviceBrowser> deviceBrowser_; |
| 32 scoped_nsobject<NSMutableArray> cameras_; | 30 scoped_nsobject<NSMutableArray> cameras_; |
| 31 | |
| 32 // Weak pointer | |
|
vandebo (ex-Chrome)
2013/01/31 23:51:29
Not a weak pointer, instead say that it is guarant
Greg Billock
2013/02/01 18:28:42
Done.
| |
| 33 chrome::RemovableStorageNotifications::Receiver* notifications_; | |
| 33 } | 34 } |
| 34 | 35 |
| 36 - (void)setNotifications:(chrome::RemovableStorageNotifications::Receiver* | |
| 37 notifications); | |
| 35 - (void)close; | 38 - (void)close; |
| 36 | 39 |
| 37 // The UUIDs passed here are available in the device attach notifications | 40 // The UUIDs passed here are available in the device attach notifications. |
| 38 // given through SystemMonitor. They're gotten by cracking the device ID | 41 // They're gotten by cracking the device ID and taking the unique ID output. |
| 39 // and taking the unique ID output. | |
| 40 - (ImageCaptureDevice*)deviceForUUID:(const std::string&)uuid; | 42 - (ImageCaptureDevice*)deviceForUUID:(const std::string&)uuid; |
| 41 | 43 |
| 42 @end | 44 @end |
| 43 | 45 |
| 44 @implementation ImageCaptureDeviceManagerImpl | 46 @implementation ImageCaptureDeviceManagerImpl |
| 45 | 47 |
| 46 - (id)init { | 48 - (id)init { |
| 47 if ((self = [super init])) { | 49 if ((self = [super init])) { |
| 48 cameras_.reset([[NSMutableArray alloc] init]); | 50 cameras_.reset([[NSMutableArray alloc] init]); |
| 49 | 51 |
| 50 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); | 52 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); |
| 51 [deviceBrowser_ setDelegate:self]; | 53 [deviceBrowser_ setDelegate:self]; |
| 52 [deviceBrowser_ setBrowsedDeviceTypeMask: | 54 [deviceBrowser_ setBrowsedDeviceTypeMask: |
| 53 [deviceBrowser_ browsedDeviceTypeMask] | | 55 [deviceBrowser_ browsedDeviceTypeMask] | |
| 54 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal]; | 56 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal]; |
| 55 [deviceBrowser_ start]; | 57 [deviceBrowser_ start]; |
| 56 } | 58 } |
| 57 return self; | 59 return self; |
| 58 } | 60 } |
| 59 | 61 |
| 62 - (void)setNotifications:(chrome::RemovableStorageNotifications::Receiver* | |
| 63 notifications) { | |
| 64 notifications_ = notifications; | |
| 65 } | |
| 66 | |
| 60 - (void)close { | 67 - (void)close { |
| 61 [deviceBrowser_ setDelegate:nil]; | 68 [deviceBrowser_ setDelegate:nil]; |
| 62 [deviceBrowser_ stop]; | 69 [deviceBrowser_ stop]; |
| 63 deviceBrowser_.reset(); | 70 deviceBrowser_.reset(); |
| 64 cameras_.reset(); | 71 cameras_.reset(); |
| 65 } | 72 } |
| 66 | 73 |
| 67 - (ImageCaptureDevice*) deviceForUUID:(const std::string&)uuid { | 74 - (ImageCaptureDevice*) deviceForUUID:(const std::string&)uuid { |
| 68 for (ICCameraDevice* camera in cameras_.get()) { | 75 for (ICCameraDevice* camera in cameras_.get()) { |
| 69 NSString* camera_id = [camera UUIDString]; | 76 NSString* camera_id = [camera UUIDString]; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 80 moreComing:(BOOL)moreComing { | 87 moreComing:(BOOL)moreComing { |
| 81 if (!(addedDevice.type & ICDeviceTypeCamera)) | 88 if (!(addedDevice.type & ICDeviceTypeCamera)) |
| 82 return; | 89 return; |
| 83 | 90 |
| 84 ICCameraDevice* cameraDevice = | 91 ICCameraDevice* cameraDevice = |
| 85 base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice); | 92 base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice); |
| 86 | 93 |
| 87 [cameras_ addObject:addedDevice]; | 94 [cameras_ addObject:addedDevice]; |
| 88 | 95 |
| 89 // TODO(gbillock): use [cameraDevice mountPoint] here when possible. | 96 // TODO(gbillock): use [cameraDevice mountPoint] here when possible. |
| 90 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | 97 notifications_->ProcessAttach(RemovableStorageNotifications::StorageInfo( |
| 91 chrome::MediaStorageUtil::MakeDeviceId( | 98 chrome::MediaStorageUtil::MakeDeviceId( |
| 92 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, | 99 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, |
| 93 base::SysNSStringToUTF8([cameraDevice UUIDString])), | 100 base::SysNSStringToUTF8([cameraDevice UUIDString])), |
| 94 base::SysNSStringToUTF16([cameraDevice name]), ""); | 101 base::SysNSStringToUTF16([cameraDevice name]), "")); |
| 95 } | 102 } |
| 96 | 103 |
| 97 - (void)deviceBrowser:(ICDeviceBrowser*)browser | 104 - (void)deviceBrowser:(ICDeviceBrowser*)browser |
| 98 didRemoveDevice:(ICDevice*)device | 105 didRemoveDevice:(ICDevice*)device |
| 99 moreGoing:(BOOL)moreGoing { | 106 moreGoing:(BOOL)moreGoing { |
| 100 if (!(device.type & ICDeviceTypeCamera)) | 107 if (!(device.type & ICDeviceTypeCamera)) |
| 101 return; | 108 return; |
| 102 | 109 |
| 103 std::string uuid = base::SysNSStringToUTF8([device UUIDString]); | 110 std::string uuid = base::SysNSStringToUTF8([device UUIDString]); |
| 104 | 111 |
| 105 // May delete |device|. | 112 // May delete |device|. |
| 106 [cameras_ removeObject:device]; | 113 [cameras_ removeObject:device]; |
| 107 | 114 |
| 108 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( | 115 notifications_->ProcessDetach( |
| 109 chrome::MediaStorageUtil::MakeDeviceId( | 116 chrome::MediaStorageUtil::MakeDeviceId( |
| 110 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid)); | 117 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid)); |
| 111 } | 118 } |
| 112 | 119 |
| 113 @end // ImageCaptureDeviceManagerImpl | 120 @end // ImageCaptureDeviceManagerImpl |
| 114 | 121 |
| 115 namespace chrome { | 122 namespace chrome { |
| 116 | 123 |
| 117 ImageCaptureDeviceManager::ImageCaptureDeviceManager() { | 124 ImageCaptureDeviceManager::ImageCaptureDeviceManager() { |
| 118 device_browser_.reset([[ImageCaptureDeviceManagerImpl alloc] init]); | 125 device_browser_.reset([[ImageCaptureDeviceManagerImpl alloc] init]); |
| 119 g_image_capture_device_manager = this; | 126 g_image_capture_device_manager = this; |
| 120 } | 127 } |
| 121 | 128 |
| 122 ImageCaptureDeviceManager::~ImageCaptureDeviceManager() { | 129 ImageCaptureDeviceManager::~ImageCaptureDeviceManager() { |
| 123 g_image_capture_device_manager = NULL; | 130 g_image_capture_device_manager = NULL; |
| 124 [device_browser_ close]; | 131 [device_browser_ close]; |
| 125 } | 132 } |
| 126 | 133 |
| 134 void ImageCaptureDeviceManager::SetNotifications( | |
| 135 RemovableStorageNotifications::Receiver* notifications) { | |
| 136 [device_browser_ setNotifications:notifications]; | |
| 137 } | |
| 138 | |
| 127 // static | 139 // static |
| 128 ImageCaptureDevice* ImageCaptureDeviceManager::deviceForUUID( | 140 ImageCaptureDevice* ImageCaptureDeviceManager::deviceForUUID( |
| 129 const std::string& uuid) { | 141 const std::string& uuid) { |
| 130 ImageCaptureDeviceManagerImpl* manager = | 142 ImageCaptureDeviceManagerImpl* manager = |
| 131 g_image_capture_device_manager->device_browser_; | 143 g_image_capture_device_manager->device_browser_; |
| 132 return [manager deviceForUUID:uuid]; | 144 return [manager deviceForUUID:uuid]; |
| 133 } | 145 } |
| 134 | 146 |
| 135 id<ICDeviceBrowserDelegate> ImageCaptureDeviceManager::device_browser() { | 147 id<ICDeviceBrowserDelegate> ImageCaptureDeviceManager::device_browser() { |
| 136 return device_browser_.get(); | 148 return device_browser_.get(); |
| 137 } | 149 } |
| 138 | 150 |
| 139 } // namespace chrome | 151 } // namespace chrome |
| OLD | NEW |