|
|
Created:
8 years ago by Greg Billock Modified:
7 years, 11 months ago CC:
chromium-reviews, sail+watch_chromium.org Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
Description[Media Galleries] Add an ImageCaptureCore listener for Mac. (part 2)
This listener uses the ImageCapture API to watch for attach and detach
events of PTP devices and other devices which can be read through the
library. It forwards such notifications through the SystemMonitor.
Also provides an API for clients to access such devices directly and
retrieve the media contents from them.
R=thestig@chromium.org,sail@chromium.org
BUG=151681
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=175471
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=175938
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=176243
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=176529
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=176797
Patch Set 1 #
Total comments: 44
Patch Set 2 : Correct base cl #Patch Set 3 : Better ObjC #
Total comments: 95
Patch Set 4 : Lots of fixes #
Total comments: 41
Patch Set 5 : Use weak ptr for listener. #
Total comments: 11
Patch Set 6 : Device browser test #Patch Set 7 : Review comments #Patch Set 8 : Add test for ImageCaptureCameraInterface #
Total comments: 28
Patch Set 9 : Add accessor for device browser #
Total comments: 8
Patch Set 10 : Add removal test #
Total comments: 13
Patch Set 11 : Rename classes #Patch Set 12 : Pool-delegate all listener callbacks #Patch Set 13 : Delete unused factory #
Total comments: 10
Patch Set 14 : Switch to only use the UI thread. #
Total comments: 5
Patch Set 15 : Add test for downloadFile #
Total comments: 17
Patch Set 16 : Use constants #
Total comments: 33
Patch Set 17 : Casts and comments #Patch Set 18 : Take out header #Patch Set 19 : Remove include line #
Total comments: 11
Patch Set 20 : Using init, but now double-free'ing #Patch Set 21 : Mark spots where doing what seems sensible is leading to test crashes #Patch Set 22 : Add overloads to get the mock camera device initialized properly #
Total comments: 10
Patch Set 23 : Fix comment #
Total comments: 4
Patch Set 24 : Get autorelease right #Patch Set 25 : Take out mountPoint #Patch Set 26 : Fix paren #Patch Set 27 : Rebase to head #Patch Set 28 : Allocate array, handle deviceDidBecomeReady #Patch Set 29 : Add declarations for 10.8 methods #
Total comments: 6
Patch Set 30 : Don't run ImageCapture on 10.6 #
Total comments: 5
Patch Set 31 : Fix 10.6 declarations #Patch Set 32 : Ifdef fix #Patch Set 33 : Add casts for 10.6 #Patch Set 34 : Repair patch #Patch Set 35 : the sequel #Patch Set 36 : Don't use second cast #Messages
Total messages: 86 (0 generated)
On 2012/12/12 18:07:01, Greg Billock wrote: I'm not sure how to go about writing tests for a lot of this. Is there a standard way to mock out internal APIs like ImageCapture?
Are you rolling https://codereview.chromium.org/11490010/ into this CL?
Some high level comments: - the CL name needs to have "part x of y" in it - the CL should be branched against the other parts. it shouldn't have the other parts rolled into it. - each class should be in its own file - each file should have its own tests - you may need to create dummy versions of OS objects to test your code. For example, to test the ICDeviceBrowserDelegate you might be able to get away with passing a NULL ICDevice object. If not then maybe try stubbing out the ICDevice implementation. https://codereview.chromium.org/11442057/diff/1/chrome/browser/chrome_browser... File chrome/browser/chrome_browser_main_mac.h (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/chrome_browser... chrome/browser/chrome_browser_main_mac.h:37: scoped_ptr<Inner> inner_; I think a better way to do this would be to expose a C++ class in chrome/browser/system_monitor. Make the Objective-C class internal to the implementation. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:21: class ImageCaptureDeviceListener { This isn't used anywhere in this patch. It's hard to review abstract code that doesn't have any use yet. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:51: @interface ImageCaptureDeviceBrowserMac : name isn't very descriptive. colon on the next line? same below As per my earlier comment, I'd make this a C++ class and remove everything else from this file. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:54: ICDeviceBrowser* device_browser_; Objective-C classes should use camel case variable names, something like deviceBrowser_. Also, all variables should be scoped_nsobject. If it's a weak reference then add a comment explaining that instead. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:57: @property(retain) NSMutableArray* cameras; should be (nonatomic, retain) newline before and after. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:58: - (id)init; doesn't need to be public (since this derives from NSObject it already exposes init). https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:61: + (ImageCaptureDeviceBrowserMac*)Get; Objective-C method names should start with lower case (more below) if this returns a singleton instance then maybe name this sharedInstance https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:62: @end newline before this https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:68: @interface ImageCaptureCameraInterface : name isn't very descriptive https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:74: - (id)init:(ICCameraDevice*)camera_device; new line before this https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:79: withError:(bool)rename_error; colons should line up, same below https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:85: @end new line before this https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:13: ImageCaptureDeviceBrowserMac* g_image_capture_device_browser; It doesn't seem like you really need a singleton. Callers should just grab an instance from ChromeBrowserMainPartsMac. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:45: return [[ImageCaptureCameraInterface alloc] init:camera]; In Objective-C, the naming scheme implies the owner ship rule. If the name begins with create or new then the caler owns the returned object. Otherwise the caller should retain the returned object if it keeps a reference to it. In this case you should return an autoreleased object. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:55: // Method delegates for device added and removed don't need this https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:61: if (addedDevice.type & ICDeviceTypeCamera) { should do early return instead https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:62: ICCameraDevice* camera_device = (ICCameraDevice*)addedDevice; local variable names in Objective-C classes should be camel case https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:93: [self willChangeValueForKey:@"cameras"]; Are you planning on using key value observers? I'd recommend against that.
No, I'll merge that when it gets submitted. On Wed, Dec 12, 2012 at 12:27 PM, <thestig@chromium.org> wrote: > Are you rolling https://codereview.chromium.org/11490010/ into this CL? > > https://codereview.chromium.org/11442057/
Thanks for the review. Improved the ObjC. Did I get it right? On where to put it, I was thinking to just have these classes be ObjC outright, as that followed the ImageCaptureCore example code I had the best. But wrapping at least the browser in C++ for cleaner use in ChromeBrowserPartsMain seems like a good goal. Any reason to prefer wrapping one place vs another? https://codereview.chromium.org/11442057/diff/1/chrome/browser/chrome_browser... File chrome/browser/chrome_browser_main_mac.h (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/chrome_browser... chrome/browser/chrome_browser_main_mac.h:37: scoped_ptr<Inner> inner_; On 2012/12/12 20:53:20, sail wrote: > I think a better way to do this would be to expose a C++ class in > chrome/browser/system_monitor. Make the Objective-C class internal to the > implementation. I've sketched that out separately -- I think we actually need to move these notifications out of SystemMonitor. They aren't base:: namespaced notifications; you have to know chrome:: code to handle them, so they don't belong in base::. I tried working SystemMonitor into something that maintained list of notification types, but it ends up being complex and relatively pointless -- why not just get notifications from the sources themselves? I think the best option is for things these BrowserMainParts use should be available in BrowserContext. But that has its own problems.... https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:21: class ImageCaptureDeviceListener { On 2012/12/12 20:53:20, sail wrote: > This isn't used anywhere in this patch. It's hard to review abstract code that > doesn't have any use yet. There's ImageCaptureCameraInterface:setListener, and that code uses the interface. I wanted to separate out the MTP delegate and this class to make the review smaller. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:51: @interface ImageCaptureDeviceBrowserMac : On 2012/12/12 20:53:20, sail wrote: > name isn't very descriptive. colon on the next line? same below Suggestion? The ImageCapture API calls this the DeviceBrowser, so I was basically wrapping that. > > As per my earlier comment, I'd make this a C++ class and remove everything else > from this file. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:54: ICDeviceBrowser* device_browser_; OK. Do I need to make a scoped_nsobject for my cameras_ member? Or since that's getting synthesized it takes care of it? The sample ImageCapture code I was following used this method. On 2012/12/12 20:53:20, sail wrote: > Objective-C classes should use camel case variable names, something like > deviceBrowser_. > Also, all variables should be scoped_nsobject. If it's a weak reference then add > a comment explaining that instead. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:57: @property(retain) NSMutableArray* cameras; On 2012/12/12 20:53:20, sail wrote: > should be (nonatomic, retain) > newline before and after. Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:58: - (id)init; On 2012/12/12 20:53:20, sail wrote: > doesn't need to be public (since this derives from NSObject it already exposes > init). Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:61: + (ImageCaptureDeviceBrowserMac*)Get; On 2012/12/12 20:53:20, sail wrote: > Objective-C method names should start with lower case (more below) > if this returns a singleton instance then maybe name this sharedInstance Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:62: @end On 2012/12/12 20:53:20, sail wrote: > newline before this Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:68: @interface ImageCaptureCameraInterface : On 2012/12/12 20:53:20, sail wrote: > name isn't very descriptive The idea is this class is what you use to get images from the camera. Better ideas? https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:74: - (id)init:(ICCameraDevice*)camera_device; On 2012/12/12 20:53:20, sail wrote: > new line before this Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:79: withError:(bool)rename_error; On 2012/12/12 20:53:20, sail wrote: > colons should line up, same below Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:85: @end On 2012/12/12 20:53:20, sail wrote: > new line before this Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:13: ImageCaptureDeviceBrowserMac* g_image_capture_device_browser; On 2012/12/12 20:53:20, sail wrote: > It doesn't seem like you really need a singleton. Callers should just grab an > instance from ChromeBrowserMainPartsMac. Yes. I can't see where that's exposed, though. What am I missing? https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:45: return [[ImageCaptureCameraInterface alloc] init:camera]; OK, I think I got this. Also changed the name to use "create". On 2012/12/12 20:53:20, sail wrote: > In Objective-C, the naming scheme implies the owner ship rule. If the name > begins with create or new then the caler owns the returned object. Otherwise the > caller should retain the returned object if it keeps a reference to it. > > In this case you should return an autoreleased object. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:55: // Method delegates for device added and removed On 2012/12/12 20:53:20, sail wrote: > don't need this Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:61: if (addedDevice.type & ICDeviceTypeCamera) { On 2012/12/12 20:53:20, sail wrote: > should do early return instead Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:62: ICCameraDevice* camera_device = (ICCameraDevice*)addedDevice; On 2012/12/12 20:53:20, sail wrote: > local variable names in Objective-C classes should be camel case Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:93: [self willChangeValueForKey:@"cameras"]; On 2012/12/12 20:53:20, sail wrote: > Are you planning on using key value observers? I'd recommend against that. No. This is boilerplate from the ImageCapture sample app. I don't know enough about Mac programming to know what's safe to remove. :-/ Is it OK to get rid of this?
https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:51: @interface ImageCaptureDeviceBrowserMac : On 2012/12/13 00:31:58, Greg Billock wrote: > On 2012/12/12 20:53:20, sail wrote: > > name isn't very descriptive. colon on the next line? same below > > Suggestion? The ImageCapture API calls this the DeviceBrowser, so I was > basically wrapping that. > > > > > As per my earlier comment, I'd make this a C++ class and remove everything > else > > from this file. > How about: ImageCaptureCameraInterface -> SystemMonitorICDeviceBrowserDelegate https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:54: ICDeviceBrowser* device_browser_; On 2012/12/13 00:31:58, Greg Billock wrote: > OK. Do I need to make a scoped_nsobject for my cameras_ member? Or since that's > getting synthesized it takes care of it? The sample ImageCapture code I was > following used this method. > > On 2012/12/12 20:53:20, sail wrote: > > Objective-C classes should use camel case variable names, something like > > deviceBrowser_. > > Also, all variables should be scoped_nsobject. If it's a weak reference then > add > > a comment explaining that instead. > Everything should be scoped_nsobject or a scoped_ptr, etc.. If it's a weak reference then it should have a comment about that (usually a // weak is sufficient) https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.h:68: @interface ImageCaptureCameraInterface : On 2012/12/13 00:31:58, Greg Billock wrote: > On 2012/12/12 20:53:20, sail wrote: > > name isn't very descriptive > > The idea is this class is what you use to get images from the camera. Better > ideas? ImageCaptureDeviceListener -> SystemMonitorICDeviceDelegate https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:13: ImageCaptureDeviceBrowserMac* g_image_capture_device_browser; On 2012/12/13 00:31:58, Greg Billock wrote: > On 2012/12/12 20:53:20, sail wrote: > > It doesn't seem like you really need a singleton. Callers should just grab an > > instance from ChromeBrowserMainPartsMac. > > Yes. I can't see where that's exposed, though. What am I missing? Ahh, you're right, k maybe have the C++ class be a singleton then https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:45: return [[ImageCaptureCameraInterface alloc] init:camera]; On 2012/12/13 00:31:58, Greg Billock wrote: > OK, I think I got this. Also changed the name to use "create". > > On 2012/12/12 20:53:20, sail wrote: > > In Objective-C, the naming scheme implies the owner ship rule. If the name > > begins with create or new then the caler owns the returned object. Otherwise > the > > caller should retain the returned object if it keeps a reference to it. > > > > In this case you should return an autoreleased object. > Actually, you should do one or the other. If you name it createDeviceByUUID: then it should return a [[Foo alloc] init]. If you name it openDeviceByUUID: then it should return a [[[Foo alloc] init] autorelease] https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:93: [self willChangeValueForKey:@"cameras"]; On 2012/12/13 00:31:58, Greg Billock wrote: > On 2012/12/12 20:53:20, sail wrote: > > Are you planning on using key value observers? I'd recommend against that. > > No. This is boilerplate from the ImageCapture sample app. I don't know enough > about Mac programming to know what's safe to remove. :-/ Is it OK to get rid of > this? Yea, it's safe to remove https://codereview.chromium.org/11442057/diff/13/chrome/browser/chrome_browse... File chrome/browser/chrome_browser_main_mac.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/chrome_browse... chrome/browser/chrome_browser_main_mac.h:37: scoped_ptr<Inner> inner_; this needs to reference a C++ class in system_monitor https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:21: class ImageCaptureDeviceListener { this should probably be moved to a separate header file https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:50: ICCameraDevice* camera_; scoped_nsobject https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:51: ImageCaptureDeviceListener* listener_; // weak https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:54: - (id)init:(ICCameraDevice*)camera_device; maybe initWithCameraDevice: https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:58: - (void)DidRenameDownloadFile:(const std::string&)name lowercase D https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:59: withError:(bool)rename_error; renameError https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:63: - (void)DownloadFile:(const std::string&)name lowercase D https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:64: localPath:(const FilePath&)local_path; localPath https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:16: camera_ = camera_device; init methods should be of the form: if ((self = [super init])) { .... } return self; https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:42: NSString* fileURLString = fileURLString and filename are confusing, one is the parent folder path and is the name of a file. maybe parentDirectoryPath and fileName https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:43: [NSString stringWithUTF8String:local_path.DirName().value().c_str()]; base::mac::FilePathToNSString(), more below https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:45: forKey:ICDownloadsDirectoryURL]; align colons, more below https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:51: [camera_ requestDownloadFile:(ICCameraFile*)item no C style casts should use base::mac::ObjCCastStrict<> here https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:70: info.size = 0; this is already initialized in the constructor, same with is_directory and is_symbolic_link https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:72: if ([[item UTI] isEqualToString:(NSString*)kUTTypeFolder]) no C style casts, use base::mac::CFToNSCast(kUTTypeFolder) instead https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:75: info.size = [(ICCameraFile*)item fileSize]; no C style casts, https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:78: base::Time::FromDoubleT([[item modificationDate] timeIntervalSince1970]); maybe move this to a utility function above, NSDateToBaseTime() https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:94: // Note: handled by ICDeviceBrowser::didRemoveDevice It's not clear what the ready/open etc.. are used for. The comment isn't very helpful either. For example, if you didn't have these two line then what would happen? https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:106: if (error == NULL) Objective-C uses nil in this caes this should just be if (!error) https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:112: // Notifies that the device is ready for commands (i.e. download images) i.e. -> e.g. period at end https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:124: if (device.type & ICDeviceTypeCamera) { no braces https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:125: [device.userData setValue:(id)kCFBooleanTrue forKey:@"complete"]; No C-style casts https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:131: // Delegates for ICCameraDeviceDownloadDelegate not needed https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:133: void RenameFileAndReturn(const std::string& name, move this to an anonymous namespace above https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:137: int64 edsize = 0; need to assert that this is on the file thread https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:140: [caller DidRenameDownloadFile:name withError:error]; is the caller thread safe? do you want to do this on the UI thread https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:143: - (void)didDownloadFile:(ICCameraFile*)file error:(NSError*)error one argument per line and line up colons https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:160: // !!! should really pass a weak pointer or a refptr or something. how about just retaining self here and releasing on callback https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:166: if (error) maybe just have an early return at the beginning, then you don't need the err variable https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:25: @interface ImageCaptureDeviceBrowserMac split this into a C++ and Objective-C class https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:29: NSMutableArray* cameras_; scoped_nsobject https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:39: - (ImageCaptureCameraInterface*)createCameraInterfaceForUUID:(std::string&)uuid; createCameraInterface -> cameraInterface.. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:43: + (ImageCaptureDeviceBrowserMac*)get; don't need this https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:14: ImageCaptureDeviceBrowserMac* g_image_capture_device_browser; don't need this https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:20: - (id)init { if ((self = [super init])) { } return self https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:21: cameras_ = [[NSMutableArray alloc] initWithCapacity:0]; just init] https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:24: deviceBrowser_.get().delegate = self; [deviceBrowser setDelegate:self] more below https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:26: deviceBrowser_.get().browsedDeviceTypeMask | [deviceBrowser browsedDeviceTypeMask] https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:40: - (ImageCaptureCameraInterface*)createCameraInterfaceForUUID: break the lien after the ) instead https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:44: if (base::SysNSStringToUTF8(camera_id) == uuid) { no braces https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:57: - (void)deviceBrowser:(ICDeviceBrowser*)browser align colons https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:58: didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing { one line per argument https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:62: ICCameraDevice* cameraDevice = (ICCameraDevice*)addedDevice; no C style casts https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:64: NSString* name = [addedDevice name]; no need for local variables if this is only used once (more below) https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( this isn't need, just use the data directly the function should be removed from disk_info_mac.h also
OK, Made a lot of ObjC improvements. Hopefully things are looking better now. Still a couple things to hash through and get the tests done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:45: return [[ImageCaptureCameraInterface alloc] init:camera]; On 2012/12/13 02:14:00, sail wrote: > On 2012/12/13 00:31:58, Greg Billock wrote: > > OK, I think I got this. Also changed the name to use "create". > > > > On 2012/12/12 20:53:20, sail wrote: > > > In Objective-C, the naming scheme implies the owner ship rule. If the name > > > begins with create or new then the caler owns the returned object. Otherwise > > the > > > caller should retain the returned object if it keeps a reference to it. > > > > > > In this case you should return an autoreleased object. > > > > Actually, you should do one or the other. > If you name it createDeviceByUUID: then it should return a [[Foo alloc] init]. > If you name it openDeviceByUUID: then it should return a [[[Foo alloc] init] > autorelease] Done. https://codereview.chromium.org/11442057/diff/1/chrome/browser/system_monitor... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:93: [self willChangeValueForKey:@"cameras"]; On 2012/12/13 02:14:00, sail wrote: > On 2012/12/13 00:31:58, Greg Billock wrote: > > On 2012/12/12 20:53:20, sail wrote: > > > Are you planning on using key value observers? I'd recommend against that. > > > > No. This is boilerplate from the ImageCapture sample app. I don't know enough > > about Mac programming to know what's safe to remove. :-/ Is it OK to get rid > of > > this? > > Yea, it's safe to remove Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/chrome_browse... File chrome/browser/chrome_browser_main_mac.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/chrome_browse... chrome/browser/chrome_browser_main_mac.h:37: scoped_ptr<Inner> inner_; On 2012/12/13 02:14:00, sail wrote: > this needs to reference a C++ class in system_monitor We want to keep this device notifications stuff in chrome::, not base::. If anything, we need to move the notifications out of SystemMonitor. We're working on that separately. I'll change the implementation to C++ and move the hiding layer into that code, though. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:21: class ImageCaptureDeviceListener { On 2012/12/13 02:14:00, sail wrote: > this should probably be moved to a separate header file Is that just to isolate the ObjC? I thought about making this an inner class for the CameraInterface. The way it's written, you can really only have ObjC clients for this whole IC subsystem. Is that frowned on and I should switch to a C++ interface only? https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:50: ICCameraDevice* camera_; On 2012/12/13 02:14:00, sail wrote: > scoped_nsobject Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:51: ImageCaptureDeviceListener* listener_; On 2012/12/13 02:14:00, sail wrote: > // weak Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:54: - (id)init:(ICCameraDevice*)camera_device; On 2012/12/13 02:14:00, sail wrote: > maybe initWithCameraDevice: Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:58: - (void)DidRenameDownloadFile:(const std::string&)name On 2012/12/13 02:14:00, sail wrote: > lowercase D This isn't public; should it even be here? https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:59: withError:(bool)rename_error; On 2012/12/13 02:14:00, sail wrote: > renameError Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:63: - (void)DownloadFile:(const std::string&)name On 2012/12/13 02:14:00, sail wrote: > lowercase D Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.h:64: localPath:(const FilePath&)local_path; On 2012/12/13 02:14:00, sail wrote: > localPath Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:16: camera_ = camera_device; On 2012/12/13 02:14:00, sail wrote: > init methods should be of the form: > if ((self = [super init])) { > .... > } > return self; Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:42: NSString* fileURLString = On 2012/12/13 02:14:00, sail wrote: > fileURLString and filename are confusing, one is the parent folder path and is > the name of a file. > > maybe parentDirectoryPath and fileName Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:43: [NSString stringWithUTF8String:local_path.DirName().value().c_str()]; Ah ha! That's what I was wanting. Is there an NSURL version that goes all the way? On 2012/12/13 02:14:00, sail wrote: > base::mac::FilePathToNSString(), more below https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:45: forKey:ICDownloadsDirectoryURL]; On 2012/12/13 02:14:00, sail wrote: > align colons, more below Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:45: forKey:ICDownloadsDirectoryURL]; On 2012/12/13 02:14:00, sail wrote: > align colons, more below Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:51: [camera_ requestDownloadFile:(ICCameraFile*)item On 2012/12/13 02:14:00, sail wrote: > no C style casts > should use base::mac::ObjCCastStrict<> here Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:70: info.size = 0; On 2012/12/13 02:14:00, sail wrote: > this is already initialized in the constructor, same with is_directory and > is_symbolic_link Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:72: if ([[item UTI] isEqualToString:(NSString*)kUTTypeFolder]) On 2012/12/13 02:14:00, sail wrote: > no C style casts, use base::mac::CFToNSCast(kUTTypeFolder) instead Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:75: info.size = [(ICCameraFile*)item fileSize]; On 2012/12/13 02:14:00, sail wrote: > no C style casts, Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:78: base::Time::FromDoubleT([[item modificationDate] timeIntervalSince1970]); On 2012/12/13 02:14:00, sail wrote: > maybe move this to a utility function above, NSDateToBaseTime() Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:94: // Note: handled by ICDeviceBrowser::didRemoveDevice On 2012/12/13 02:14:00, sail wrote: > It's not clear what the ready/open etc.. are used for. The comment isn't very > helpful either. > > For example, if you didn't have these two line then what would happen? Yeah, I'm not sure yet what kind of error handling makes sense, or how we need to relay it to the listener. I'll just take these out for now. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:106: if (error == NULL) On 2012/12/13 02:14:00, sail wrote: > Objective-C uses nil > in this caes this should just be if (!error) Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:112: // Notifies that the device is ready for commands (i.e. download images) Removed. On 2012/12/13 02:14:00, sail wrote: > i.e. -> e.g. > period at end https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:124: if (device.type & ICDeviceTypeCamera) { Removed On 2012/12/13 02:14:00, sail wrote: > no braces https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:125: [device.userData setValue:(id)kCFBooleanTrue forKey:@"complete"]; Removed On 2012/12/13 02:14:00, sail wrote: > No C-style casts https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:131: // Delegates for ICCameraDeviceDownloadDelegate On 2012/12/13 02:14:00, sail wrote: > not needed Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:133: void RenameFileAndReturn(const std::string& name, On 2012/12/13 02:14:00, sail wrote: > move this to an anonymous namespace above Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:137: int64 edsize = 0; file_util does this assert On 2012/12/13 02:14:00, sail wrote: > need to assert that this is on the file thread https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:140: [caller DidRenameDownloadFile:name withError:error]; On 2012/12/13 02:14:00, sail wrote: > is the caller thread safe? do you want to do this on the UI thread I need to think more about this. The calling situation for the media galleries is that the caller is on the browser blocking pool, but these ImageCapture notifications come in on the UI thread. I think ultimately the caller needs to be thread-safe, and whether I need to also add a mutex on listener for this object or can get by with something else. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:143: - (void)didDownloadFile:(ICCameraFile*)file error:(NSError*)error On 2012/12/13 02:14:00, sail wrote: > one argument per line and line up colons Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:160: // !!! should really pass a weak pointer or a refptr or something. On 2012/12/13 02:14:00, sail wrote: > how about just retaining self here and releasing on callback That'd work. The other problem is the listener. I need to either add weak ptr machinery for it or mutex-protect it. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:166: if (error) On 2012/12/13 02:14:00, sail wrote: > maybe just have an early return at the beginning, then you don't need the err > variable Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:25: @interface ImageCaptureDeviceBrowserMac On 2012/12/13 02:14:00, sail wrote: > split this into a C++ and Objective-C class Done. Moved the split from the ChromeMainPartsMac to here. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:29: NSMutableArray* cameras_; On 2012/12/13 02:14:00, sail wrote: > scoped_nsobject Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:39: - (ImageCaptureCameraInterface*)createCameraInterfaceForUUID:(std::string&)uuid; On 2012/12/13 02:14:00, sail wrote: > createCameraInterface -> cameraInterface.. Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.h:43: + (ImageCaptureDeviceBrowserMac*)get; On 2012/12/13 02:14:00, sail wrote: > don't need this What are you thinking as the alternative? The chrome:: interfaces can't be included in base::SystemMonitor, and there's no good accessor from BrowserMainParts. My ideal scenario would somehow expose that through BrowserContext, but I'm not sure if/how that ought to be arranged. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:20: - (id)init { Done. This guards the singleton? On 2012/12/13 02:14:00, sail wrote: > if ((self = [super init])) { > } > return self https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:21: cameras_ = [[NSMutableArray alloc] initWithCapacity:0]; On 2012/12/13 02:14:00, sail wrote: > just init] Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:24: deviceBrowser_.get().delegate = self; On 2012/12/13 02:14:00, sail wrote: > [deviceBrowser setDelegate:self] > more below Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:26: deviceBrowser_.get().browsedDeviceTypeMask | On 2012/12/13 02:14:00, sail wrote: > [deviceBrowser browsedDeviceTypeMask] Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:40: - (ImageCaptureCameraInterface*)createCameraInterfaceForUUID: On 2012/12/13 02:14:00, sail wrote: > break the lien after the ) instead Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:44: if (base::SysNSStringToUTF8(camera_id) == uuid) { On 2012/12/13 02:14:00, sail wrote: > no braces Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:57: - (void)deviceBrowser:(ICDeviceBrowser*)browser On 2012/12/13 02:14:00, sail wrote: > align colons Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:58: didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing { On 2012/12/13 02:14:00, sail wrote: > one line per argument Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:62: ICCameraDevice* cameraDevice = (ICCameraDevice*)addedDevice; Done. Is there an ObjC style that's better? On 2012/12/13 02:14:00, sail wrote: > no C style casts https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:64: NSString* name = [addedDevice name]; On 2012/12/13 02:14:00, sail wrote: > no need for local variables if this is only used once > (more below) Done. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( On 2012/12/13 02:14:00, sail wrote: > this isn't need, just use the data directly > the function should be removed from disk_info_mac.h also I'd rather keep the purpose-built factories than add setters for all the variables.
Looks pretty good! https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_camera.mm:140: [caller DidRenameDownloadFile:name withError:error]; On 2012/12/14 00:39:59, Greg Billock wrote: > On 2012/12/13 02:14:00, sail wrote: > > is the caller thread safe? do you want to do this on the UI thread > > I need to think more about this. The calling situation for the media galleries > is that the caller is on the browser blocking pool, but these ImageCapture > notifications come in on the UI thread. I think ultimately the caller needs to > be thread-safe, and whether I need to also add a mutex on listener for this > object or can get by with something else. This shouldn't be check in as is. If you'd like to commit this CL then remove this line and add a TODO saying you need to notify the caller. https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( On 2012/12/14 00:39:59, Greg Billock wrote: > On 2012/12/13 02:14:00, sail wrote: > > this isn't need, just use the data directly > > the function should be removed from disk_info_mac.h also > > I'd rather keep the purpose-built factories than add setters for all the > variables. I don't understand this. There's nothing in disk info that you're using. Just do: base::SystemMonitor::Get()->ProcessRemovableStorageAttached( chrome::MediaStorageUtil::MakeDeviceId( MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid), name, mountPoint) https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:49: @interface ImageCaptureCameraInterface I think SystemMonitorICDeviceDelegate would be better https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:53: // Weak pointer to this class' client. would it be possible to use weak_ptr<> ? https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:57: - (id)initWithCameraDevice:(ICCameraDevice*)camera_device; cameraDevice https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:59: - (void)close; Add a check in dealloc to ensure that close has been called? https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:36: camera_.reset(camera_device); camera_.reset([cameraDevice retain]) https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:56: localPath:(const FilePath&)localPath { line up colons https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:90: // Delegates for ICCameraDeviceDelegate don't need this https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:147: options:(NSDictionary*)options contextInfo:(void*)contextInfo { align colons, one argument per line https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:180: // !!! need to mutex-protect this listener This should be removed and just assert that you're on the UI thread. It would be good to avoid locks where possible. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:24: class ImageCaptureDeviceBrowser { I think SystemMonitorICDeviceBrowser would be a better name https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:37: @implementation ImageCaptureDeviceBrowserMac I think SystemMonitorICDeviceBrowserMac would be a better name. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:56: [deviceBrowser_ release]; deviceBrowser_.reset() https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:57: [cameras_ release]; cameras_.reset() https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:60: - (ImageCaptureCameraInterface*)cameraInterfaceForUUID:(const std::string&) break line after ) https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: // must call willChangeValueForKey to modify list. this can be removed https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:85: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( this can be removed https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:101: ICCameraDevice* cameraDevice = (ICCameraDevice*)device; no C style casts https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:107: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( this can be removed https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:117: // ImageCaptureDeviceBrowser implementation don't need this https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:119: chrome::ImageCaptureDeviceBrowser* g_image_capture_device_browser = NULL; move this to an anonymous namespace above
https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13/chrome/browser/system_monito... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( On 2012/12/14 01:26:32, sail wrote: > On 2012/12/14 00:39:59, Greg Billock wrote: > > On 2012/12/13 02:14:00, sail wrote: > > > this isn't need, just use the data directly > > > the function should be removed from disk_info_mac.h also > > > > I'd rather keep the purpose-built factories than add setters for all the > > variables. > > I don't understand this. > There's nothing in disk info that you're using. > Just do: > base::SystemMonitor::Get()->ProcessRemovableStorageAttached( > chrome::MediaStorageUtil::MakeDeviceId( > MediaStorageUtil::MAC_IMAGE_CAPTURE, uuid), > name, > mountPoint) Oy, thanks. The prehistory is that this class was owned by the RemovableDeviceNotificationsMac, but ObjC includes made that a pain. I've separately disentangled that, so I wonder whether that may end up making more sense than having it directly owned by the BrowserPartsMain at this point. Lei, what do you think? It kind of depends on whether we end up handling mass storage style attaches through ImageCapture or directly.
Tests coming up. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:57: - (id)initWithCameraDevice:(ICCameraDevice*)camera_device; On 2012/12/14 01:26:32, sail wrote: > cameraDevice Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:59: - (void)close; On 2012/12/14 01:26:32, sail wrote: > Add a check in dealloc to ensure that close has been called? Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:36: camera_.reset(camera_device); On 2012/12/14 01:26:32, sail wrote: > camera_.reset([cameraDevice retain]) Done. Does that mean I need to release in the destructor though? Or does scoped_nsobject do that itself? It seems to me like scoped_nsobject ought to be doing the retain call, though, right? https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:56: localPath:(const FilePath&)localPath { On 2012/12/14 01:26:32, sail wrote: > line up colons Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:90: // Delegates for ICCameraDeviceDelegate On 2012/12/14 01:26:32, sail wrote: > don't need this Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:147: options:(NSDictionary*)options contextInfo:(void*)contextInfo { Done. I think I have them all now. Whew! :-) On 2012/12/14 01:26:32, sail wrote: > align colons, one argument per line https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:180: // !!! need to mutex-protect this listener On 2012/12/14 01:26:32, sail wrote: > This should be removed and just assert that you're on the UI thread. There's at least three threads involved: the blocking pool thread for calls from the client, the UI thread for events from ImageCapture, and the File thread for this rename. > It would be good to avoid locks where possible. Yes. I'm trying to figure out whether weak ptrs and currying will do the trick better. OK, I think I have a solution. Not completely awesome, though. :-/ Will add comments. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:24: class ImageCaptureDeviceBrowser { On 2012/12/14 01:26:32, sail wrote: > I think SystemMonitorICDeviceBrowser would be a better name I suspect we'll end up not going through SystemMonitor at all. We do need to resolve that approach, though. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:56: [deviceBrowser_ release]; On 2012/12/14 01:26:32, sail wrote: > deviceBrowser_.reset() Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:57: [cameras_ release]; On 2012/12/14 01:26:32, sail wrote: > cameras_.reset() Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:60: - (ImageCaptureCameraInterface*)cameraInterfaceForUUID:(const std::string&) Done. I'm finding the intuition on these hard, even after looking over the style guide. :-/ On 2012/12/14 01:26:32, sail wrote: > break line after ) https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:73: // must call willChangeValueForKey to modify list. On 2012/12/14 01:26:32, sail wrote: > this can be removed Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:85: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( On 2012/12/14 01:26:32, sail wrote: > this can be removed Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:101: ICCameraDevice* cameraDevice = (ICCameraDevice*)device; Fixed up this whole method to match. On 2012/12/14 01:26:32, sail wrote: > no C style casts https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:107: chrome::DiskInfoMac info = chrome::DiskInfoMac::BuildDiskInfoFromICDevice( On 2012/12/14 01:26:32, sail wrote: > this can be removed Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:117: // ImageCaptureDeviceBrowser implementation On 2012/12/14 01:26:32, sail wrote: > don't need this Done. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:119: chrome::ImageCaptureDeviceBrowser* g_image_capture_device_browser = NULL; On 2012/12/14 01:26:32, sail wrote: > move this to an anonymous namespace above Done.
Everything looks really good! I think a really simple solution to the threading problem would be to do the following: - (void)didDownloadFile: { DCHECK(BrowserThread::UI) [self retain]; PostTask(BrowserThread::File, base::Bind(RenameFileAndReturn, self)); } - (void)didRenameDownloadFile: { DCHECK(BrowserThread::UI) if (listener) listener_->DownloadedFile() [self release]; // matches didDownloadFile } void RenameFileAndReturn(caller) { DCHECK(BrowserThread::FILE) ... PostTask(BrowserThread::UI, base::Bind(PerformReturn, caller)); } void PerformReturn(caller) { DCHECK(BrowserThread::UI) [caller didRenameDownloadFile:] } https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:36: camera_.reset(camera_device); On 2012/12/14 18:59:11, Greg Billock wrote: > On 2012/12/14 01:26:32, sail wrote: > > camera_.reset([cameraDevice retain]) > > Done. Does that mean I need to release in the destructor though? Or does > scoped_nsobject do that itself? It seems to me like scoped_nsobject ought to be > doing the retain call, though, right? scoped_nsobject is modeled after scoped_ptt. They both assume that the caller is giving up ownership. https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:24: class ImageCaptureDeviceBrowser { On 2012/12/14 18:59:11, Greg Billock wrote: > On 2012/12/14 01:26:32, sail wrote: > > I think SystemMonitorICDeviceBrowser would be a better name > > I suspect we'll end up not going through SystemMonitor at all. We do need to > resolve that approach, though. Sorry, I wasn't referring to the base/system_monitor API. I was referring to the module this code is in (chrome/browser/system_monitor). Ideally this should be named to reflect the module. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:59: // client supplies a WeakPtr callback interface. The reference to WeakPtr can be removed. WeakPtr isn't thread safe (it's just there for asynchronous callbacks). https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:64: // Weak pointer to this class' client. don't need this comment anymore https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:51: CHECK(![camera_ delegate]); DCHECK ? https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:97: didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { one argument per line https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:102: base::mac::ObjCCastStrict<ICCameraDevice>(device); It looks like you don't need this cast anymore. You can just call UUIDString on ICDevice directly.
Note there's now a test. Working on the second one... https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:24: class ImageCaptureDeviceBrowser { Ah, hmmm. We haven't really followed that elsewhere here, and I worry it'd be confusing. To me what these classes do is provide a wrapper on the ImageCapture library, so that's the main feature of their name. On 2012/12/14 19:27:32, sail wrote: > On 2012/12/14 18:59:11, Greg Billock wrote: > > On 2012/12/14 01:26:32, sail wrote: > > > I think SystemMonitorICDeviceBrowser would be a better name > > > > I suspect we'll end up not going through SystemMonitor at all. We do need to > > resolve that approach, though. > > Sorry, I wasn't referring to the base/system_monitor API. I was referring to the > module this code is in (chrome/browser/system_monitor). Ideally this should be > named to reflect the module. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:59: // client supplies a WeakPtr callback interface. Oops! Editing here was imperfect. Just removed this. I thought earlier about bouncing all the callbacks through a provided pool. That's really obnoxious, though. You think it's more obnoxious than demanding the client be thread-safe? Or is the expected convention that these callbacks will come on the UI thread, so I should just trampoline them to there. The thing is, that's doable, but a bit of work, and in practice will still mean the caller needs to be thread-safe. That's why I thought it wasn't worth it. I think we need a weakptr due to async callbacks, and if we thread-forward then obviously the weakptr will be nice for that, so I'm happy with it, but my instinct in tricky cases like this is usually to push complication out to clients. (A thread adapter client would be easy to write, for instance, and then isolates all that stuff away from the guts of this interface.) On 2012/12/14 19:27:32, sail wrote: > The reference to WeakPtr can be removed. WeakPtr isn't thread safe (it's just > there for asynchronous callbacks). https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:64: // Weak pointer to this class' client. On 2012/12/14 19:27:32, sail wrote: > don't need this comment anymore Done. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:51: CHECK(![camera_ delegate]); On 2012/12/14 19:27:32, sail wrote: > DCHECK ? Done. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.mm (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:97: didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing { On 2012/12/14 19:27:32, sail wrote: > one argument per line Done. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.mm:102: base::mac::ObjCCastStrict<ICCameraDevice>(device); On 2012/12/14 19:27:32, sail wrote: > It looks like you don't need this cast anymore. You can just call UUIDString on > ICDevice directly. Done.
https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/13001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:24: class ImageCaptureDeviceBrowser { On 2012/12/14 22:03:56, Greg Billock wrote: > Ah, hmmm. We haven't really followed that elsewhere here, and I worry it'd be > confusing. To me what these classes do is provide a wrapper on the ImageCapture > library, so that's the main feature of their name. > > On 2012/12/14 19:27:32, sail wrote: > > On 2012/12/14 18:59:11, Greg Billock wrote: > > > On 2012/12/14 01:26:32, sail wrote: > > > > I think SystemMonitorICDeviceBrowser would be a better name > > > > > > I suspect we'll end up not going through SystemMonitor at all. We do need to > > > resolve that approach, though. > > > > Sorry, I wasn't referring to the base/system_monitor API. I was referring to > the > > module this code is in (chrome/browser/system_monitor). Ideally this should be > > named to reflect the module. > In ui/cocoa/* we normally name the class after the feature it's implementing and not the API its using. For example, instead of MyTableDelegate it would be TaskManagerTableDelegate. This helps avoid confusion where we have lots of table delegates but they all do different things. https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.h (right): https://codereview.chromium.org/11442057/diff/14009/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.h:59: // client supplies a WeakPtr callback interface. On 2012/12/14 22:03:56, Greg Billock wrote: > Oops! Editing here was imperfect. Just removed this. > > I thought earlier about bouncing all the callbacks through a provided pool. > That's really obnoxious, though. You think it's more obnoxious than demanding > the client be thread-safe? Or is the expected convention that these callbacks > will come on the UI thread, so I should just trampoline them to there. The thing > is, that's doable, but a bit of work, and in practice will still mean the caller > needs to be thread-safe. That's why I thought it wasn't worth it. > > I think we need a weakptr due to async callbacks, and if we thread-forward then > obviously the weakptr will be nice for that, so I'm happy with it, but my > instinct in tricky cases like this is usually to push complication out to > clients. (A thread adapter client would be easy to write, for instance, and then > isolates all that stuff away from the guts of this interface.) > > On 2012/12/14 19:27:32, sail wrote: > > The reference to WeakPtr can be removed. WeakPtr isn't thread safe (it's just > > there for asynchronous callbacks). > WeakPtr is not thread safe. That means you can't pass it to RenameFileAndReturn. By having RenameFileAndReturn perform the callback on the UI thread you encapsulate all the threading issues into a single function.
https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:36: friend class ::ImageCaptureDeviceBrowserTest; It would be better to add a public accessor that returns a ICDeviceBrowserDelegate. That way you don't need this friend statement and the cast in the test. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:7: #import <ImageCaptureCore/ImageCaptureCore.h> newline after system includes https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:32: return @"id"; make this a constant above in an anonymous namespace? https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:48: @private space https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:94: ~TestCameraListener() {} virtual https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:114: std::vector<std::string> items_; private and add accessors as needed https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:128: ICCameraDevice* device = [MockICCameraDevice alloc]; scoped_nsobject, [[MockICCameraDevice alloc] init] same in DeatchDevice https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:131: browser->device_browser_.get()); change to use an accessor, same in DetachDevice https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:143: MessageLoop message_loop_; protected https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:156: EXPECT_EQ("ic:id", devices[0].device_id); use a constant for "id"? https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:171: [chrome::ImageCaptureDeviceBrowser::cameraInterfaceForUUID("id") retain]); use a constant for "id"? https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:191: [camera close]; add a test for DidRemoveDevice? test that removing the camera and calling cameraInterfaceForUUID returns nil?
https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:36: friend class ::ImageCaptureDeviceBrowserTest; On 2012/12/17 03:16:03, sail wrote: > It would be better to add a public accessor that returns a > ICDeviceBrowserDelegate. That way you don't need this friend statement and the > cast in the test. Sounds good. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:7: #import <ImageCaptureCore/ImageCaptureCore.h> On 2012/12/17 03:16:03, sail wrote: > newline after system includes Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:32: return @"id"; On 2012/12/17 03:16:03, sail wrote: > make this a constant above in an anonymous namespace? Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:48: @private On 2012/12/17 03:16:03, sail wrote: > space Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:94: ~TestCameraListener() {} On 2012/12/17 03:16:03, sail wrote: > virtual Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:114: std::vector<std::string> items_; I think that just adds noise to test-only objects. On 2012/12/17 03:16:03, sail wrote: > private and add accessors as needed https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:128: ICCameraDevice* device = [MockICCameraDevice alloc]; Yes. Saw this looking through the test as well. On 2012/12/17 03:16:03, sail wrote: > scoped_nsobject, > [[MockICCameraDevice alloc] init] > same in DeatchDevice https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:131: browser->device_browser_.get()); On 2012/12/17 03:16:03, sail wrote: > change to use an accessor, same in DetachDevice Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:143: MessageLoop message_loop_; On 2012/12/17 03:16:03, sail wrote: > protected Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:156: EXPECT_EQ("ic:id", devices[0].device_id); On 2012/12/17 03:16:03, sail wrote: > use a constant for "id"? Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:171: [chrome::ImageCaptureDeviceBrowser::cameraInterfaceForUUID("id") retain]); On 2012/12/17 03:16:03, sail wrote: > use a constant for "id"? Done. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:191: [camera close]; Added. I still need a couple more tests for the camera object. Shall I add them in follow-ups, though? This change is somewhat large as is... On 2012/12/17 03:16:03, sail wrote: > add a test for DidRemoveDevice? > test that removing the camera and calling cameraInterfaceForUUID returns nil?
Only nits left, everything else looks good. Also, what do you think of changing the names to SystemMonitorICDeviceBrowserDelegate and SystemMonitorICDeviceDelegate? https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:114: std::vector<std::string> items_; On 2012/12/17 23:20:41, Greg Billock wrote: > I think that just adds noise to test-only objects. > > On 2012/12/17 03:16:03, sail wrote: > > private and add accessors as needed > I've never seen a test do that. Only structs have public members. It's only one line of code more to add an accessor. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:191: [camera close]; On 2012/12/17 23:20:41, Greg Billock wrote: > Added. I still need a couple more tests for the camera object. Shall I add them > in follow-ups, though? This change is somewhat large as is... > > On 2012/12/17 03:16:03, sail wrote: > > add a test for DidRemoveDevice? > > test that removing the camera and calling cameraInterfaceForUUID returns nil? > I think now would be better. https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:36: // Return a weak pointer to the internal ImageCapture interface protocol. Return -> Returns https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:37: // Currently useful for unit tests. probably don't need https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:41: // friend class ::ImageCaptureDeviceBrowserTest; remove? https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:179: retain]); indent 3 more spaces
> Also, what do you think of changing the names to SystemMonitorICDeviceBrowserDelegate and SystemMonitorICDeviceDelegate? I prefer spelling out "ImageCapture" and not including any ref to "SystemMonitor", away from which I'm hoping we move. :-) Lei, what do you think? https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:114: std::vector<std::string> items_; ok, sure. On 2012/12/17 23:55:03, sail wrote: > On 2012/12/17 23:20:41, Greg Billock wrote: > > I think that just adds noise to test-only objects. > > > > On 2012/12/17 03:16:03, sail wrote: > > > private and add accessors as needed > > > > I've never seen a test do that. Only structs have public members. It's only one > line of code more to add an accessor. https://codereview.chromium.org/11442057/diff/24003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:191: [camera close]; Added. This was pretty low impact. Getting the downloads tested is going to take more oomph. And I think some of our bots run on <10.8, and this download delegate interface was introduced then, so I need to work around that. On 2012/12/17 23:55:03, sail wrote: > On 2012/12/17 23:20:41, Greg Billock wrote: > > Added. I still need a couple more tests for the camera object. Shall I add > them > > in follow-ups, though? This change is somewhat large as is... > > > > On 2012/12/17 03:16:03, sail wrote: > > > add a test for DidRemoveDevice? > > > test that removing the camera and calling cameraInterfaceForUUID returns > nil? > > > > I think now would be better. https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:36: // Return a weak pointer to the internal ImageCapture interface protocol. On 2012/12/17 23:55:03, sail wrote: > Return -> Returns Done. https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:37: // Currently useful for unit tests. On 2012/12/17 23:55:03, sail wrote: > probably don't need Done. https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:41: // friend class ::ImageCaptureDeviceBrowserTest; Oops! yes. On 2012/12/17 23:55:03, sail wrote: > remove? https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm (right): https://codereview.chromium.org/11442057/diff/30001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm:179: retain]); On 2012/12/17 23:55:03, sail wrote: > indent 3 more spaces Done.
I'm cool with spelling out ImageCapture, especially in the external bits that go into browser main, since readers there probably won't know what "IC" means. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/chrome_bro... File chrome/browser/chrome_browser_main_mac.mm (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/chrome_bro... chrome/browser/chrome_browser_main_mac.mm:26: #include "chrome/browser/system_monitor/image_capture_device_browser_mac.h" nit: move up 1 line. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:14: // This continuation runs on the file thread to rename a saved file if needed. Ading DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); makes for even better documentation. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:20: file_util::GetFileSize(downloaded_filename, &edsize); We are getting the file size but not using it. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:21: bool error = file_util::ReplaceFile(downloaded_filename, desired_filename); |error| should be renamed 'succeeded'. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:10: #include "base/file_path.h" nit: remove unused headers.
https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:14: // This continuation runs on the file thread to rename a saved file if needed. On 2012/12/19 00:30:52, Lei Zhang wrote: > Ading DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); > makes for even better documentation. +1 https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:18: base::WeakPtr<ImageCaptureDeviceListener> listener) { As per my earlier comment this won't work. See the earlier comment for a much better way to do this.
On 2012/12/19 00:05:08, Greg Billock wrote: > > Also, what do you think of changing the names to > SystemMonitorICDeviceBrowserDelegate and SystemMonitorICDeviceDelegate? > > I prefer spelling out "ImageCapture" That sounds good to me. > and not including any ref to > "SystemMonitor", away from which I'm hoping we move. :-) I don't have an opinion on SystemMonitor or something else. But simply naming this my TableDelegate is not ok. This needs a descriptive name that reflects the feature its implementing.
On 2012/12/19 01:20:15, sail wrote: > On 2012/12/19 00:05:08, Greg Billock wrote: > > > Also, what do you think of changing the names to > > SystemMonitorICDeviceBrowserDelegate and SystemMonitorICDeviceDelegate? > > > > I prefer spelling out "ImageCapture" > > That sounds good to me. > > > and not including any ref to > > "SystemMonitor", away from which I'm hoping we move. :-) > > I don't have an opinion on SystemMonitor or something else. But simply naming > this my TableDelegate is not ok. This needs a descriptive name that reflects the > feature its implementing. I'm not following. Current public names are "ImageCaptureDeviceBrowser" and "ImageCaptureCameraInterface". There's nothing named "xxxDelegate", although I do have a "ImageCaptureDeviceListener". Don't these describe them pretty well? I'm leaning towards "ImageCaptureDeviceManager" for the 'browser' (although I don't think using the mac-native name is bad). We could call the camera interface just "ImageCaptureCamera" or "ImageCaptureDevice". Would that be better? The "camera"/"device" ought to translate to the listener as well -- I think that'd be nicest.
I think the remaining issue is using WeakPtr handoff vs continuations to do the rename. I prefer just having one listener weak ptr there rather than coordinating through the manager (which means it'll need to support weak ptr as well), but if there's some flaw I'm not seeing, let me know. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/chrome_bro... File chrome/browser/chrome_browser_main_mac.mm (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/chrome_bro... chrome/browser/chrome_browser_main_mac.mm:26: #include "chrome/browser/system_monitor/image_capture_device_browser_mac.h" On 2012/12/19 00:30:52, Lei Zhang wrote: > nit: move up 1 line. Done. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_camera.mm (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:14: // This continuation runs on the file thread to rename a saved file if needed. On 2012/12/19 01:18:54, sail wrote: > On 2012/12/19 00:30:52, Lei Zhang wrote: > > Ading > DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); > > makes for even better documentation. > > +1 Done. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:18: base::WeakPtr<ImageCaptureDeviceListener> listener) { On 2012/12/19 01:18:54, sail wrote: > As per my earlier comment this won't work. > See the earlier comment for a much better way to do this. How so? I agree bouncing between the threads will work too, but I like this better -- requires no additional handoff between this continuation and the caller. It relies on thread safety in the listener, but that's already pretty much a certain requirement given other factors. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:20: file_util::GetFileSize(downloaded_filename, &edsize); On 2012/12/19 00:30:52, Lei Zhang wrote: > We are getting the file size but not using it. Thanks. This was leftover from logging trying to figure out what was going on with the downloaded file when I was discovering it invented its own name. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_camera.mm:21: bool error = file_util::ReplaceFile(downloaded_filename, desired_filename); On 2012/12/19 00:30:52, Lei Zhang wrote: > |error| should be renamed 'succeeded'. Done. https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_browser_mac.h (right): https://codereview.chromium.org/11442057/diff/43001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_browser_mac.h:10: #include "base/file_path.h" On 2012/12/19 00:30:52, Lei Zhang wrote: > nit: remove unused headers. Done.
On 2012/12/19 17:20:08, Greg Billock wrote: > I think the remaining issue is using WeakPtr handoff vs continuations to do the > rename. I prefer just having one listener weak ptr there rather than > coordinating through the manager (which means it'll need to support weak ptr as > well), but if there's some flaw I'm not seeing, let me know. What I've been trying to say is that it's not ok to pass a weak ptr to this function. I thought that part was obvious. The work around for that is dead simple. Here's the code I sent you in an earlier comment: - (void)didDownloadFile: { DCHECK(BrowserThread::UI) [self retain]; PostTask(BrowserThread::File, base::Bind(RenameFileAndReturn, self)); } - (void)didRenameDownloadFile: { DCHECK(BrowserThread::UI) if (listener) listener_->DownloadedFile() [self release]; // matches didDownloadFile } void RenameFileAndReturn(caller) { DCHECK(BrowserThread::FILE) ... PostTask(BrowserThread::UI, base::Bind(PerformReturn, caller)); } void PerformReturn(caller) { DCHECK(BrowserThread::UI) [caller didRenameDownloadFile:] }
ok. Reading weak_ptr.h file comment I see it isn't happy with this usage. I'd originally did the callback pretty much like this (one fewer step), but I believed WeakPtrs could tolerate thread-safe access, which looks like it is just not true. (Not sure whether that's unfortunate or not; this seems like a good use for them...) On Wed, Dec 19, 2012 at 9:49 AM, <sail@chromium.org> wrote: > On 2012/12/19 17:20:08, Greg Billock wrote: > >> I think the remaining issue is using WeakPtr handoff vs continuations to >> do >> > the > >> rename. I prefer just having one listener weak ptr there rather than >> coordinating through the manager (which means it'll need to support weak >> ptr >> > as > >> well), but if there's some flaw I'm not seeing, let me know. >> > > What I've been trying to say is that it's not ok to pass a weak ptr to this > function. I thought that part was obvious. The work around for that is dead > simple. Here's the code I sent you in an earlier comment: > > > - (void)didDownloadFile: { > DCHECK(BrowserThread::UI) > [self retain]; > PostTask(BrowserThread::File, base::Bind(**RenameFileAndReturn, self)); > } > > - (void)didRenameDownloadFile: { > DCHECK(BrowserThread::UI) > if (listener) > listener_->DownloadedFile() > [self release]; // matches didDownloadFile > } > > void RenameFileAndReturn(caller) { > DCHECK(BrowserThread::FILE) > ... > PostTask(BrowserThread::UI, base::Bind(PerformReturn, caller)); > } > > void PerformReturn(caller) { > DCHECK(BrowserThread::UI) > [caller didRenameDownloadFile:] > } > > > https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >
On 2012/12/19 18:24:02, Greg Billock wrote: > ok. Reading weak_ptr.h file comment I see it isn't happy with this usage. > I'd originally did the callback pretty much like this (one fewer step), but > I believed WeakPtrs could tolerate thread-safe access, which looks like it > is just not true. (Not sure whether that's unfortunate or not; this seems > like a good use for them...) For my own benefit, could you explain what was wrong with my original review feedback?
Also, you removed the call to BuildDiskInfoFromICDevice but you didn't update disk_info_mac.h and disk_info_mac.mm.
On 2012/12/19 18:29:43, sail wrote: > Also, you removed the call to BuildDiskInfoFromICDevice but you didn't update > disk_info_mac.h and disk_info_mac.mm. Done now. WRT the weak ptr, I switched strategy a bit, and decided to do the thread delegation within this code. I think that makes the contracts neater anyway, and now I believe this satisfies the weak ptr contract -- basically the idea is that the caller sets things up within their threading context, then passes that runner down and gets all callbacks in that context. I tried to comment that, but please double check to make sure it is clear enough.
https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.h (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.h:55: // Note on thread-safety. This class ends up involving three different threads. rest of this comment should be removed https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:226: [self release]; this isn't a good idea on the file thread https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:230: listener_, name, errorCode)); you can't do this on the file thread
https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:226: [self release]; On 2012/12/19 20:41:39, sail wrote: > this isn't a good idea on the file thread Really? are the NSObject refcounters not threadsafe? Will creation be safe, then? Because that's likely done in neither the UI nor FILE threads. https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:230: listener_, name, errorCode)); On 2012/12/19 20:41:39, sail wrote: > you can't do this on the file thread What do you mean by "this"?
https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:226: [self release]; On 2012/12/19 21:19:17, Greg Billock wrote: > On 2012/12/19 20:41:39, sail wrote: > > this isn't a good idea on the file thread > > Really? are the NSObject refcounters not threadsafe? Will creation be safe, > then? Because that's likely done in neither the UI nor FILE threads. The release may cause the object to be deleted. This means that the classes destructor and all member variables need to be thread safe which they are not. https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:230: listener_, name, errorCode)); On 2012/12/19 21:19:17, Greg Billock wrote: > On 2012/12/19 20:41:39, sail wrote: > > you can't do this on the file thread > > What do you mean by "this"? this -> listener_
https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:226: [self release]; On 2012/12/19 21:32:49, sail wrote: > On 2012/12/19 21:19:17, Greg Billock wrote: > > On 2012/12/19 20:41:39, sail wrote: > > > this isn't a good idea on the file thread > > > > Really? are the NSObject refcounters not threadsafe? Will creation be safe, > > then? Because that's likely done in neither the UI nor FILE threads. > > The release may cause the object to be deleted. This means that the classes > destructor and all member variables need to be thread safe which they are not. Docs specifically say it is safe to delete WeakPtr on another thread. Which member variable is the concern? I'm still a bit worried that there's a hole here where WeakPtr can be invalidated one place and then called, but I think I've read it carefully enough now that I'm sure that won't happen. Still, it is a bit subtle. I currently believe that if the caller manages itself on a single thread, the way WeakPtr wants to be, that this class is OK. https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:230: listener_, name, errorCode)); The docs say specifically that you can copy WeakPtr on other threads, just not use it. On 2012/12/19 21:32:49, sail wrote: > On 2012/12/19 21:19:17, Greg Billock wrote: > > On 2012/12/19 20:41:39, sail wrote: > > > you can't do this on the file thread > > > > What do you mean by "this"? > > this -> listener_
https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:226: [self release]; On 2012/12/19 22:08:55, Greg Billock wrote: > On 2012/12/19 21:32:49, sail wrote: > > On 2012/12/19 21:19:17, Greg Billock wrote: > > > On 2012/12/19 20:41:39, sail wrote: > > > > this isn't a good idea on the file thread > > > > > > Really? are the NSObject refcounters not threadsafe? Will creation be safe, > > > then? Because that's likely done in neither the UI nor FILE threads. > > > > The release may cause the object to be deleted. This means that the classes > > destructor and all member variables need to be thread safe which they are not. > > Docs specifically say it is safe to delete WeakPtr on another thread. Which > member variable is the concern? > > I'm still a bit worried that there's a hole here where WeakPtr can be > invalidated one place and then called, but I think I've read it carefully enough > now that I'm sure that won't happen. Still, it is a bit subtle. I currently > believe that if the caller manages itself on a single thread, the way WeakPtr > wants to be, that this class is OK. I don't think you are correct. Basically WeakPtr<Foo> is the same as Foo* except that it does some magic when Foo is deleted. So instead of WeakPtr<Foo> my_ptr, lets imagine you just have Foo* my_ptr. In this function you are referencing my_ptr at the same time another function (lets say setListener) might be referencing it as well. To fix this you either have to make this class thread safe or do a (very very very simple) modification I suggested 6 days ago.
The alternative you've suggested still conflicts in the same way with setListener as the present state does, so switching to it buys us nothing. The reason is that setListener can be (and is) called by a thread which is neither the UI nor the FILE thread. That's what the existing comment says. I'm still concerned I've got a problem here, but I don't think your solution works. Going to look some more.... On Wed, Dec 19, 2012 at 2:52 PM, <sail@chromium.org> wrote: > > https://codereview.chromium.**org/11442057/diff/49003/** > chrome/browser/system_monitor/**image_capture_device.mm<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm> > File chrome/browser/system_monitor/**image_capture_device.mm<http://image_capture_device.mm>(right): > > https://codereview.chromium.**org/11442057/diff/49003/** > chrome/browser/system_monitor/**image_capture_device.mm#**newcode226<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm#newcode226> > chrome/browser/system_monitor/**image_capture_device.mm:226<http://image_capture_device.mm:226>: > [self > release]; > On 2012/12/19 22:08:55, Greg Billock wrote: > >> On 2012/12/19 21:32:49, sail wrote: >> > On 2012/12/19 21:19:17, Greg Billock wrote: >> > > On 2012/12/19 20:41:39, sail wrote: >> > > > this isn't a good idea on the file thread >> > > >> > > Really? are the NSObject refcounters not threadsafe? Will creation >> > be safe, > >> > > then? Because that's likely done in neither the UI nor FILE >> > threads. > >> > >> > The release may cause the object to be deleted. This means that the >> > classes > >> > destructor and all member variables need to be thread safe which >> > they are not. > > Docs specifically say it is safe to delete WeakPtr on another thread. >> > Which > >> member variable is the concern? >> > > I'm still a bit worried that there's a hole here where WeakPtr can be >> invalidated one place and then called, but I think I've read it >> > carefully enough > >> now that I'm sure that won't happen. Still, it is a bit subtle. I >> > currently > >> believe that if the caller manages itself on a single thread, the way >> > WeakPtr > >> wants to be, that this class is OK. >> > > I don't think you are correct. > > Basically WeakPtr<Foo> is the same as Foo* except that it does some > magic when Foo is deleted. > > So instead of WeakPtr<Foo> my_ptr, lets imagine you just have Foo* > my_ptr. In this function you are referencing my_ptr at the same time > another function (lets say setListener) might be referencing it as well. > > To fix this you either have to make this class thread safe or do a (very > very very simple) modification I suggested 6 days ago. > > https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >
Looking carefully at weak_ptr.h, I think the thread behavior is more iffy than the comments say -- the copy constructor uses get(), so if that's not thread safe (it isn't), then while you can copy on another thread and get a valid object, you shouldn't do it unless that thread is sequenced with the originating thread of the WeakPtr anyway. :-( I think the goal of having the interface object interact in the provided worker pool is a good one, but I need to find a better way to do it. Nothing we have so far accomplishes that. On Wed, Dec 19, 2012 at 3:35 PM, Greg Billock <gbillock@chromium.org> wrote: > The alternative you've suggested still conflicts in the same way with > setListener as the present state does, so switching to it buys us nothing. > The reason is that setListener can be (and is) called by a thread which is > neither the UI nor the FILE thread. That's what the existing comment says. > > I'm still concerned I've got a problem here, but I don't think your > solution works. Going to look some more.... > > > > On Wed, Dec 19, 2012 at 2:52 PM, <sail@chromium.org> wrote: > >> >> https://codereview.chromium.**org/11442057/diff/49003/** >> chrome/browser/system_monitor/**image_capture_device.mm<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm> >> File chrome/browser/system_monitor/**image_capture_device.mm<http://image_capture_device.mm>(right): >> >> https://codereview.chromium.**org/11442057/diff/49003/** >> chrome/browser/system_monitor/**image_capture_device.mm#**newcode226<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm#newcode226> >> chrome/browser/system_monitor/**image_capture_device.mm:226<http://image_capture_device.mm:226>: >> [self >> release]; >> On 2012/12/19 22:08:55, Greg Billock wrote: >> >>> On 2012/12/19 21:32:49, sail wrote: >>> > On 2012/12/19 21:19:17, Greg Billock wrote: >>> > > On 2012/12/19 20:41:39, sail wrote: >>> > > > this isn't a good idea on the file thread >>> > > >>> > > Really? are the NSObject refcounters not threadsafe? Will creation >>> >> be safe, >> >>> > > then? Because that's likely done in neither the UI nor FILE >>> >> threads. >> >>> > >>> > The release may cause the object to be deleted. This means that the >>> >> classes >> >>> > destructor and all member variables need to be thread safe which >>> >> they are not. >> >> Docs specifically say it is safe to delete WeakPtr on another thread. >>> >> Which >> >>> member variable is the concern? >>> >> >> I'm still a bit worried that there's a hole here where WeakPtr can be >>> invalidated one place and then called, but I think I've read it >>> >> carefully enough >> >>> now that I'm sure that won't happen. Still, it is a bit subtle. I >>> >> currently >> >>> believe that if the caller manages itself on a single thread, the way >>> >> WeakPtr >> >>> wants to be, that this class is OK. >>> >> >> I don't think you are correct. >> >> Basically WeakPtr<Foo> is the same as Foo* except that it does some >> magic when Foo is deleted. >> >> So instead of WeakPtr<Foo> my_ptr, lets imagine you just have Foo* >> my_ptr. In this function you are referencing my_ptr at the same time >> another function (lets say setListener) might be referencing it as well. >> >> To fix this you either have to make this class thread safe or do a (very >> very very simple) modification I suggested 6 days ago. >> >> https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >> > >
OK, Took out using the source pool, and now just uses the UI thread. I didn't add in DCHECKs for this in this patch, as it'll make the test more painful. On Wed, Dec 19, 2012 at 4:06 PM, Greg Billock <gbillock@chromium.org> wrote: > Looking carefully at weak_ptr.h, I think the thread behavior is more iffy > than the comments say -- the copy constructor uses get(), so if that's not > thread safe (it isn't), then while you can copy on another thread and get a > valid object, you shouldn't do it unless that thread is sequenced with the > originating thread of the WeakPtr anyway. :-( > > I think the goal of having the interface object interact in the provided > worker pool is a good one, but I need to find a better way to do it. > Nothing we have so far accomplishes that. > > > On Wed, Dec 19, 2012 at 3:35 PM, Greg Billock <gbillock@chromium.org>wrote: > >> The alternative you've suggested still conflicts in the same way with >> setListener as the present state does, so switching to it buys us nothing. >> The reason is that setListener can be (and is) called by a thread which is >> neither the UI nor the FILE thread. That's what the existing comment says. >> >> I'm still concerned I've got a problem here, but I don't think your >> solution works. Going to look some more.... >> >> >> >> On Wed, Dec 19, 2012 at 2:52 PM, <sail@chromium.org> wrote: >> >>> >>> https://codereview.chromium.**org/11442057/diff/49003/** >>> chrome/browser/system_monitor/**image_capture_device.mm<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm> >>> File chrome/browser/system_monitor/**image_capture_device.mm<http://image_capture_device.mm>(right): >>> >>> https://codereview.chromium.**org/11442057/diff/49003/** >>> chrome/browser/system_monitor/**image_capture_device.mm#**newcode226<https://codereview.chromium.org/11442057/diff/49003/chrome/browser/system_monitor/image_capture_device.mm#newcode226> >>> chrome/browser/system_monitor/**image_capture_device.mm:226<http://image_capture_device.mm:226>: >>> [self >>> release]; >>> On 2012/12/19 22:08:55, Greg Billock wrote: >>> >>>> On 2012/12/19 21:32:49, sail wrote: >>>> > On 2012/12/19 21:19:17, Greg Billock wrote: >>>> > > On 2012/12/19 20:41:39, sail wrote: >>>> > > > this isn't a good idea on the file thread >>>> > > >>>> > > Really? are the NSObject refcounters not threadsafe? Will creation >>>> >>> be safe, >>> >>>> > > then? Because that's likely done in neither the UI nor FILE >>>> >>> threads. >>> >>>> > >>>> > The release may cause the object to be deleted. This means that the >>>> >>> classes >>> >>>> > destructor and all member variables need to be thread safe which >>>> >>> they are not. >>> >>> Docs specifically say it is safe to delete WeakPtr on another thread. >>>> >>> Which >>> >>>> member variable is the concern? >>>> >>> >>> I'm still a bit worried that there's a hole here where WeakPtr can be >>>> invalidated one place and then called, but I think I've read it >>>> >>> carefully enough >>> >>>> now that I'm sure that won't happen. Still, it is a bit subtle. I >>>> >>> currently >>> >>>> believe that if the caller manages itself on a single thread, the way >>>> >>> WeakPtr >>> >>>> wants to be, that this class is OK. >>>> >>> >>> I don't think you are correct. >>> >>> Basically WeakPtr<Foo> is the same as Foo* except that it does some >>> magic when Foo is deleted. >>> >>> So instead of WeakPtr<Foo> my_ptr, lets imagine you just have Foo* >>> my_ptr. In this function you are referencing my_ptr at the same time >>> another function (lets say setListener) might be referencing it as well. >>> >>> To fix this you either have to make this class thread safe or do a (very >>> very very simple) modification I suggested 6 days ago. >>> >>> https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >>> >> >> >
https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:27: scoped_ptr<base::PlatformFileError> result_deleter(result); I think there's a memory leak here. If the listener is deleted then this function will never get called and the result will be leaked.
https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:27: scoped_ptr<base::PlatformFileError> result_deleter(result); On 2012/12/20 01:08:24, sail wrote: > I think there's a memory leak here. > If the listener is deleted then this function will never get called and the > result will be leaked. My understanding from docs and looking at the implementation is that PostTaskAndReply will call this reply closure unconditionally (and on the calling thread), as soon as the task closure returns. (base/threading/post_task_and_reply_impl.cc is what eventually ends up handling this)
https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:27: scoped_ptr<base::PlatformFileError> result_deleter(result); On 2012/12/20 16:31:52, Greg Billock wrote: > On 2012/12/20 01:08:24, sail wrote: > > I think there's a memory leak here. > > If the listener is deleted then this function will never get called and the > > result will be leaked. > > My understanding from docs and looking at the implementation is that > PostTaskAndReply will call this reply closure unconditionally (and on the > calling thread), as soon as the task closure returns. > (base/threading/post_task_and_reply_impl.cc is what eventually ends up handling > this) Ahh, you're right. https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:150: - (void)didDownloadFile:(ICCameraFile*)file now that this code is working could you add a test for this? Either by making this method public or by calling downloadFile:.
https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/52004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:150: - (void)didDownloadFile:(ICCameraFile*)file On 2012/12/20 18:34:54, sail wrote: > now that this code is working could you add a test for this? Either by making > this method public or by calling downloadFile:. Definitely. Now added, along with UI thread checks in this class to make sure the contracts get followed correctly by clients.
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:159: downloads_.push_back(name); check the thread ID here? https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:193: ICCameraDevice* device = [MockICCameraDevice alloc]; should be MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] autorelease]; https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) should remove the cast and have AttachedDevice return a MockICCameraDevice type. https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:301: ASSERT_EQ(0U, listener_.downloads().size()); expect_eq https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:304: localPath:temp_dir.path().Append("tempfile")]; make tempfile a const above this line? https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:310: [camera downloadFile:std::string("pic1") make pic1 a constant above this line https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:320: EXPECT_EQ("test", std::string(file_contents, 4)); make "test" a constant at the top of this file?
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:159: downloads_.push_back(name); On 2012/12/21 02:47:10, sail wrote: > check the thread ID here? Done. https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) I wanted to do this, but when I did, the call to [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; above fails, presumably because the compile-time type id is different, and so doesn't bind to the right message handler? I wrestled with that for a while, but in the end, just went back to this. It seems like there must be a better way, though. On 2012/12/21 02:47:10, sail wrote: > should remove the cast and have AttachedDevice return a MockICCameraDevice type. https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:301: ASSERT_EQ(0U, listener_.downloads().size()); On 2012/12/21 02:47:10, sail wrote: > expect_eq Done. https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:304: localPath:temp_dir.path().Append("tempfile")]; On 2012/12/21 02:47:10, sail wrote: > make tempfile a const above this line? Done. https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:310: [camera downloadFile:std::string("pic1") Done, kinda. I can't figure out how to make @"pic1" use the constant. All I get is double-deletes, which is a pretty shocking outcome for changing the init method to take a copy and passing in [NSString stringWithUTF8String:kxxx]. I guess I don't understand this stuff as well as I thought. :-/ On 2012/12/21 02:47:10, sail wrote: > make pic1 a constant above this line https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:320: EXPECT_EQ("test", std::string(file_contents, 4)); On 2012/12/21 02:47:10, sail wrote: > make "test" a constant at the top of this file? Done.
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) On 2012/12/21 20:05:38, Greg Billock wrote: > I wanted to do this, but when I did, the call to > [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; above > fails, presumably because the compile-time type id is different, and so doesn't > bind to the right message handler? I wrestled with that for a while, but in the > end, just went back to this. It seems like there must be a better way, though. > > On 2012/12/21 02:47:10, sail wrote: > > should remove the cast and have AttachedDevice return a MockICCameraDevice > type. > Hm.. that's really weird, it shouldn't fail. What's the compile error you get? https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:27: scoped_ptr<base::PlatformFileError> result_deleter(result); DCHECK that this is called on the UI thread https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:176: // ImageCapture did not save the file into the name we give it in the give -> gave https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:10: #include <string> no new line before this, new line after this https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:9: #import "chrome/browser/system_monitor/image_capture_device.h" not alphabetically ordered https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:52: deviceBrowser_.get().browsedDeviceTypeMask = [deviceBrowser setBrowsedDeviceTypeMask:] https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:129: base::mac::ObjCCastStrict<ImageCaptureDeviceManagerImpl>( I don't think you need this cast https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:84: FilePath toBeSaved = saveDir.Append(saveAsFilename); maybe avoid a new local variable by doing saveDir = saveDir.Append() https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:85: ASSERT_EQ(static_cast<int>(strlen(kTestFileContents)), EXPECT_EQ ? https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:86: file_util::WriteFile(toBeSaved, kTestFileContents, could this be moved to the test? currently it's hard to follow the test because it's not clear that a file is being created and then renamed. if not could you add a comment to the test about the set of events that are supposed to happen? https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:162: DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); EXPECT_TRUE ? https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:182: base::PlatformFileError last_error_; needs to be initialized in constructor https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:197: ICCameraDevice* device = [MockICCameraDevice alloc]; should be MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] autorelease]; https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:238: scoped_nsobject<ImageCaptureDevice> camera( you don't even need the scoped_nsobject here, you could just do: ImageCaptureDevcie* camera = chrome::ImageCaptureDeviceManager::deviceForUUID(kDeviceId) (not a big deal) https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:270: scoped_nsobject<ImageCaptureDevice> camera( same as above, no need for scoped_nsobject + retain https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:289: scoped_nsobject<ImageCaptureDevice> camera( same as above, no need for scoped_nsobject + retain https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:316: [camera downloadFile:std::string(kTestFileName) localPath:temp_file]; instead of creating std::string here just change the type of kTestFileName to an std::string?
On Wed, Dec 26, 2012 at 10:52 AM, <sail@chromium.org> wrote: > > https://codereview.chromium.**org/11442057/diff/53011/** > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm> > File > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<http://image_capture_device_manager_unittest.mm> > (right): > > https://codereview.chromium.**org/11442057/diff/53011/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode294<https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode294> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:294 <http://image_capture_device_manager_unittest.mm:294>: > [base::mac::ObjCCastStrict<**MockICCameraDevice>(device) > On 2012/12/21 20:05:38, Greg Billock wrote: > >> I wanted to do this, but when I did, the call to >> [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; above >> fails, presumably because the compile-time type id is different, and >> > so doesn't > >> bind to the right message handler? I wrestled with that for a while, >> > but in the > >> end, just went back to this. It seems like there must be a better way, >> > though. > > On 2012/12/21 02:47:10, sail wrote: >> > should remove the cast and have AttachedDevice return a >> > MockICCameraDevice > >> type. >> > > > Hm.. that's really weird, it shouldn't fail. What's the compile error > you get? > No compile error -- just no runtime message delivery. > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device.mm<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device.mm> > File chrome/browser/system_monitor/**image_capture_device.mm<http://image_capture_device.mm>(right): > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device.mm#**newcode27<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device.mm#newcode27> > > chrome/browser/system_monitor/**image_capture_device.mm:27<http://image_capture_device.mm:27> > : > scoped_ptr<base::**PlatformFileError> result_deleter(result); > DCHECK that this is called on the UI thread > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device.mm#**newcode176<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device.mm#newcode176> > chrome/browser/system_monitor/**image_capture_device.mm:176<http://image_capture_device.mm:176>: > // > ImageCapture did not save the file into the name we give it in the > give -> gave > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.h<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.h> > File chrome/browser/system_monitor/**image_capture_device_manager.h > (right): > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.**h#newcode10<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.h#newcode10> > chrome/browser/system_monitor/**image_capture_device_manager.**h:10: > #include <string> > no new line before this, new line after this > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.**mm<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.mm> > File chrome/browser/system_monitor/**image_capture_device_manager.**mm<http://image_capture_device_manager.mm> > (right): > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.**mm#newcode9<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.mm#newcode9> > chrome/browser/system_monitor/**image_capture_device_manager.**mm:9<http://image_capture_device_manager.mm:9>: > #import > "chrome/browser/system_**monitor/image_capture_device.**h" > not alphabetically ordered > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.** > mm#newcode52<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.mm#newcode52> > chrome/browser/system_monitor/**image_capture_device_manager.**mm:52<http://image_capture_device_manager.mm:52> > : > deviceBrowser_.get().**browsedDeviceTypeMask = > [deviceBrowser setBrowsedDeviceTypeMask:] > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager.** > mm#newcode129<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager.mm#newcode129> > chrome/browser/system_monitor/**image_capture_device_manager.**mm:129<http://image_capture_device_manager.mm:129> > : > base::mac::ObjCCastStrict<**ImageCaptureDeviceManagerImpl>**( > I don't think you need this cast > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm> > File > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<http://image_capture_device_manager_unittest.mm> > (right): > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode84<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode84> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:84 <http://image_capture_device_manager_unittest.mm:84>: > FilePath toBeSaved = saveDir.Append(saveAsFilename)**; > maybe avoid a new local variable by doing saveDir = saveDir.Append() > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode85<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode85> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:85 <http://image_capture_device_manager_unittest.mm:85>: > ASSERT_EQ(static_cast<int>(**strlen(kTestFileContents)), > EXPECT_EQ ? > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode86<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode86> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:86 <http://image_capture_device_manager_unittest.mm:86>: > file_util::WriteFile(**toBeSaved, kTestFileContents, > could this be moved to the test? currently it's hard to follow the test > because it's not clear that a file is being created and then renamed. > > if not could you add a comment to the test about the set of events that > are supposed to happen? > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode162<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode162> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:162 <http://image_capture_device_manager_unittest.mm:162>: > DCHECK(content::BrowserThread:**:CurrentlyOn(content::** > BrowserThread::UI)); > EXPECT_TRUE ? > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode182<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode182> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:182 <http://image_capture_device_manager_unittest.mm:182>: > base::PlatformFileError last_error_; > needs to be initialized in constructor > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode197<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode197> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:197 <http://image_capture_device_manager_unittest.mm:197>: > > ICCameraDevice* device = [MockICCameraDevice alloc]; > should be > MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] > autorelease]; > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode238<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode238> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:238 <http://image_capture_device_manager_unittest.mm:238>: > scoped_nsobject<**ImageCaptureDevice> camera( > you don't even need the scoped_nsobject here, you could just do: > ImageCaptureDevcie* camera = > chrome::**ImageCaptureDeviceManager::**deviceForUUID(kDeviceId) > > (not a big deal) > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode270<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode270> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:270 <http://image_capture_device_manager_unittest.mm:270>: > scoped_nsobject<**ImageCaptureDevice> camera( > same as above, no need for scoped_nsobject + retain > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode289<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode289> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:289 <http://image_capture_device_manager_unittest.mm:289>: > scoped_nsobject<**ImageCaptureDevice> camera( > same as above, no need for scoped_nsobject + retain > > https://codereview.chromium.**org/11442057/diff/56001/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode316<https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode316> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:316 <http://image_capture_device_manager_unittest.mm:316>: > [camera downloadFile:std::string(**kTestFileName) localPath:temp_file]; > instead of creating std::string here just change the type of > kTestFileName to an std::string? > > https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) > No compile error -- just no runtime message delivery. There's no strong typing on method dispatch. If doing: MockICCameraDevice* foo = ... vs ICCameraDevcie* foo = ... changes things then there's some other problem. In this case -[ImageCaptureDeviceManagerImpl deviceBrowser:didAddDevice:moreComing:] didn't get called right? I would try several things: - EXPECT_TRUE(delegate) - EXPECT_TRUE(device) - printf in deviceBrowser:ddiAddDevice:
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) OK, it must have been some other simultaneous change I made that messed it up. It works fine. On 2012/12/26 20:48:47, sail wrote: > > No compile error -- just no runtime message delivery. > > There's no strong typing on method dispatch. If doing: > MockICCameraDevice* foo = ... > vs > ICCameraDevcie* foo = ... > changes things then there's some other problem. > > In this case -[ImageCaptureDeviceManagerImpl > deviceBrowser:didAddDevice:moreComing:] didn't get called right? I would try > several things: > - EXPECT_TRUE(delegate) > - EXPECT_TRUE(device) > - printf in deviceBrowser:ddiAddDevice: https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:27: scoped_ptr<base::PlatformFileError> result_deleter(result); On 2012/12/26 18:52:37, sail wrote: > DCHECK that this is called on the UI thread Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device.mm:176: // ImageCapture did not save the file into the name we give it in the On 2012/12/26 18:52:37, sail wrote: > give -> gave Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:10: #include <string> On 2012/12/26 18:52:37, sail wrote: > no new line before this, new line after this Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:9: #import "chrome/browser/system_monitor/image_capture_device.h" On 2012/12/26 18:52:37, sail wrote: > not alphabetically ordered Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:52: deviceBrowser_.get().browsedDeviceTypeMask = On 2012/12/26 18:52:37, sail wrote: > [deviceBrowser setBrowsedDeviceTypeMask:] Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:129: base::mac::ObjCCastStrict<ImageCaptureDeviceManagerImpl>( On 2012/12/26 18:52:37, sail wrote: > I don't think you need this cast Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:84: FilePath toBeSaved = saveDir.Append(saveAsFilename); On 2012/12/26 18:52:37, sail wrote: > maybe avoid a new local variable by doing saveDir = saveDir.Append() Could do, It isn't a directory though. I don't think it's that bad. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:85: ASSERT_EQ(static_cast<int>(strlen(kTestFileContents)), On 2012/12/26 18:52:37, sail wrote: > EXPECT_EQ ? This is more a low-level thing, so it if fails, it likely isn't this test, so I think ASSERT is a better choice. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:86: file_util::WriteFile(toBeSaved, kTestFileContents, On 2012/12/26 18:52:37, sail wrote: > could this be moved to the test? currently it's hard to follow the test because > it's not clear that a file is being created and then renamed. > > if not could you add a comment to the test about the set of events that are > supposed to happen? It can't really be moved, since this mimics the behavior of the actual platform object. Agreed it is hard to follow! I discovered it by trial and error. :-( I'll add comments. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:162: DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); On 2012/12/26 18:52:37, sail wrote: > EXPECT_TRUE ? Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:182: base::PlatformFileError last_error_; On 2012/12/26 18:52:37, sail wrote: > needs to be initialized in constructor Done. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:197: ICCameraDevice* device = [MockICCameraDevice alloc]; On 2012/12/26 18:52:37, sail wrote: > should be > MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] autorelease]; Making this change makes the registrations fail, presumably because of the autorelease? I thought that since the delegate takes ownership, I should just use alloc, and since there's no init receiver, it wasn't necessary to invoke. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:238: scoped_nsobject<ImageCaptureDevice> camera( On 2012/12/26 18:52:37, sail wrote: > you don't even need the scoped_nsobject here, you could just do: > ImageCaptureDevcie* camera = > chrome::ImageCaptureDeviceManager::deviceForUUID(kDeviceId) > > (not a big deal) deviceForUUID is creating a new one, though. Won't that then leak? https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:316: [camera downloadFile:std::string(kTestFileName) localPath:temp_file]; On 2012/12/26 18:52:37, sail wrote: > instead of creating std::string here just change the type of kTestFileName to an > std::string? Done.
https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/53011/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:294: [base::mac::ObjCCastStrict<MockICCameraDevice>(device) On 2013/01/03 20:59:55, Greg Billock wrote: > OK, it must have been some other simultaneous change I made that messed it up. > It works fine. > > On 2012/12/26 20:48:47, sail wrote: > > > No compile error -- just no runtime message delivery. > > > > There's no strong typing on method dispatch. If doing: > > MockICCameraDevice* foo = ... > > vs > > ICCameraDevcie* foo = ... > > changes things then there's some other problem. > > > > In this case -[ImageCaptureDeviceManagerImpl > > deviceBrowser:didAddDevice:moreComing:] didn't get called right? I would try > > several things: > > - EXPECT_TRUE(delegate) > > - EXPECT_TRUE(device) > > - printf in deviceBrowser:ddiAddDevice: > Ahh cool. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:84: FilePath toBeSaved = saveDir.Append(saveAsFilename); On 2013/01/03 20:59:55, Greg Billock wrote: > On 2012/12/26 18:52:37, sail wrote: > > maybe avoid a new local variable by doing saveDir = saveDir.Append() > > Could do, It isn't a directory though. I don't think it's that bad. Ah, ok to leave as is then. https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:197: ICCameraDevice* device = [MockICCameraDevice alloc]; On 2013/01/03 20:59:55, Greg Billock wrote: > On 2012/12/26 18:52:37, sail wrote: > > should be > > MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] autorelease]; > > Making this change makes the registrations fail, presumably because of the > autorelease? I did a quick audit of the code and couldn't find anyplace that would cause this to crash. There was a small error in -[ImageCaptureDeviceManagerImpl deviceBrowser:didRemoveDevice:...] but that wouldn't cause a crash in this case. Could you apply this change and show me steps to reproduce the crash? I can try to figure out what's going on. > I thought that since the delegate takes ownership, I should just > use alloc, and since there's no init receiver, it wasn't necessary to invoke. Alloc should always be followed by an init. ICCameraDevice and ICDevice don't have a designated initializer. NSObject's designated initializer is -init which is what you should call here. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:103: [cameras_ removeObject:device]; At this point device may be deleted. You can do something like this to make sure it stays alive: scoped_nsobject<IDDevice> deviceKeepAlive([device retain]); https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:290: new content::TestBrowserThread( this needs to be indented 2 more spaces (thus the next line also needs to be indented). https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:306: [[MockICCameraFile alloc] init:@"pic1"]); this can be base::SysUTF8ToNSString(kTestFileName) https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:315: FilePath temp_file = temp_dir.path().Append("tempfile"); high level comments about what you're testing would be good
https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/56001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:197: ICCameraDevice* device = [MockICCameraDevice alloc]; On 2013/01/03 21:50:28, sail wrote: > On 2013/01/03 20:59:55, Greg Billock wrote: > > On 2012/12/26 18:52:37, sail wrote: > > > should be > > > MockICCameraDevice* device = [[[MockICCameraDevice alloc] init] > autorelease]; > > > > Making this change makes the registrations fail, presumably because of the > > autorelease? > > I did a quick audit of the code and couldn't find anyplace that would cause this > to crash. > > There was a small error in -[ImageCaptureDeviceManagerImpl > deviceBrowser:didRemoveDevice:...] but that wouldn't cause a crash in this case. > > Could you apply this change and show me steps to reproduce the crash? I can try > to figure out what's going on. > > > I thought that since the delegate takes ownership, I should just > > use alloc, and since there's no init receiver, it wasn't necessary to invoke. > > Alloc should always be followed by an init. > ICCameraDevice and ICDevice don't have a designated initializer. NSObject's > designated initializer is -init which is what you should call here. It didn't crash; it just leaves no registered devices, presumably because when the autorelease runs, it deletes itself from all containers. Added the init call. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:103: [cameras_ removeObject:device]; On 2013/01/03 21:50:28, sail wrote: > At this point device may be deleted. You can do something like this to make sure > it stays alive: > scoped_nsobject<IDDevice> deviceKeepAlive([device retain]); I just need it to get the UUIDString. I'll do that above. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:290: new content::TestBrowserThread( On 2013/01/03 21:50:28, sail wrote: > this needs to be indented 2 more spaces (thus the next line also needs to be > indented). Done. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:306: [[MockICCameraFile alloc] init:@"pic1"]); On 2013/01/03 21:50:28, sail wrote: > this can be base::SysUTF8ToNSString(kTestFileName) Done. But I think it ends up that using literals is more legible than all this fiddling with the constant. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:315: FilePath temp_file = temp_dir.path().Append("tempfile"); On 2013/01/03 21:50:28, sail wrote: > high level comments about what you're testing would be good Done.
https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.mm:103: [cameras_ removeObject:device]; On 2013/01/03 23:09:42, Greg Billock wrote: > On 2013/01/03 21:50:28, sail wrote: > > At this point device may be deleted. You can do something like this to make > sure > > it stays alive: > > scoped_nsobject<IDDevice> deviceKeepAlive([device retain]); > > I just need it to get the UUIDString. I'll do that above. Ok, looks good. https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:306: [[MockICCameraFile alloc] init:@"pic1"]); On 2013/01/03 23:09:42, Greg Billock wrote: > On 2013/01/03 21:50:28, sail wrote: > > this can be base::SysUTF8ToNSString(kTestFileName) > > Done. But I think it ends up that using literals is more legible than all this > fiddling with the constant. By using unique constants it's easier to track down what the expectations are. For example, if the code used the literal "pic1" everywhere, and you changed it in one place where else would you need to change it? This is difficult to answer in code that spread across multiple classes and functions.
Here's the patch I applied to get all the tests to pass on my machine: diff --git a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm index 5154da1..787bfb4 100644 --- a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm +++ b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm @@ -25,6 +25,11 @@ const char kTestFileContents[] = "test"; } // namespace +// Private ICCamerDevice method needed to properly initialize the object. +@interface NSObject (PrivateAPIICCamerDevice) +- (id)initWithDictionary:(id)properties; +@end + @interface MockICCameraDevice : ICCameraDevice { @private scoped_nsobject<NSMutableArray> allMediaFiles_; @@ -36,6 +41,12 @@ const char kTestFileContents[] = "test"; @implementation MockICCameraDevice +- (id)init { + if ((self = [super initWithDictionary:[NSDictionary dictionary]])) { + } + return self; +} + - (NSString*)mountPoint { return @"mountPoint"; } @@ -116,7 +127,7 @@ const char kTestFileContents[] = "test"; - (id)init:(NSString*)name { if ((self = [super init])) { - name_.reset([NSString stringWithString:name]); + name_.reset([name retain]); date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]); } return self; @@ -201,9 +212,7 @@ class ImageCaptureDeviceManagerTest : public testing::Test { MockICCameraDevice* AttachDevice( chrome::ImageCaptureDeviceManager* manager) { // Ownership will be passed to the device browser delegate. - MockICCameraDevice* device = [MockICCameraDevice alloc]; - //[device init]; <--- causes the MockICCameraDevice to throw on exit - //[device autorelease]; + MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; LOG(INFO) << "camera is " << device; id<ICDeviceBrowserDelegate> delegate = manager->device_browser(); [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; @@ -306,12 +315,8 @@ LOG(INFO) << "camera=" << camera.get(); std::string kTestFileName("pic1"); - //scoped_nsobject<MockICCameraFile> picture1( - // [[MockICCameraFile alloc] - // init:base::SysUTF8ToNSString(kTestFileName)]); <--- is the cause of the double free - scoped_nsobject<MockICCameraFile> picture1( - [[MockICCameraFile alloc] init:@"pic1"]); -LOG(INFO) << "pic1 = " << picture1.get(); + scoped_nsobject<MockICCameraFile> picture1([[MockICCameraFile alloc] + init:base::SysUTF8ToNSString(kTestFileName)]); [device addMediaFile:picture1]; [camera cameraDevice:nil didAddItem:picture1]; @@ -345,4 +350,6 @@ LOG(INFO) << "pic1 = " << picture1.get(); strlen(kTestFileContents))); EXPECT_EQ(kTestFileContents, std::string(file_contents, strlen(kTestFileContents))); + + [camera didRemoveDevice:device]; }
On 2013/01/04 01:43:02, sail wrote: > Here's the patch I applied to get all the tests to pass on my machine: > > diff --git > a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > index 5154da1..787bfb4 100644 > --- a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > +++ b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > @@ -25,6 +25,11 @@ const char kTestFileContents[] = "test"; > > } // namespace > > +// Private ICCamerDevice method needed to properly initialize the object. > +@interface NSObject (PrivateAPIICCamerDevice) > +- (id)initWithDictionary:(id)properties; > +@end > + > @interface MockICCameraDevice : ICCameraDevice { > @private > scoped_nsobject<NSMutableArray> allMediaFiles_; > @@ -36,6 +41,12 @@ const char kTestFileContents[] = "test"; > > @implementation MockICCameraDevice > > +- (id)init { > + if ((self = [super initWithDictionary:[NSDictionary dictionary]])) { > + } > + return self; > +} > + > - (NSString*)mountPoint { > return @"mountPoint"; > } > @@ -116,7 +127,7 @@ const char kTestFileContents[] = "test"; > > - (id)init:(NSString*)name { > if ((self = [super init])) { > - name_.reset([NSString stringWithString:name]); > + name_.reset([name retain]); > date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]); > } > return self; > @@ -201,9 +212,7 @@ class ImageCaptureDeviceManagerTest : public testing::Test { > MockICCameraDevice* AttachDevice( > chrome::ImageCaptureDeviceManager* manager) { > // Ownership will be passed to the device browser delegate. > - MockICCameraDevice* device = [MockICCameraDevice alloc]; > - //[device init]; <--- causes the MockICCameraDevice to throw on exit > - //[device autorelease]; > + MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; > LOG(INFO) << "camera is " << device; > id<ICDeviceBrowserDelegate> delegate = manager->device_browser(); > [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; > @@ -306,12 +315,8 @@ LOG(INFO) << "camera=" << camera.get(); > > std::string kTestFileName("pic1"); > > - //scoped_nsobject<MockICCameraFile> picture1( > - // [[MockICCameraFile alloc] > - // init:base::SysUTF8ToNSString(kTestFileName)]); <--- is the cause of > the double free > - scoped_nsobject<MockICCameraFile> picture1( > - [[MockICCameraFile alloc] init:@"pic1"]); > -LOG(INFO) << "pic1 = " << picture1.get(); > + scoped_nsobject<MockICCameraFile> picture1([[MockICCameraFile alloc] > + init:base::SysUTF8ToNSString(kTestFileName)]); > [device addMediaFile:picture1]; > [camera cameraDevice:nil didAddItem:picture1]; > > @@ -345,4 +350,6 @@ LOG(INFO) << "pic1 = " << picture1.get(); > strlen(kTestFileContents))); > EXPECT_EQ(kTestFileContents, > std::string(file_contents, strlen(kTestFileContents))); > + > + [camera didRemoveDevice:device]; > } OK, applied pretty much this and it is repaired. :-) Nico, added you for base/mac owners. Can you have a look? I think this is pretty much ready now, right?
https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71003/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:306: [[MockICCameraFile alloc] init:@"pic1"]); On 2013/01/04 00:00:36, sail wrote: > On 2013/01/03 23:09:42, Greg Billock wrote: > > On 2013/01/03 21:50:28, sail wrote: > > > this can be base::SysUTF8ToNSString(kTestFileName) > > > > Done. But I think it ends up that using literals is more legible than all this > > fiddling with the constant. > > By using unique constants it's easier to track down what the expectations are. > > For example, if the code used the literal "pic1" everywhere, and you changed it > in one place where else would you need to change it? This is difficult to answer > in code that spread across multiple classes and functions. I think this is fine the way it ended up; I just don't think it's that hard to track unique strings within a test, and having noisy string management boilerplate is worse.
Looks good, just a few nits left. https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:19: // This wrapper basically allows the owner to have a scoped_ptr rather than a This comment explaining how a C++ wrapper is not that useful. Instead could you explain what this class does. For example, if I create an instance of this class what happens? https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:130: // name_.reset([NSString stringWithString:name]); remove https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:190: std::vector<std::string> items() { return items_; } const, more below https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:216: MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; autorelease (sorry this was missing from my patch) or even better: scoped_nsobject<MockICCameraDevice> device([[MockICCameraDevice alloc] init]); ... return device.autorelease();
https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:19: // This wrapper basically allows the owner to have a scoped_ptr rather than a Yeah, this was bad. Fixed up. On 2013/01/04 18:58:56, sail wrote: > This comment explaining how a C++ wrapper is not that useful. Instead could you > explain what this class does. For example, if I create an instance of this class > what happens? https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:130: // name_.reset([NSString stringWithString:name]); On 2013/01/04 18:58:56, sail wrote: > remove Done. https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:190: std::vector<std::string> items() { return items_; } On 2013/01/04 18:58:56, sail wrote: > const, more below Done. https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:216: MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; Looks good. Done. But autorelease() causes a crash; used release() instead, which may have been what you meant. On 2013/01/04 18:58:56, sail wrote: > autorelease (sorry this was missing from my patch) > > or even better: > scoped_nsobject<MockICCameraDevice> device([[MockICCameraDevice alloc] init]); > ... > return device.autorelease();
https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:216: MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; On 2013/01/04 21:05:50, Greg Billock wrote: > Looks good. Done. But autorelease() causes a crash; used release() instead, > which may have been what you meant. > > On 2013/01/04 18:58:56, sail wrote: > > autorelease (sorry this was missing from my patch) > > > > or even better: > > scoped_nsobject<MockICCameraDevice> device([[MockICCameraDevice alloc] init]); > > ... > > return device.autorelease(); > I applied the following patch on my machine and I don't see a crash: diff --git a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm index 8e11f4d..397afbd 100644 --- a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm +++ b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm @@ -213,10 +213,10 @@ class ImageCaptureDeviceManagerTest : public testing::Test { chrome::ImageCaptureDeviceManager* manager) { // Ownership will be passed to the device browser delegate. scoped_nsobject<MockICCameraDevice> device( - [[[MockICCameraDevice alloc] init] autorelease]); + [[MockICCameraDevice alloc] init]); id<ICDeviceBrowserDelegate> delegate = manager->device_browser(); [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; - return device.release(); + return device.autorelease(); } void DetachDevice(chrome::ImageCaptureDeviceManager* manager, https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:19: // Upon creation, begins monitoring the ImageCapture API for any attached begins monitoring for any attached devices using the ImageCapture API https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:21: // USB cards) using the SystemMonitor, and makes them available using no comma after SystemMonitor ?
https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/71004/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:216: MockICCameraDevice* device = [[MockICCameraDevice alloc] init]; Oh; I'd forgotten to take out my autorelease there. I assume scoped_nsobject is doing the refcount? Every time I feel like I've figured this out, it turns out I was wrong. I thought when I read scoped_nsobject, it specifically said it does *not* inc the refcount. On 2013/01/04 21:21:43, sail wrote: > On 2013/01/04 21:05:50, Greg Billock wrote: > > Looks good. Done. But autorelease() causes a crash; used release() instead, > > which may have been what you meant. > > > > On 2013/01/04 18:58:56, sail wrote: > > > autorelease (sorry this was missing from my patch) > > > > > > or even better: > > > scoped_nsobject<MockICCameraDevice> device([[MockICCameraDevice alloc] > init]); > > > ... > > > return device.autorelease(); > > > > I applied the following patch on my machine and I don't see a crash: > diff --git > a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > index 8e11f4d..397afbd 100644 > --- a/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > +++ b/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm > @@ -213,10 +213,10 @@ class ImageCaptureDeviceManagerTest : public testing::Test > { > chrome::ImageCaptureDeviceManager* manager) { > // Ownership will be passed to the device browser delegate. > scoped_nsobject<MockICCameraDevice> device( > - [[[MockICCameraDevice alloc] init] autorelease]); > + [[MockICCameraDevice alloc] init]); > id<ICDeviceBrowserDelegate> delegate = manager->device_browser(); > [delegate deviceBrowser:nil didAddDevice:device moreComing:NO]; > - return device.release(); > + return device.autorelease(); > } > > void DetachDevice(chrome::ImageCaptureDeviceManager* manager, https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... File chrome/browser/system_monitor/image_capture_device_manager.h (right): https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:19: // Upon creation, begins monitoring the ImageCapture API for any attached On 2013/01/04 21:21:43, sail wrote: > begins monitoring for any attached devices using the ImageCapture API Done. https://codereview.chromium.org/11442057/diff/83001/chrome/browser/system_mon... chrome/browser/system_monitor/image_capture_device_manager.h:21: // USB cards) using the SystemMonitor, and makes them available using sure On 2013/01/04 21:21:43, sail wrote: > no comma after SystemMonitor ?
LGTM! Looks really good
+mark for base/
On 2013/01/05 01:11:22, Lei Zhang wrote: > +mark for base/ Nico and/or Mark, can you have a look? I'd like to get this into the submit queue.
base/mac lgtm. Sorry for the delay.
chrome bits aside from image_capture_device.* lgtm.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/86001
Message was sent while issue was closed.
Change committed as 175471
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/83004
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/85008
Step "update" is always a major failure. Look at the try server FAQ for more details.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/113001
Retried try job too often on mac_rel for step(s) unit_tests
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/114015
Message was sent while issue was closed.
Change committed as 175938
https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_br... File chrome/browser/chrome_browser_main_mac.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_br... chrome/browser/chrome_browser_main_mac.mm:287: image_capture_device_manager_.reset(new chrome::ImageCaptureDeviceManager); I think this should only be created for 10.7 and higher https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... chrome/browser/system_monitor/image_capture_device.mm:160: if (listener_ && !base::mac::IsOSLionOrLater()) the 10.6 specific code should be removed https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:33: - (CGFloat)backingScaleFactor; don't need this and the one below
10.6 is still showing ~30% in some surveys (NetMarketShare). Do you think it's not worth the effort? Or just disable until we can figure out what the ImageCapture library is doing on it? On Thu, Jan 10, 2013 at 10:34 AM, <sail@chromium.org> wrote: > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/chrome_browser_**main_mac.mm<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_browser_main_mac.mm> > File chrome/browser/chrome_browser_**main_mac.mm<http://chrome_browser_main_mac.mm>(right): > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/chrome_browser_**main_mac.mm#newcode287<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_browser_main_mac.mm#newcode287> > chrome/browser/chrome_browser_**main_mac.mm:287<http://chrome_browser_main_mac.mm:287> > : > image_capture_device_manager_.**reset(new > chrome::**ImageCaptureDeviceManager); > I think this should only be created for 10.7 and higher > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/system_monitor/**image_capture_device.mm<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_monitor/image_capture_device.mm> > File chrome/browser/system_monitor/**image_capture_device.mm<http://image_capture_device.mm>(right): > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/system_monitor/**image_capture_device.mm#**newcode160<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_monitor/image_capture_device.mm#newcode160> > chrome/browser/system_monitor/**image_capture_device.mm:160<http://image_capture_device.mm:160>: > if (listener_ > && !base::mac::IsOSLionOrLater()) > the 10.6 specific code should be removed > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm> > File > chrome/browser/system_monitor/**image_capture_device_manager_**unittest.mm<http://image_capture_device_manager_unittest.mm> > (right): > > https://codereview.chromium.**org/11442057/diff/120007/** > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm#newcode33<https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_monitor/image_capture_device_manager_unittest.mm#newcode33> > chrome/browser/system_monitor/**image_capture_device_manager_** > unittest.mm:33 <http://image_capture_device_manager_unittest.mm:33>: > - (CGFloat)backingScaleFactor; > don't need this and the one below > > https://codereview.chromium.**org/11442057/<https://codereview.chromium.org/1... >
On 2013/01/10 19:24:10, Greg Billock wrote: > 10.6 is still showing ~30% in some surveys (NetMarketShare). Do you think > it's not worth the effort? Or just disable until we can figure out what the > ImageCapture library is doing on it? I doubt it's worth the effort. Specially considering that most devs don't have access to a 10.6 machine.
OK, took out the 10.6 support. We can assess that later. I think I've gotten the right 10.6 build/try support now. Sigh. https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_br... File chrome/browser/chrome_browser_main_mac.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/chrome_br... chrome/browser/chrome_browser_main_mac.mm:287: image_capture_device_manager_.reset(new chrome::ImageCaptureDeviceManager); On 2013/01/10 18:34:31, sail wrote: > I think this should only be created for 10.7 and higher Done. https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... File chrome/browser/system_monitor/image_capture_device.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... chrome/browser/system_monitor/image_capture_device.mm:160: if (listener_ && !base::mac::IsOSLionOrLater()) Sounds good. Just removing it for 10.6. On 2013/01/10 18:34:31, sail wrote: > the 10.6 specific code should be removed https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://codereview.chromium.org/11442057/diff/120007/chrome/browser/system_mo... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:33: - (CGFloat)backingScaleFactor; Oops! Removed. On 2013/01/10 18:34:31, sail wrote: > don't need this and the one below
new changes LGTM!
On 2013/01/10 21:47:14, sail wrote: > new changes LGTM! ok, here we go, CQ roulette. :-)
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/123002
Message was sent while issue was closed.
Change committed as 176243
Message was sent while issue was closed.
https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:21: #if !defined(MAC_OS_X_VERSION_10_6) || \ I think this should be 10_7 https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:24: @interface ICCameraDeviceDelegate (SnowLeopardAPI) I think this should be @interface NSObject (ICCameraDeviceDownloadDelegateLionAPI)
Message was sent while issue was closed.
https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:21: #if !defined(MAC_OS_X_VERSION_10_6) || \ On 2013/01/11 03:38:15, sail wrote: > I think this should be 10_7 Looking at the deprecation page, I think this is right. It doesn't have a version marker, it's "when ppc wasn't a target" but that was 10.6, and the page is "APIChangesLion" or some synonym. That's why I changed it.
Message was sent while issue was closed.
https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:24: @interface ICCameraDeviceDelegate (SnowLeopardAPI) On 2013/01/11 03:38:15, sail wrote: > I think this should be @interface NSObject > (ICCameraDeviceDownloadDelegateLionAPI) Done. I thought I understood this from looking at the example, but I guess not. :-/ Does it look right now?
Message was sent while issue was closed.
https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... File chrome/browser/system_monitor/image_capture_device_manager_unittest.mm (right): https://chromiumcodereview.appspot.com/11442057/diff/123002/chrome/browser/sy... chrome/browser/system_monitor/image_capture_device_manager_unittest.mm:21: #if !defined(MAC_OS_X_VERSION_10_6) || \ Oh, drat. I see. I changed the wrong one. Grr. Fixing. On 2013/01/11 16:17:21, Greg Billock wrote: > On 2013/01/11 03:38:15, sail wrote: > > I think this should be 10_7 > > Looking at the deprecation page, I think this is right. It doesn't have a > version marker, it's "when ppc wasn't a target" but that was 10.6, and the page > is "APIChangesLion" or some synonym. That's why I changed it.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/127004
Message was sent while issue was closed.
Change committed as 176529
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/gbillock@chromium.org/11442057/153001
Message was sent while issue was closed.
Change committed as 176797 |