Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/browser/system_monitor/image_capture_device_browser_mac.mm

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

Powered by Google App Engine
This is Rietveld 408576698