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

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

Issue 12147002: Add a receiver interface to RemovableStorageNotifications. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merging Created 7 years, 10 months 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
OLDNEW
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 // Guaranteed to outlive this class.
33 // TODO(gbillock): Update when ownership chains go up through
34 // a RemovableStorageNotifications subclass.
35 chrome::RemovableStorageNotifications::Receiver* notifications_;
33 } 36 }
34 37
38 - (void)setNotifications:(chrome::RemovableStorageNotifications::Receiver*)
39 notifications;
35 - (void)close; 40 - (void)close;
36 41
37 // The UUIDs passed here are available in the device attach notifications 42 // The UUIDs passed here are available in the device attach notifications.
38 // given through SystemMonitor. They're gotten by cracking the device ID 43 // 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; 44 - (ImageCaptureDevice*)deviceForUUID:(const std::string&)uuid;
41 45
42 @end 46 @end
43 47
44 @implementation ImageCaptureDeviceManagerImpl 48 @implementation ImageCaptureDeviceManagerImpl
45 49
46 - (id)init { 50 - (id)init {
47 if ((self = [super init])) { 51 if ((self = [super init])) {
48 cameras_.reset([[NSMutableArray alloc] init]); 52 cameras_.reset([[NSMutableArray alloc] init]);
53 notifications_ = NULL;
49 54
50 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]); 55 deviceBrowser_.reset([[ICDeviceBrowser alloc] init]);
51 [deviceBrowser_ setDelegate:self]; 56 [deviceBrowser_ setDelegate:self];
52 [deviceBrowser_ setBrowsedDeviceTypeMask: 57 [deviceBrowser_ setBrowsedDeviceTypeMask:
53 [deviceBrowser_ browsedDeviceTypeMask] | 58 [deviceBrowser_ browsedDeviceTypeMask] |
54 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal]; 59 ICDeviceTypeMaskCamera | ICDeviceLocationTypeMaskLocal];
55 [deviceBrowser_ start]; 60 [deviceBrowser_ start];
56 } 61 }
57 return self; 62 return self;
58 } 63 }
59 64
65 - (void)setNotifications:(chrome::RemovableStorageNotifications::Receiver*)
66 notifications {
67 notifications_ = notifications;
68 }
69
60 - (void)close { 70 - (void)close {
61 [deviceBrowser_ setDelegate:nil]; 71 [deviceBrowser_ setDelegate:nil];
62 [deviceBrowser_ stop]; 72 [deviceBrowser_ stop];
63 deviceBrowser_.reset(); 73 deviceBrowser_.reset();
64 cameras_.reset(); 74 cameras_.reset();
65 } 75 }
66 76
67 - (ImageCaptureDevice*) deviceForUUID:(const std::string&)uuid { 77 - (ImageCaptureDevice*) deviceForUUID:(const std::string&)uuid {
68 for (ICCameraDevice* camera in cameras_.get()) { 78 for (ICCameraDevice* camera in cameras_.get()) {
69 NSString* camera_id = [camera UUIDString]; 79 NSString* camera_id = [camera UUIDString];
(...skipping 10 matching lines...) Expand all
80 moreComing:(BOOL)moreComing { 90 moreComing:(BOOL)moreComing {
81 if (!(addedDevice.type & ICDeviceTypeCamera)) 91 if (!(addedDevice.type & ICDeviceTypeCamera))
82 return; 92 return;
83 93
84 ICCameraDevice* cameraDevice = 94 ICCameraDevice* cameraDevice =
85 base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice); 95 base::mac::ObjCCastStrict<ICCameraDevice>(addedDevice);
86 96
87 [cameras_ addObject:addedDevice]; 97 [cameras_ addObject:addedDevice];
88 98
89 // TODO(gbillock): use [cameraDevice mountPoint] here when possible. 99 // TODO(gbillock): use [cameraDevice mountPoint] here when possible.
90 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( 100 notifications_->ProcessAttach(
91 chrome::MediaStorageUtil::MakeDeviceId( 101 chrome::MediaStorageUtil::MakeDeviceId(
92 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, 102 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE,
93 base::SysNSStringToUTF8([cameraDevice UUIDString])), 103 base::SysNSStringToUTF8([cameraDevice UUIDString])),
94 base::SysNSStringToUTF16([cameraDevice name]), ""); 104 base::SysNSStringToUTF16([cameraDevice name]), "");
95 } 105 }
96 106
97 - (void)deviceBrowser:(ICDeviceBrowser*)browser 107 - (void)deviceBrowser:(ICDeviceBrowser*)browser
98 didRemoveDevice:(ICDevice*)device 108 didRemoveDevice:(ICDevice*)device
99 moreGoing:(BOOL)moreGoing { 109 moreGoing:(BOOL)moreGoing {
100 if (!(device.type & ICDeviceTypeCamera)) 110 if (!(device.type & ICDeviceTypeCamera))
101 return; 111 return;
102 112
103 std::string uuid = base::SysNSStringToUTF8([device UUIDString]); 113 std::string uuid = base::SysNSStringToUTF8([device UUIDString]);
104 114
105 // May delete |device|. 115 // May delete |device|.
106 [cameras_ removeObject:device]; 116 [cameras_ removeObject:device];
107 117
108 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( 118 notifications_->ProcessDetach(
109 chrome::MediaStorageUtil::MakeDeviceId( 119 chrome::MediaStorageUtil::MakeDeviceId(
110 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid)); 120 chrome::MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid));
111 } 121 }
112 122
113 @end // ImageCaptureDeviceManagerImpl 123 @end // ImageCaptureDeviceManagerImpl
114 124
115 namespace chrome { 125 namespace chrome {
116 126
117 ImageCaptureDeviceManager::ImageCaptureDeviceManager() { 127 ImageCaptureDeviceManager::ImageCaptureDeviceManager() {
118 device_browser_.reset([[ImageCaptureDeviceManagerImpl alloc] init]); 128 device_browser_.reset([[ImageCaptureDeviceManagerImpl alloc] init]);
119 g_image_capture_device_manager = this; 129 g_image_capture_device_manager = this;
120 } 130 }
121 131
122 ImageCaptureDeviceManager::~ImageCaptureDeviceManager() { 132 ImageCaptureDeviceManager::~ImageCaptureDeviceManager() {
123 g_image_capture_device_manager = NULL; 133 g_image_capture_device_manager = NULL;
124 [device_browser_ close]; 134 [device_browser_ close];
125 } 135 }
126 136
137 void ImageCaptureDeviceManager::SetNotifications(
138 RemovableStorageNotifications::Receiver* notifications) {
139 [device_browser_ setNotifications:notifications];
140 }
141
127 // static 142 // static
128 ImageCaptureDevice* ImageCaptureDeviceManager::deviceForUUID( 143 ImageCaptureDevice* ImageCaptureDeviceManager::deviceForUUID(
129 const std::string& uuid) { 144 const std::string& uuid) {
130 ImageCaptureDeviceManagerImpl* manager = 145 ImageCaptureDeviceManagerImpl* manager =
131 g_image_capture_device_manager->device_browser_; 146 g_image_capture_device_manager->device_browser_;
132 return [manager deviceForUUID:uuid]; 147 return [manager deviceForUUID:uuid];
133 } 148 }
134 149
135 id<ICDeviceBrowserDelegate> ImageCaptureDeviceManager::device_browser() { 150 id<ICDeviceBrowserDelegate> ImageCaptureDeviceManager::device_browser() {
136 return device_browser_.get(); 151 return device_browser_.get();
137 } 152 }
138 153
139 } // namespace chrome 154 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698