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

Issue 368613002: DeviceMonitorMac: move CrAVFoundationDeviceObserver and most of SuspendObserverDelegate to UI Thread (Closed)

Created:
6 years, 5 months ago by mcasas
Modified:
6 years, 5 months ago
CC:
chromium-reviews, darin-cc_chromium.org, jam
Project:
chromium
Visibility:
Public.

Description

DeviceMonitorMac: move CrAVFoundationDeviceObserver and most of SuspendObserverDelegate to UI Thread (tl; dr : Move all operations to UI thread except device enumerations.) CrAVFoundationObserver was located in Device Thread based on the assumption that OS KVO callbacks would come on that thread too, but instead they come from UI thread. -observeValueForKeyPath:... is then called in UI thread, and since the rest of the actions of the class are small, this CL moves the whole class to UI thread. Its overlord SuspendObserverDelegate (best not use acronyms for its name :) ), however, lives a mixed life in UI and Device threads. The model is simplified by making it work always in UI thread _except_ for device enumerations (done via [AVCaptureDeviceglue devices]). AVFoundationMonitorImpl will destroy SuspendObserverDelegate in UI thread and that in turn destroys CrAVFoundationObserver in that very thread, thus cleaning up the multi threading and hopefully addressing the bug reports of a small but consistent crash rate (~2 crashes every four canaries or so). UI Thread checks are added everywhere. The code around CrAVFoundationDeviceObserver::dealloc and -stopObserving is refactored in order to avoid a redundant search-for-device in |monitoredDevices_|. BUG=366087 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=282723

Patch Set 1 : #

Total comments: 6

Patch Set 2 : Suspended/Resumed Event posts the notification to Device Thread. #

Total comments: 10

Patch Set 3 : tommi@s comments #

Total comments: 6

Patch Set 4 : tommi@s 2nd round of comments #

Total comments: 15

Patch Set 5 : rsesek@ comments, adding reference counting to |device| manipulation, simplified use of Device Thre… #

Total comments: 20

Patch Set 6 : rsesek@ and tommi@ comments #

Total comments: 8

Patch Set 7 : Comments and using scoped_nsobject<> for auto releasing |devices| #

Total comments: 4

Patch Set 8 : jochen@ comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+135 lines, -74 lines) Patch
M content/browser/device_monitor_mac.mm View 1 2 3 4 5 6 7 7 chunks +135 lines, -74 lines 0 comments Download

Messages

Total messages: 30 (0 generated)
mcasas
rsesek@, tommi@ PTAL.
6 years, 5 months ago (2014-07-02 07:17:11 UTC) #1
tommi (sloooow) - chröme
I'm holding off with the review as per our offline discussion - rsesek, you might ...
6 years, 5 months ago (2014-07-02 10:56:12 UTC) #2
mcasas
Should be cleaned up now, and beefed up the explanation. PTAL.
6 years, 5 months ago (2014-07-02 14:30:48 UTC) #3
Robert Sesek
I'm finding it really hard to follow the threading logic of this file—it really seems ...
6 years, 5 months ago (2014-07-02 19:44:46 UTC) #4
tommi (sloooow) - chröme
Yes same situation here. Miguel went over this together yesterday and there are quite a ...
6 years, 5 months ago (2014-07-03 10:17:00 UTC) #5
mcasas
Correct understanding, everything on UI thread except operations involving device enumerations, namely SuspendObserverDelegate::StartObserver() and SuspendObserverDelegate::OnDeviceChanged(). ...
6 years, 5 months ago (2014-07-03 11:15:10 UTC) #6
mcasas
Added posting suspended/resume events to Device Thread, apologies for forgetting it before -- lucky the ...
6 years, 5 months ago (2014-07-03 12:03:26 UTC) #7
tommi (sloooow) - chröme
https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm#newcode224 content/browser/device_monitor_mac.mm:224: scoped_refptr<SuspendObserverDelegate> receiver_; instead of holding on to the loop ...
6 years, 5 months ago (2014-07-03 13:30:17 UTC) #8
mcasas
tommi@ PTAL. https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm#newcode224 content/browser/device_monitor_mac.mm:224: scoped_refptr<SuspendObserverDelegate> receiver_; On 2014/07/03 13:30:17, tommi wrote: ...
6 years, 5 months ago (2014-07-04 14:08:58 UTC) #9
tommi (sloooow) - chröme
https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/160001/content/browser/device_monitor_mac.mm#newcode277 content/browser/device_monitor_mac.mm:277: base::BindBlock(^{ [suspend_observer_ startObserving:device]; })); On 2014/07/04 14:08:58, mcasas wrote: ...
6 years, 5 months ago (2014-07-07 07:41:07 UTC) #10
Robert Sesek
Thanks for the explanation. That plus fresh eyes makes this more clear. I'm definitely in ...
6 years, 5 months ago (2014-07-07 22:47:50 UTC) #11
mcasas
PTAL. Updated description, bottom line: All operations in UI thread except the device enumerations, thanks ...
6 years, 5 months ago (2014-07-08 15:11:46 UTC) #12
Robert Sesek
https://codereview.chromium.org/368613002/diff/200001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/200001/content/browser/device_monitor_mac.mm#newcode481 content/browser/device_monitor_mac.mm:481: onDeviceChangedCallback_.Run(); On 2014/07/08 15:11:46, mcasas wrote: > On 2014/07/07 ...
6 years, 5 months ago (2014-07-08 17:05:40 UTC) #13
tommi (sloooow) - chröme
we're getting there :) https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm#newcode262 content/browser/device_monitor_mac.mm:262: void DoStartObserver(NSArray* devices); On 2014/07/08 ...
6 years, 5 months ago (2014-07-08 17:23:42 UTC) #14
Robert Sesek
https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm#newcode262 content/browser/device_monitor_mac.mm:262: void DoStartObserver(NSArray* devices); On 2014/07/08 17:23:42, tommi wrote: > ...
6 years, 5 months ago (2014-07-08 17:25:25 UTC) #15
tommi (sloooow) - chröme
https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm#newcode262 content/browser/device_monitor_mac.mm:262: void DoStartObserver(NSArray* devices); On 2014/07/08 17:25:25, rsesek wrote: > ...
6 years, 5 months ago (2014-07-08 17:29:29 UTC) #16
mcasas
PTAL. I'd like to point out that CrAVFoundationDeviceObserver -startObserver: has scoped_nsobject<bla> as parameter. I'm not ...
6 years, 5 months ago (2014-07-09 08:27:34 UTC) #17
tommi (sloooow) - chröme
https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/300001/content/browser/device_monitor_mac.mm#newcode262 content/browser/device_monitor_mac.mm:262: void DoStartObserver(NSArray* devices); On 2014/07/09 08:27:33, mcasas wrote: > ...
6 years, 5 months ago (2014-07-09 09:19:40 UTC) #18
mcasas
tommi@ PTAL. https://codereview.chromium.org/368613002/diff/320001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/320001/content/browser/device_monitor_mac.mm#newcode270 content/browser/device_monitor_mac.mm:270: void DoOnDeviceChanged(NSArray* devices); On 2014/07/09 09:19:39, tommi ...
6 years, 5 months ago (2014-07-09 09:56:45 UTC) #19
tommi (sloooow) - chröme
lgtm
6 years, 5 months ago (2014-07-09 10:06:18 UTC) #20
mcasas
sky@ RS please. (Usually I send Mac code to avi@ but he seems to be ...
6 years, 5 months ago (2014-07-10 13:53:31 UTC) #21
sky
I'm not a good reviewer for this code. Is there another owner you can fine?
6 years, 5 months ago (2014-07-10 16:34:05 UTC) #22
mcasas
piman@ RS please.
6 years, 5 months ago (2014-07-10 16:47:16 UTC) #23
jochen (gone - plz use gerrit)
https://codereview.chromium.org/368613002/diff/380001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm (right): https://codereview.chromium.org/368613002/diff/380001/content/browser/device_monitor_mac.mm#newcode17 content/browser/device_monitor_mac.mm:17: #include "media/base/bind_to_current_loop.h" should not be needed? https://codereview.chromium.org/368613002/diff/380001/content/browser/device_monitor_mac.mm#newcode20 content/browser/device_monitor_mac.mm:20: using ...
6 years, 5 months ago (2014-07-11 12:55:22 UTC) #24
mcasas
jochen@: Thanks, passing on to avi@ now. avi@ OWNERS RS / PTAL. https://codereview.chromium.org/368613002/diff/380001/content/browser/device_monitor_mac.mm File content/browser/device_monitor_mac.mm ...
6 years, 5 months ago (2014-07-11 13:11:28 UTC) #25
piman
lgtm
6 years, 5 months ago (2014-07-11 20:20:09 UTC) #26
mcasas
The CQ bit was checked by mcasas@chromium.org
6 years, 5 months ago (2014-07-11 20:21:01 UTC) #27
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mcasas@chromium.org/368613002/400001
6 years, 5 months ago (2014-07-11 20:23:13 UTC) #28
commit-bot: I haz the power
Change committed as 282723
6 years, 5 months ago (2014-07-11 22:56:47 UTC) #29
Robert Sesek
6 years, 5 months ago (2014-07-14 19:40:15 UTC) #30
Message was sent while issue was closed.
LGTM

Powered by Google App Engine
This is Rietveld 408576698