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 ImageCaptureDeviceBrowserMac* g_image_capture_device_browser; | |
sail
2012/12/13 02:14:00
don't need this
| |
15 | |
16 @implementation ImageCaptureDeviceBrowserMac | |
17 | |
18 @synthesize cameras = cameras_; | |
19 | |
20 - (id)init { | |
sail
2012/12/13 02:14:00
if ((self = [super init])) {
}
return self
Greg Billock
2012/12/14 00:39:59
Done. This guards the singleton?
On 2012/12/13 02
| |
21 cameras_ = [[NSMutableArray alloc] initWithCapacity:0]; | |
sail
2012/12/13 02:14:00
just init]
Greg Billock
2012/12/14 00:39:59
Done.
| |
22 | |
23 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); | |
24 deviceBrowser_.get().delegate = self; | |
sail
2012/12/13 02:14:00
[deviceBrowser setDelegate:self]
more below
Greg Billock
2012/12/14 00:39:59
Done.
| |
25 deviceBrowser_.get().browsedDeviceTypeMask = | |
26 deviceBrowser_.get().browsedDeviceTypeMask | | |
sail
2012/12/13 02:14:00
[deviceBrowser browsedDeviceTypeMask]
Greg Billock
2012/12/14 00:39:59
Done.
| |
27 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal; | |
28 [deviceBrowser_ start]; | |
29 g_image_capture_device_browser = self; | |
30 return self; | |
31 } | |
32 | |
33 - (void)close { | |
34 deviceBrowser_.get().delegate = NULL; | |
35 [deviceBrowser_ stop]; | |
36 [deviceBrowser_ release]; | |
37 [cameras_ release]; | |
38 } | |
39 | |
40 - (ImageCaptureCameraInterface*)createCameraInterfaceForUUID: | |
sail
2012/12/13 02:14:00
break the lien after the ) instead
Greg Billock
2012/12/14 00:39:59
Done.
| |
41 (std::string&)uuid { | |
42 for (ICCameraDevice* camera in cameras_) { | |
43 NSString* camera_id = [camera UUIDString]; | |
44 if (base::SysNSStringToUTF8(camera_id) == uuid) { | |
sail
2012/12/13 02:14:00
no braces
Greg Billock
2012/12/14 00:39:59
Done.
| |
45 return [[[ImageCaptureCameraInterface alloc] init:camera] autorelease]; | |
46 } | |
47 } | |
48 return nil; | |
49 } | |
50 | |
51 + (ImageCaptureDeviceBrowserMac*)get { | |
52 return g_image_capture_device_browser; | |
53 } | |
54 | |
55 // Device browser maintains list of cameras as key-value pairs, so delegate | |
56 // must call willChangeValueForKey to modify list. | |
57 - (void)deviceBrowser:(ICDeviceBrowser*)browser | |
sail
2012/12/13 02:14:00
align colons
Greg Billock
2012/12/14 00:39:59
Done.
| |
58 didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing { | |
sail
2012/12/13 02:14:00
one line per argument
Greg Billock
2012/12/14 00:39:59
Done.
| |
59 if (!(addedDevice.type & ICDeviceTypeCamera)) | |
60 return; | |
61 | |
62 ICCameraDevice* cameraDevice = (ICCameraDevice*)addedDevice; | |
sail
2012/12/13 02:14:00
no C style casts
Greg Billock
2012/12/14 00:39:59
Done. Is there an ObjC style that's better?
On 20
| |
63 | |
64 NSString* name = [addedDevice name]; | |
sail
2012/12/13 02:14:00
no need for local variables if this is only used o
Greg Billock
2012/12/14 00:39:59
Done.
| |
65 NSString* mountPoint = [cameraDevice mountPoint]; | |
66 NSString* uuid = [cameraDevice UUIDString]; | |
67 | |
68 // implement manual observer notification for the cameras property | |
69 [self willChangeValueForKey:@"cameras"]; | |
70 [cameras_ addObject:addedDevice]; | |
71 [self didChangeValueForKey:@"cameras"]; | |
72 | |
73 chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( | |
sail
2012/12/13 02:14:00
this isn't need, just use the data directly
the fu
Greg Billock
2012/12/14 00:39:59
I'd rather keep the purpose-built factories than a
sail
2012/12/14 01:26:32
I don't understand this.
There's nothing in disk i
Greg Billock
2012/12/14 17:29:22
Oy, thanks. The prehistory is that this class was
| |
74 base::SysNSStringToUTF8(uuid), | |
75 base::SysNSStringToUTF16(name), | |
76 FilePath(base::SysNSStringToUTF8(mountPoint))); | |
77 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | |
78 chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id()), | |
79 info.device_name(), info.mount_point().value()); | |
80 } | |
81 | |
82 - (void)deviceBrowser:(ICDeviceBrowser*)browser | |
83 didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { | |
84 if (!(device.type & ICDeviceTypeCamera)) | |
85 return; | |
86 | |
87 NSString* name = [device name]; | |
88 | |
89 ICCameraDevice* cameraDevice = (ICCameraDevice*)device; | |
90 NSString* mountPoint = [cameraDevice mountPoint]; | |
91 NSString* uuid = [cameraDevice UUIDString]; | |
92 | |
93 // implement manual observer notification for the cameras property | |
94 [self willChangeValueForKey:@"cameras"]; | |
95 [cameras_ removeObject:device]; | |
96 [self didChangeValueForKey:@"cameras"]; | |
97 | |
98 chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( | |
99 base::SysNSStringToUTF8(uuid), | |
100 base::SysNSStringToUTF16(name), | |
101 FilePath(base::SysNSStringToUTF8(mountPoint))); | |
102 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( | |
103 chrome::MediaStorageUtil::MakeDeviceId(info.type(), info.device_id())); | |
104 } | |
105 | |
106 @end // ImageCaptureDeviceBrowserMac | |
OLD | NEW |