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