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

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

Powered by Google App Engine
This is Rietveld 408576698