|
|
Created:
5 years, 1 month ago by Sam McNally Modified:
4 years, 10 months ago Reviewers:
Ken Rockot(use gerrit already), jam, danakj, yzshen1, Michael van Ouwerkerk, blundell, Anand Mistry (off Chromium) CC:
Aaron Boodman, abarth-chromium, ben+mojo_chromium.org, chrome-apps-syd-reviews_chromium.org, chromium-reviews, creis+watch_chromium.org, danakj, darin (slow to review), darin-cc_chromium.org, devtools-reviews_chromium.org, mlamouri+watch-geolocation_chromium.org, nasko+codewatch_chromium.org, pfeldman, qsr+mojo_chromium.org, viettrungluu+watch_chromium.org, yzshen+watch_chromium.org Base URL:
https://chromium.googlesource.com/chromium/src.git@master Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionAdd mojo::StrongBindingSet and use it in GeolocationServiceContext.
Currently, mojo service context classes each manage their service
lifetimes. This causes duplicated code for tying service lifetime to
the corresponding mojo connection. This change adds
mojo::StrongBindingSet to abstract away those details.
This also changes GeolocationServiceContext into a WebContentsUserData
so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate.
BUG=556749
Patch Set 1 #
Total comments: 24
Patch Set 2 : #Patch Set 3 : #
Total comments: 12
Patch Set 4 : #
Total comments: 8
Patch Set 5 : #
Total comments: 7
Patch Set 6 : rebase #Patch Set 7 : #
Total comments: 5
Patch Set 8 : rebase #Patch Set 9 : #Patch Set 10 : #Dependent Patchsets: Messages
Total messages: 57 (16 generated)
sammc@chromium.org changed reviewers: + amistry@chromium.org, rockot@chromium.org
https://codereview.chromium.org/1411063007/diff/1/content/browser/android/con... File content/browser/android/content_view_core_impl.cc (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/android/con... content/browser/android/content_view_core_impl.cc:371: auto geolocation_service_context = Why the difference? https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_context.cc (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_context.cc:67: service->OnOverrideSet(); Why have you moved the position override into this class? The friending as a result looks nasty. https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_context.h (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_context.h:29: // |update_callback| will be called when services send update comment https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_impl.h (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_impl.h:20: // |context| must outlive this object. |update_callback| will be called when update comment https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_impl.h:35: // responsibility to ensure |position| remains valid until either |position|? https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:16: // A set of mojo services where each service's lifetime is bound to its message This could really do with a longer comment. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:31: Impl* AddService(InterfaceRequest<Interface> request, Args&&... args) { This doesn't just add a service. Maybe rename to CreateService to better reflect what this actually does. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:39: void EraseService(Impl* impl) { Maybe RemoveService, or DestroyService if you rename AddService above. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:41: DCHECK_EQ(1u, num_erased); IWYU. #include "base/logging.h" https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:44: void EraseAllServices() { holders_.clear(); } Maybe clear() instead? It fits the stl-like pattern you have below for iterators. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:59: error_handler_.Run(impl); Hmmm. At this point, |impl| has been deleted. I can see how people are likely to mis-use this API, assuming that |impl| is still valid. Maybe run the callback before deleting |impl|. That, or re-consider this entirely. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:71: using ErrorHandler = base::Callback<void(Holder*)>; Unused?
Patchset #3 (id:40001) has been deleted
https://codereview.chromium.org/1411063007/diff/1/content/browser/android/con... File content/browser/android/content_view_core_impl.cc (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/android/con... content/browser/android/content_view_core_impl.cc:371: auto geolocation_service_context = On 2015/11/10 04:53:39, Anand Mistry wrote: > Why the difference? Pausing should create the context so that if the first service is created after pausing, it starts off paused. Resuming changes back to the default state so having no context is equivalent. https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_context.cc (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_context.cc:67: service->OnOverrideSet(); On 2015/11/10 04:53:39, Anand Mistry wrote: > Why have you moved the position override into this class? The friending as a > result looks nasty. Each GeolocationServiceImpl doesn't really need its own copy of the override and it already has a pointer to the context. Added an getter for the override. https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_context.h (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_context.h:29: // |update_callback| will be called when services send On 2015/11/10 04:53:39, Anand Mistry wrote: > update comment Done. https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... File content/browser/geolocation/geolocation_service_impl.h (right): https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_impl.h:20: // |context| must outlive this object. |update_callback| will be called when On 2015/11/10 04:53:39, Anand Mistry wrote: > update comment Done. https://codereview.chromium.org/1411063007/diff/1/content/browser/geolocation... content/browser/geolocation/geolocation_service_impl.h:35: // responsibility to ensure |position| remains valid until either On 2015/11/10 04:53:39, Anand Mistry wrote: > |position|? Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:16: // A set of mojo services where each service's lifetime is bound to its message On 2015/11/10 04:53:39, Anand Mistry wrote: > This could really do with a longer comment. Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:31: Impl* AddService(InterfaceRequest<Interface> request, Args&&... args) { On 2015/11/10 04:53:39, Anand Mistry wrote: > This doesn't just add a service. Maybe rename to CreateService to better reflect > what this actually does. Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:39: void EraseService(Impl* impl) { On 2015/11/10 04:53:39, Anand Mistry wrote: > Maybe RemoveService, or DestroyService if you rename AddService above. Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:41: DCHECK_EQ(1u, num_erased); On 2015/11/10 04:53:39, Anand Mistry wrote: > IWYU. > #include "base/logging.h" Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:44: void EraseAllServices() { holders_.clear(); } On 2015/11/10 04:53:39, Anand Mistry wrote: > Maybe clear() instead? It fits the stl-like pattern you have below for > iterators. Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:59: error_handler_.Run(impl); On 2015/11/10 04:53:39, Anand Mistry wrote: > Hmmm. At this point, |impl| has been deleted. I can see how people are likely to > mis-use this API, assuming that |impl| is still valid. Maybe run the callback > before deleting |impl|. That, or re-consider this entirely. Done. https://codereview.chromium.org/1411063007/diff/1/mojo/common/service_set.h#n... mojo/common/service_set.h:71: using ErrorHandler = base::Callback<void(Holder*)>; On 2015/11/10 04:53:39, Anand Mistry wrote: > Unused? Done.
mvanouwerkerk@chromium.org changed reviewers: + mvanouwerkerk@chromium.org
Thanks Sam. For future patches, please break out changes to Mojo from things like turning the context into a WebContentsUserData. https://codereview.chromium.org/1411063007/diff/60001/content/browser/android... File content/browser/android/content_view_core_impl.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/android... content/browser/android/content_view_core_impl.cc:371: auto geolocation_service_context = nit: knowing it's a raw pointer right here would be easier to read without auto. https://codereview.chromium.org/1411063007/diff/60001/content/browser/devtool... File content/browser/devtools/protocol/emulation_handler.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/devtool... content/browser/devtools/protocol/emulation_handler.cc:104: return Response::OK(); Should this return OK if !geolocation_context ? https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_context.h (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_context.h:22: explicit GeolocationServiceContext(WebContents* web_contents); The constructor and destructor should be private now. https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_impl.cc (left): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_impl.cc:77: // Make sure to respond to any pending callback even without a valid position. Why is this no longer needed? https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_impl.h (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_impl.h:8: #include "content/public/common/geoposition.h" nit: this can be forward declared. It is also included in the cc file. https://codereview.chromium.org/1411063007/diff/60001/content/browser/web_con... File content/browser/web_contents/web_contents_impl.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/web_con... content/browser/web_contents/web_contents_impl.cc:44: #include "content/browser/geolocation/geolocation_service_context.h" nit: unused, delete
LGTM with a few minor nits. https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... File content/browser/frame_host/render_frame_host_impl.cc (right): https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... content/browser/frame_host/render_frame_host_impl.cc:59: #include "content/public/browser/permission_manager.h" Could you delete this? https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... content/browser/frame_host/render_frame_host_impl.cc:60: #include "content/public/browser/permission_type.h" ... and this? https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set... mojo/common/service_set.h:8: #include <map> nit: blank line after stl includes https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set... mojo/common/service_set.h:46: new Holder(this, request.Pass(), std::forward<Args>(args)...)); #include <utility> for std::forward
https://codereview.chromium.org/1411063007/diff/60001/content/browser/android... File content/browser/android/content_view_core_impl.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/android... content/browser/android/content_view_core_impl.cc:371: auto geolocation_service_context = On 2015/11/11 11:20:55, Michael van Ouwerkerk wrote: > nit: knowing it's a raw pointer right here would be easier to read without auto. Done. https://codereview.chromium.org/1411063007/diff/60001/content/browser/devtool... File content/browser/devtools/protocol/emulation_handler.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/devtool... content/browser/devtools/protocol/emulation_handler.cc:104: return Response::OK(); On 2015/11/11 11:20:56, Michael van Ouwerkerk wrote: > Should this return OK if !geolocation_context ? Yes. If an EmulationHandler tries to clear the override without either there being a service created or an override set, then this should be a no-op, so OK is correct. https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_context.h (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_context.h:22: explicit GeolocationServiceContext(WebContents* web_contents); On 2015/11/11 11:20:56, Michael van Ouwerkerk wrote: > The constructor and destructor should be private now. Done. https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_impl.cc (left): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_impl.cc:77: // Make sure to respond to any pending callback even without a valid position. On 2015/11/11 11:20:56, Michael van Ouwerkerk wrote: > Why is this no longer needed? There are two reasons this might be needed: (1) The callback to a mojo call must be called, as long as the mojo connection is still up. (2) To provide a final result to unblock the client. (1) is fine because the binding is always deleted before this, so the connection is always closed. (2) is not really relevant because if this is being deleted, either the client has disconnected, or we're disconnecting from the client because the WebContents is being deleted or the client misbehaved. https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... File content/browser/geolocation/geolocation_service_impl.h (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/geoloca... content/browser/geolocation/geolocation_service_impl.h:8: #include "content/public/common/geoposition.h" On 2015/11/11 11:20:56, Michael van Ouwerkerk wrote: > nit: this can be forward declared. It is also included in the cc file. Done. https://codereview.chromium.org/1411063007/diff/60001/content/browser/web_con... File content/browser/web_contents/web_contents_impl.cc (right): https://codereview.chromium.org/1411063007/diff/60001/content/browser/web_con... content/browser/web_contents/web_contents_impl.cc:44: #include "content/browser/geolocation/geolocation_service_context.h" On 2015/11/11 11:20:56, Michael van Ouwerkerk wrote: > nit: unused, delete Done. https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... File content/browser/frame_host/render_frame_host_impl.cc (right): https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... content/browser/frame_host/render_frame_host_impl.cc:59: #include "content/public/browser/permission_manager.h" On 2015/11/12 07:11:32, Anand Mistry wrote: > Could you delete this? Done. https://codereview.chromium.org/1411063007/diff/70001/content/browser/frame_h... content/browser/frame_host/render_frame_host_impl.cc:60: #include "content/public/browser/permission_type.h" On 2015/11/12 07:11:32, Anand Mistry wrote: > ... and this? Done. https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set... mojo/common/service_set.h:8: #include <map> On 2015/11/12 07:11:32, Anand Mistry wrote: > nit: blank line after stl includes Done. https://codereview.chromium.org/1411063007/diff/70001/mojo/common/service_set... mojo/common/service_set.h:46: new Holder(this, request.Pass(), std::forward<Args>(args)...)); On 2015/11/12 07:11:32, Anand Mistry wrote: > #include <utility> > for std::forward Done.
lgtm
geolocation lgtm - thanks Sam!
Hey, I looked at your use of std::forwarding and it looks right. Thanks for the example. I had a couple suggestions when I read the class: https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:46: Impl* CreateService(InterfaceRequest<Interface> request, Args&&... args) { Consider putting Emplace in the name so people reading it see the pattern more easily, and calling it know they are passing constructor arguments? https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:59: void clear() { holders_.clear(); } These aren't member var accessors, they should be named LikeSo. I'd expect a comment explaining why they are not if you have some very strong reason to violate the style guide here. https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:67: using Container = std::map<Impl*, scoped_ptr<Holder>>; Consider not using a typedef that is only referred to once.
Description was changed from ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. ========== to ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. ==========
Patchset #7 (id:130001) has been deleted
sammc@chromium.org changed reviewers: + jam@chromium.org
+jam for content/ outside content/browser/geolocation and mojo/ https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:46: Impl* CreateService(InterfaceRequest<Interface> request, Args&&... args) { On 2015/11/17 21:42:17, danakj (behind on reviews) wrote: > Consider putting Emplace in the name so people reading it see the pattern more > easily, and calling it know they are passing constructor arguments? Done. https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:59: void clear() { holders_.clear(); } On 2015/11/17 21:42:17, danakj (behind on reviews) wrote: > These aren't member var accessors, they should be named LikeSo. I'd expect a > comment explaining why they are not if you have some very strong reason to > violate the style guide here. empty() and size() are both cheap; begin() and end() are required for range-based for loops and are pretty cheap. Changed clear() to Clear(). https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:67: using Container = std::map<Impl*, scoped_ptr<Holder>>; On 2015/11/17 21:42:17, danakj (behind on reviews) wrote: > Consider not using a typedef that is only referred to once. It's also used by ServiceSet::Iterator.
danakj@chromium.org changed reviewers: + danakj@chromium.org
https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/90001/mojo/common/service_set... mojo/common/service_set.h:59: void clear() { holders_.clear(); } On 2015/11/18 03:17:18, Sam McNally wrote: > On 2015/11/17 21:42:17, danakj (behind on reviews) wrote: > > These aren't member var accessors, they should be named LikeSo. I'd expect a > > comment explaining why they are not if you have some very strong reason to > > violate the style guide here. > > empty() and size() are both cheap; begin() and end() are required for > range-based for loops and are pretty cheap. Changed clear() to Clear(). Oh, I re-read the style guide, as I've been reading the outdated one for some time. I see it's been updated to say you can write "cheap" functions this way. It used to be explicitly for accessors. Cool.
https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... mojo/common/service_set.h:46: Impl* EmplaceService(InterfaceRequest<Interface> request, Args&&... args) { I should point out that && is not allowed to be used yet in our C++11 styleguide. I'm trying to sort out what we need to allow you to write stuff like this.
jam@chromium.org changed reviewers: + yzshen@chromium.org
+yzshen I have a few questions: -why do we need to decouple GeolocationServiceContext from WebContentsImpl? -even with the description, I'm still not sure why we need this (a tracking bug with more info would have been helpful). Regarding lifetime management, my naive question is why aren't services just shutting down when their message pipe is torn down automatically through StrongBinding?
On 2015/11/19 02:45:38, jam wrote: > +yzshen > > I have a few questions: > -why do we need to decouple GeolocationServiceContext from WebContentsImpl? For consistency with services outside content plus a bit of "why does WebContentsImpl even care about geolocation?" > -even with the description, I'm still not sure why we need this (a tracking bug > with more info would have been helpful). Regarding lifetime management, my naive > question is why aren't services just shutting down when their message pipe is > torn down automatically through StrongBinding? The point of this is to try to make the render-exposed mojo services in content more consistent. All of them have a context class, often for different reasons and/or with different responsibilities, but every context class owns its services. Doing this in terms of StrongBinding and notifying the context when a service is destroyed (with a delete all on context destruction) also works, but it seemed simpler to abstract away most of service lifetime management. In the specific case of geolocation, the context is to expose a per-WebContents API to other parts of the browser (pause for android webview, position override for devtools). The general problem with relying on StrongBinding alone is browser shutdown. I experimented with converting text-to-speech to use mojo, using StrongBinding, with the service exposed using the RenderProcessHost ServiceRegistry. This was fine for most renderer processes, but if the renderer process contained a ServiceWorker, the message pipe remained open until the message loop stops, and the service has to contend with an unexpected environment: (depending on which voice was used) the TTS service wants to send an event to the extension providing the TTS implementation to stop speaking when it's destroyed, but when the message loop is stopped, the BrowserContext-keyed services have been deleted already and it hits a use-after-free.
https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... mojo/common/service_set.h:34: class ServiceSet { With a quick look, this looks similar to WeakBindingSet, except that this class also owns the impl objects. Can this be made a StrongBindingSet? Or one step further, unify {Weak|Strong}BindingSet to share implementation, using different Traits to deal with impl ownership?
To me a StrongBindingSet would be a thing that maintains multiple bindings to a single impl, and deletes that impl once the set is empty (which is an idea that's been thrown around separately). ServiceSet a set of impls which each have their own binding, so it's not really the same thing. On Thu, Nov 19, 2015 at 9:34 AM, <yzshen@chromium.org> wrote: > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > File mojo/common/service_set.h (right): > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > mojo/common/service_set.h:34: class ServiceSet { > With a quick look, this looks similar to WeakBindingSet, except that > this class also owns the impl objects. > > Can this be made a StrongBindingSet? Or one step further, unify > {Weak|Strong}BindingSet to share implementation, using different Traits > to deal with impl ownership? > > https://codereview.chromium.org/1411063007/ > -- You received this message because you are subscribed to the Google Groups "Chromium-reviews" group. To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org.
On 2015/11/19 04:53:26, Sam McNally wrote: > On 2015/11/19 02:45:38, jam wrote: > > +yzshen > > > > I have a few questions: > > -why do we need to decouple GeolocationServiceContext from WebContentsImpl? > > For consistency with services outside content plus a bit of "why does > WebContentsImpl even care about geolocation?" > > > -even with the description, I'm still not sure why we need this (a tracking > bug > > with more info would have been helpful). Regarding lifetime management, my > naive > > question is why aren't services just shutting down when their message pipe is > > torn down automatically through StrongBinding? > > The point of this is to try to make the render-exposed mojo services in content > more consistent. All of them have a context class, often for different reasons > and/or with different responsibilities, but every context class owns its > services. You're talking about the browser side context class, like Geolocation's right? This was a very old pattern in chrome, and we stopped it (although some newer features may have copied it). If we convert more code in content, I think a context class is the minority by far. > Doing this in terms of StrongBinding and notifying the context when a > service is destroyed (with a delete all on context destruction) also works, but > it seemed simpler to abstract away most of service lifetime management. Can you expand on why it's simpler to not use StrongBinding? StrongBinding should be a well understood concept for anyone using mojo. Adding another concept here with ServiceSet adds yet another thing that devs have to be familiar with. > In the > specific case of geolocation, the context is to expose a per-WebContents API to > other parts of the browser (pause for android webview, position override for > devtools). > > The general problem with relying on StrongBinding alone is browser shutdown. I > experimented with converting text-to-speech to use mojo, using StrongBinding, > with the service exposed using the RenderProcessHost ServiceRegistry. This was > fine for most renderer processes, but if the renderer process contained a > ServiceWorker, the message pipe remained open until the message loop stops, and > the service has to contend with an unexpected environment: (depending on which > voice was used) the TTS service wants to send an event to the extension > providing the TTS implementation to stop speaking when it's destroyed, but when > the message loop is stopped, the BrowserContext-keyed services have been deleted > already and it hits a use-after-free. I'm not sure I follow all the above; I'm missing some context/stacktraces. It seems that part of the above is because code is outliving the profile (i.e. BrowserContext).Why is a renderer process outliving the profile? Or is because RenderProcessHostImpl isn't outliving the profile, but by the time the strongbinding notices the connection error that is later?
On 2015/11/19 17:43:23, Ken Rockot wrote: > To me a StrongBindingSet would be a thing that maintains multiple bindings > to a single impl, and deletes that impl once the set is empty (which is an > idea that's been thrown around separately). > > ServiceSet a set of impls which each have their own binding, so it's not > really the same thing. > > On Thu, Nov 19, 2015 at 9:34 AM, <mailto:yzshen@chromium.org> wrote: > > > > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > > File mojo/common/service_set.h (right): > > > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > > mojo/common/service_set.h:34: class ServiceSet { > > With a quick look, this looks similar to WeakBindingSet, except that > > this class also owns the impl objects. > > > > Can this be made a StrongBindingSet? Or one step further, unify > > {Weak|Strong}BindingSet to share implementation, using different Traits > > to deal with impl ownership? > > > > https://codereview.chromium.org/1411063007/ > > > > -- > You received this message because you are subscribed to the Google Groups > "Chromium-reviews" group. > To unsubscribe from this group and stop receiving emails from it, send an email > to mailto:chromium-reviews+unsubscribe@chromium.org. Ah, thanks for the explanation! However, I would argue that a WeakBindingSet doesn't require all the bindings refer to the same impl object. Why do we want it differently in StrongBindingSet?
On 2015/11/19 17:43:57, jam wrote: > On 2015/11/19 04:53:26, Sam McNally wrote: > > On 2015/11/19 02:45:38, jam wrote: > > > +yzshen > > > > > > I have a few questions: > > > -why do we need to decouple GeolocationServiceContext from WebContentsImpl? > > > > For consistency with services outside content plus a bit of "why does > > WebContentsImpl even care about geolocation?" > > > > > -even with the description, I'm still not sure why we need this (a tracking > > bug > > > with more info would have been helpful). Regarding lifetime management, my > > naive > > > question is why aren't services just shutting down when their message pipe > is > > > torn down automatically through StrongBinding? > > > > The point of this is to try to make the render-exposed mojo services in > content > > more consistent. All of them have a context class, often for different reasons > > and/or with different responsibilities, but every context class owns its > > services. > > You're talking about the browser side context class, like Geolocation's right? > This was a very old pattern in chrome, and we stopped it (although some newer > features may have copied it). If we convert more code in content, I think a > context class is the minority by far. > > > Doing this in terms of StrongBinding and notifying the context when a > > service is destroyed (with a delete all on context destruction) also works, > but > > it seemed simpler to abstract away most of service lifetime management. > > Can you expand on why it's simpler to not use StrongBinding? StrongBinding > should be a well understood concept for anyone using mojo. Adding another > concept here with ServiceSet adds yet another thing that devs have to be > familiar with. +1!! > > > In the > > specific case of geolocation, the context is to expose a per-WebContents API > to > > other parts of the browser (pause for android webview, position override for > > devtools). > > > > The general problem with relying on StrongBinding alone is browser shutdown. I > > experimented with converting text-to-speech to use mojo, using StrongBinding, > > with the service exposed using the RenderProcessHost ServiceRegistry. This was > > fine for most renderer processes, but if the renderer process contained a > > ServiceWorker, the message pipe remained open until the message loop stops, > and > > the service has to contend with an unexpected environment: (depending on which > > voice was used) the TTS service wants to send an event to the extension > > providing the TTS implementation to stop speaking when it's destroyed, but > when > > the message loop is stopped, the BrowserContext-keyed services have been > deleted > > already and it hits a use-after-free. > > I'm not sure I follow all the above; I'm missing some context/stacktraces. > > It seems that part of the above is because code is outliving the profile (i.e. > BrowserContext).Why is a renderer process outliving the profile? Or is because > RenderProcessHostImpl isn't outliving the profile, but by the time the > strongbinding notices the connection error that is later?
On Thu, Nov 19, 2015 at 9:46 AM, <yzshen@chromium.org> wrote: > On 2015/11/19 17:43:23, Ken Rockot wrote: > >> To me a StrongBindingSet would be a thing that maintains multiple bindings >> to a single impl, and deletes that impl once the set is empty (which is an >> idea that's been thrown around separately). >> > > ServiceSet a set of impls which each have their own binding, so it's not >> really the same thing. >> > > On Thu, Nov 19, 2015 at 9:34 AM, <mailto:yzshen@chromium.org> wrote: >> > > > >> > >> > >> > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > >> > File mojo/common/service_set.h (right): >> > >> > >> > >> > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > >> > mojo/common/service_set.h:34: class ServiceSet { >> > With a quick look, this looks similar to WeakBindingSet, except that >> > this class also owns the impl objects. >> > >> > Can this be made a StrongBindingSet? Or one step further, unify >> > {Weak|Strong}BindingSet to share implementation, using different Traits >> > to deal with impl ownership? >> > >> > https://codereview.chromium.org/1411063007/ >> > >> > > -- >> You received this message because you are subscribed to the Google Groups >> "Chromium-reviews" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> > email > >> to mailto:chromium-reviews+unsubscribe@chromium.org. >> > > Ah, thanks for the explanation! > > However, I would argue that a WeakBindingSet doesn't require all the > bindings > refer to the same impl object. Why do we want it differently in > StrongBindingSet? > > Oh... you're right :) Not sure why I thought that was the case. > > https://codereview.chromium.org/1411063007/ > -- You received this message because you are subscribed to the Google Groups "Chromium-reviews" group. To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org.
blundell@chromium.org changed reviewers: + blundell@chromium.org
Hi Sam, Can you add BUG=556749? This CL will solve that bug (I got pointed here by Ken on https://codereview.chromium.org/1459343003/, which I'm not going to bother landing given your CL). Thanks!
Description was changed from ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. ========== to ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ==========
Description was changed from ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. ========== to ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ==========
On 2015/11/19 17:43:57, jam wrote: > On 2015/11/19 04:53:26, Sam McNally wrote: > > On 2015/11/19 02:45:38, jam wrote: > > > +yzshen > > > > > > I have a few questions: > > > -why do we need to decouple GeolocationServiceContext from WebContentsImpl? > > > > For consistency with services outside content plus a bit of "why does > > WebContentsImpl even care about geolocation?" > > > > > -even with the description, I'm still not sure why we need this (a tracking > > bug > > > with more info would have been helpful). Regarding lifetime management, my > > naive > > > question is why aren't services just shutting down when their message pipe > is > > > torn down automatically through StrongBinding? > > > > The point of this is to try to make the render-exposed mojo services in > content > > more consistent. All of them have a context class, often for different reasons > > and/or with different responsibilities, but every context class owns its > > services. > > You're talking about the browser side context class, like Geolocation's right? > This was a very old pattern in chrome, and we stopped it (although some newer > features may have copied it). If we convert more code in content, I think a > context class is the minority by far. What do you propose as the alternative to a context class if a per-WebContents/per-RenderFrame interface is required where each service instance may also require its own state? I wasn't a fan of these context classes either, but I couldn't find a way to get rid of them. Most of the mojo services in content require some of the functionality that a context allows so it seems useful to have an easy to use/copy-paste pattern to follow. Using a context + ServiceSet also provides service lifetime guarantees; StrongBinding provides edges on which to race during shutdown of all kinds. Standalone services using a StrongBinding are also useful, but they don't work well for everything and trying to force everything to follow that pattern is just going to lead to more mess. > > > Doing this in terms of StrongBinding and notifying the context when a > > service is destroyed (with a delete all on context destruction) also works, > but > > it seemed simpler to abstract away most of service lifetime management. > > Can you expand on why it's simpler to not use StrongBinding? StrongBinding > should be a well understood concept for anyone using mojo. Adding another > concept here with ServiceSet adds yet another thing that devs have to be > familiar with. It's fewer moving parts to worry about. StrongBinding + a context means the context has to track the active services and the service has the notify the context on deletion so it can clean up properly. This is just busywork for every service with a context. > > > In the > > specific case of geolocation, the context is to expose a per-WebContents API > to > > other parts of the browser (pause for android webview, position override for > > devtools). > > > > The general problem with relying on StrongBinding alone is browser shutdown. I > > experimented with converting text-to-speech to use mojo, using StrongBinding, > > with the service exposed using the RenderProcessHost ServiceRegistry. This was > > fine for most renderer processes, but if the renderer process contained a > > ServiceWorker, the message pipe remained open until the message loop stops, > and > > the service has to contend with an unexpected environment: (depending on which > > voice was used) the TTS service wants to send an event to the extension > > providing the TTS implementation to stop speaking when it's destroyed, but > when > > the message loop is stopped, the BrowserContext-keyed services have been > deleted > > already and it hits a use-after-free. > > I'm not sure I follow all the above; I'm missing some context/stacktraces. > > It seems that part of the above is because code is outliving the profile (i.e. > BrowserContext).Why is a renderer process outliving the profile? Or is because > RenderProcessHostImpl isn't outliving the profile, but by the time the > strongbinding notices the connection error that is later? I'm not sure which it was. I decided to wait and see if mojo-in-blink would make it simpler. https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... mojo/common/service_set.h:34: class ServiceSet { On 2015/11/19 17:34:24, yzshen1 wrote: > With a quick look, this looks similar to WeakBindingSet, except that this class > also owns the impl objects. > > Can this be made a StrongBindingSet? Or one step further, unify > {Weak|Strong}BindingSet to share implementation, using different Traits to deal > with impl ownership? It's similar, but I think the ownership here is different enough to not try to merge implementations, at least for now.
On 2015/11/19 02:45:38, jam wrote: > +yzshen > > I have a few questions: > -why do we need to decouple GeolocationServiceContext from WebContentsImpl? > -even with the description, I'm still not sure why we need this (a tracking bug > with more info would have been helpful). Regarding lifetime management, my naive > question is why aren't services just shutting down when their message pipe is > torn down automatically through StrongBinding? Without getting into the larger questions going back and forth here, some details on this last question: GeolocationServiceImpl does shut down when its message pipe is closed (by overriding OnConnectionError()). Irrespective of whether GeolocationServiceImpl uses a weak binding or strong binding to do that (it currently uses a weak binding because it also needs to die when the GeolocationServiceContext goes away), there's an issue with race on shutdown of a RenderFrameHostImpl: There's no ordering between the RenderFrameHostImpl instance being destroyed and the related GeolocationServiceImpl receiving the OnConnectionError() message. This race causes crashes because GeolocationServiceImpl has a reference to its associated RenderFrameHostImpl (crbug.com/556749). I had made a targeted change to fix just this crash: https://codereview.chromium.org/1459343003/, which I closed when pointed to this CL.
https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... mojo/common/service_set.h:34: class ServiceSet { On 2015/11/23 01:12:53, Sam McNally wrote: > On 2015/11/19 17:34:24, yzshen1 wrote: > > With a quick look, this looks similar to WeakBindingSet, except that this > class > > also owns the impl objects. > > > > Can this be made a StrongBindingSet? Or one step further, unify > > {Weak|Strong}BindingSet to share implementation, using different Traits to > deal > > with impl ownership? > > It's similar, but I think the ownership here is different enough to not try to > merge implementations, at least for now. What do you think about naming it StrongBindingSet and making the interface consistent with WeakBindingSet?
On 2015/11/23 01:12:53, Sam McNally wrote: > On 2015/11/19 17:43:57, jam wrote: > > On 2015/11/19 04:53:26, Sam McNally wrote: > > > On 2015/11/19 02:45:38, jam wrote: > > > > +yzshen > > > > > > > > I have a few questions: > > > > -why do we need to decouple GeolocationServiceContext from > WebContentsImpl? > > > > > > For consistency with services outside content plus a bit of "why does > > > WebContentsImpl even care about geolocation?" > > > > > > > -even with the description, I'm still not sure why we need this (a > tracking > > > bug > > > > with more info would have been helpful). Regarding lifetime management, my > > > naive > > > > question is why aren't services just shutting down when their message pipe > > is > > > > torn down automatically through StrongBinding? > > > > > > The point of this is to try to make the render-exposed mojo services in > > content > > > more consistent. All of them have a context class, often for different > reasons > > > and/or with different responsibilities, but every context class owns its > > > services. > > > > You're talking about the browser side context class, like Geolocation's right? > > This was a very old pattern in chrome, and we stopped it (although some newer > > features may have copied it). If we convert more code in content, I think a > > context class is the minority by far. > > What do you propose as the alternative to a context class if a > per-WebContents/per-RenderFrame interface is required where each service > instance may also require its own state? I wasn't a fan of these context classes > either, but I couldn't find a way to get rid of them. Most of the mojo services > in content require some of the functionality that a context allows so it seems > useful to have an easy to use/copy-paste pattern to follow. Using a context + > ServiceSet also provides service lifetime guarantees; StrongBinding provides > edges on which to race during shutdown of all kinds. > > Standalone services using a StrongBinding are also useful, but they don't work > well for everything and trying to force everything to follow that pattern is > just going to lead to more mess. I don't follow everything above. Can you schedule a vc to discuss this some more? > > > > > Doing this in terms of StrongBinding and notifying the context when a > > > service is destroyed (with a delete all on context destruction) also works, > > but > > > it seemed simpler to abstract away most of service lifetime management. > > > > Can you expand on why it's simpler to not use StrongBinding? StrongBinding > > should be a well understood concept for anyone using mojo. Adding another > > concept here with ServiceSet adds yet another thing that devs have to be > > familiar with. > > It's fewer moving parts to worry about. StrongBinding + a context means the > context has to track the active services and the service has the notify the > context on deletion so it can clean up properly. This is just busywork for every > service with a context. > > > > > In the > > > specific case of geolocation, the context is to expose a per-WebContents API > > to > > > other parts of the browser (pause for android webview, position override for > > > devtools). > > > > > > The general problem with relying on StrongBinding alone is browser shutdown. > I > > > experimented with converting text-to-speech to use mojo, using > StrongBinding, > > > with the service exposed using the RenderProcessHost ServiceRegistry. This > was > > > fine for most renderer processes, but if the renderer process contained a > > > ServiceWorker, the message pipe remained open until the message loop stops, > > and > > > the service has to contend with an unexpected environment: (depending on > which > > > voice was used) the TTS service wants to send an event to the extension > > > providing the TTS implementation to stop speaking when it's destroyed, but > > when > > > the message loop is stopped, the BrowserContext-keyed services have been > > deleted > > > already and it hits a use-after-free. > > > > I'm not sure I follow all the above; I'm missing some context/stacktraces. > > > > It seems that part of the above is because code is outliving the profile (i.e. > > BrowserContext).Why is a renderer process outliving the profile? Or is because > > RenderProcessHostImpl isn't outliving the profile, but by the time the > > strongbinding notices the connection error that is later? > > I'm not sure which it was. I decided to wait and see if mojo-in-blink would make > it simpler. > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > File mojo/common/service_set.h (right): > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > mojo/common/service_set.h:34: class ServiceSet { > On 2015/11/19 17:34:24, yzshen1 wrote: > > With a quick look, this looks similar to WeakBindingSet, except that this > class > > also owns the impl objects. > > > > Can this be made a StrongBindingSet? Or one step further, unify > > {Weak|Strong}BindingSet to share implementation, using different Traits to > deal > > with impl ownership? > > It's similar, but I think the ownership here is different enough to not try to > merge implementations, at least for now.
Patchset #9 (id:190001) has been deleted
Patchset #8 (id:170001) has been deleted
On 2015/11/24 00:14:52, jam wrote: > On 2015/11/23 01:12:53, Sam McNally wrote: > > On 2015/11/19 17:43:57, jam wrote: > > > On 2015/11/19 04:53:26, Sam McNally wrote: > > > > On 2015/11/19 02:45:38, jam wrote: > > > > > +yzshen > > > > > > > > > > I have a few questions: > > > > > -why do we need to decouple GeolocationServiceContext from > > WebContentsImpl? > > > > > > > > For consistency with services outside content plus a bit of "why does > > > > WebContentsImpl even care about geolocation?" > > > > > > > > > -even with the description, I'm still not sure why we need this (a > > tracking > > > > bug > > > > > with more info would have been helpful). Regarding lifetime management, > my > > > > naive > > > > > question is why aren't services just shutting down when their message > pipe > > > is > > > > > torn down automatically through StrongBinding? > > > > > > > > The point of this is to try to make the render-exposed mojo services in > > > content > > > > more consistent. All of them have a context class, often for different > > reasons > > > > and/or with different responsibilities, but every context class owns its > > > > services. > > > > > > You're talking about the browser side context class, like Geolocation's > right? > > > This was a very old pattern in chrome, and we stopped it (although some > newer > > > features may have copied it). If we convert more code in content, I think a > > > context class is the minority by far. > > > > What do you propose as the alternative to a context class if a > > per-WebContents/per-RenderFrame interface is required where each service > > instance may also require its own state? I wasn't a fan of these context > classes > > either, but I couldn't find a way to get rid of them. Most of the mojo > services > > in content require some of the functionality that a context allows so it seems > > useful to have an easy to use/copy-paste pattern to follow. Using a context + > > ServiceSet also provides service lifetime guarantees; StrongBinding provides > > edges on which to race during shutdown of all kinds. > > > > Standalone services using a StrongBinding are also useful, but they don't work > > well for everything and trying to force everything to follow that pattern is > > just going to lead to more mess. > > I don't follow everything above. Can you schedule a vc to discuss this some > more? > I've put together a doc on what this is trying to achieve: https://docs.google.com/a/chromium.org/document/d/1DGux2YJb1dW5HPwxsFeRGfj8_9.... I checked what was happening with TTS-using-mojo and shutdown: the RenderProcessHosts are shut down before the profile is destroyed, but the mojo::Binding isn't notified before the message loop stops. https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h File mojo/common/service_set.h (right): https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... mojo/common/service_set.h:34: class ServiceSet { On 2015/11/23 16:12:09, yzshen1 wrote: > On 2015/11/23 01:12:53, Sam McNally wrote: > > On 2015/11/19 17:34:24, yzshen1 wrote: > > > With a quick look, this looks similar to WeakBindingSet, except that this > > class > > > also owns the impl objects. > > > > > > Can this be made a StrongBindingSet? Or one step further, unify > > > {Weak|Strong}BindingSet to share implementation, using different Traits to > > deal > > > with impl ownership? > > > > It's similar, but I think the ownership here is different enough to not try to > > merge implementations, at least for now. > > What do you think about naming it StrongBindingSet and making the interface > consistent with WeakBindingSet? This class isn't publicly concerned with bindings. The public interface is a set of services whose lifetime is managed by the set.
On 2015/12/01 00:12:54, Sam McNally wrote: > On 2015/11/24 00:14:52, jam wrote: > > On 2015/11/23 01:12:53, Sam McNally wrote: > > > On 2015/11/19 17:43:57, jam wrote: > > > > On 2015/11/19 04:53:26, Sam McNally wrote: > > > > > On 2015/11/19 02:45:38, jam wrote: > > > > > > +yzshen > > > > > > > > > > > > I have a few questions: > > > > > > -why do we need to decouple GeolocationServiceContext from > > > WebContentsImpl? > > > > > > > > > > For consistency with services outside content plus a bit of "why does > > > > > WebContentsImpl even care about geolocation?" > > > > > > > > > > > -even with the description, I'm still not sure why we need this (a > > > tracking > > > > > bug > > > > > > with more info would have been helpful). Regarding lifetime > management, > > my > > > > > naive > > > > > > question is why aren't services just shutting down when their message > > pipe > > > > is > > > > > > torn down automatically through StrongBinding? > > > > > > > > > > The point of this is to try to make the render-exposed mojo services in > > > > content > > > > > more consistent. All of them have a context class, often for different > > > reasons > > > > > and/or with different responsibilities, but every context class owns its > > > > > services. > > > > > > > > You're talking about the browser side context class, like Geolocation's > > right? > > > > This was a very old pattern in chrome, and we stopped it (although some > > newer > > > > features may have copied it). If we convert more code in content, I think > a > > > > context class is the minority by far. > > > > > > What do you propose as the alternative to a context class if a > > > per-WebContents/per-RenderFrame interface is required where each service > > > instance may also require its own state? I wasn't a fan of these context > > classes > > > either, but I couldn't find a way to get rid of them. Most of the mojo > > services > > > in content require some of the functionality that a context allows so it > seems > > > useful to have an easy to use/copy-paste pattern to follow. Using a context > + > > > ServiceSet also provides service lifetime guarantees; StrongBinding provides > > > edges on which to race during shutdown of all kinds. > > > > > > Standalone services using a StrongBinding are also useful, but they don't > work > > > well for everything and trying to force everything to follow that pattern is > > > just going to lead to more mess. > > > > I don't follow everything above. Can you schedule a vc to discuss this some > > more? > > > I've put together a doc on what this is trying to achieve: > https://docs.google.com/a/chromium.org/document/d/1DGux2YJb1dW5HPwxsFeRGfj8_9.... > > I checked what was happening with TTS-using-mojo and shutdown: the > RenderProcessHosts are shut down before the profile is destroyed, but the > mojo::Binding isn't notified before the message loop stops. > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > File mojo/common/service_set.h (right): > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > mojo/common/service_set.h:34: class ServiceSet { > On 2015/11/23 16:12:09, yzshen1 wrote: > > On 2015/11/23 01:12:53, Sam McNally wrote: > > > On 2015/11/19 17:34:24, yzshen1 wrote: > > > > With a quick look, this looks similar to WeakBindingSet, except that this > > > class > > > > also owns the impl objects. > > > > > > > > Can this be made a StrongBindingSet? Or one step further, unify > > > > {Weak|Strong}BindingSet to share implementation, using different Traits to > > > deal > > > > with impl ownership? > > > > > > It's similar, but I think the ownership here is different enough to not try > to > > > merge implementations, at least for now. > > > > What do you think about naming it StrongBindingSet and making the interface > > consistent with WeakBindingSet? > > This class isn't publicly concerned with bindings. The public interface is a set > of services whose lifetime is managed by the set. I still feel that the difference is not significant enough to justify introducing a new concept in mojo/common. StrongBindingSet manages the lifetime of the impl objects, too. And the learning cost is smaller because we already have StrongBinding, WeakBinding and WeakBindingSet. It seems natural to introduce StrongBindingSet instead of ServiceSet. Besides, the name ServiceSet is a little too broad. Please let me know if I have missed or misunderstood anything.
On 2015/12/01 18:05:23, yzshen1 wrote: > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > > File mojo/common/service_set.h (right): > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > > mojo/common/service_set.h:34: class ServiceSet { > > On 2015/11/23 16:12:09, yzshen1 wrote: > > > On 2015/11/23 01:12:53, Sam McNally wrote: > > > > On 2015/11/19 17:34:24, yzshen1 wrote: > > > > > With a quick look, this looks similar to WeakBindingSet, except that > this > > > > class > > > > > also owns the impl objects. > > > > > > > > > > Can this be made a StrongBindingSet? Or one step further, unify > > > > > {Weak|Strong}BindingSet to share implementation, using different Traits > to > > > > deal > > > > > with impl ownership? > > > > > > > > It's similar, but I think the ownership here is different enough to not > try > > to > > > > merge implementations, at least for now. > > > > > > What do you think about naming it StrongBindingSet and making the interface > > > consistent with WeakBindingSet? > > > > This class isn't publicly concerned with bindings. The public interface is a > set > > of services whose lifetime is managed by the set. > > I still feel that the difference is not significant enough to justify > introducing a new concept in mojo/common. StrongBindingSet manages the lifetime > of the impl objects, too. And the learning cost is smaller because we already > have StrongBinding, WeakBinding and WeakBindingSet. It seems natural to > introduce StrongBindingSet instead of ServiceSet. Besides, the name ServiceSet > is a little too broad. > How would a StrongBindingSet providing similar functionality differ from this? The StrongBindingSet in the mojo repo lacks functionality like iteration, deletion and connection error notifications. Trying to make this look like WeakBindingSet will produce a worse interface. They have different purposes so they have different interfaces.
On 2015/12/02 05:30:46, Sam McNally wrote: > On 2015/12/01 18:05:23, yzshen1 wrote: > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > > > File mojo/common/service_set.h (right): > > > > > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > > > mojo/common/service_set.h:34: class ServiceSet { > > > On 2015/11/23 16:12:09, yzshen1 wrote: > > > > On 2015/11/23 01:12:53, Sam McNally wrote: > > > > > On 2015/11/19 17:34:24, yzshen1 wrote: > > > > > > With a quick look, this looks similar to WeakBindingSet, except that > > this > > > > > class > > > > > > also owns the impl objects. > > > > > > > > > > > > Can this be made a StrongBindingSet? Or one step further, unify > > > > > > {Weak|Strong}BindingSet to share implementation, using different > Traits > > to > > > > > deal > > > > > > with impl ownership? > > > > > > > > > > It's similar, but I think the ownership here is different enough to not > > try > > > to > > > > > merge implementations, at least for now. > > > > > > > > What do you think about naming it StrongBindingSet and making the > interface > > > > consistent with WeakBindingSet? > > > > > > This class isn't publicly concerned with bindings. The public interface is a > > set > > > of services whose lifetime is managed by the set. > > > > I still feel that the difference is not significant enough to justify > > introducing a new concept in mojo/common. StrongBindingSet manages the > lifetime > > of the impl objects, too. And the learning cost is smaller because we already > > have StrongBinding, WeakBinding and WeakBindingSet. It seems natural to > > introduce StrongBindingSet instead of ServiceSet. Besides, the name ServiceSet > > is a little too broad. > > > How would a StrongBindingSet providing similar functionality differ from this? > The StrongBindingSet in the mojo repo lacks functionality like iteration, > deletion and connection error notifications. I wasn't saying that we should copy it from the mojo repo. We certainly can have a richer interface with the functionality you proposed. > > Trying to make this look like WeakBindingSet will produce a worse interface. > They have different purposes so they have different interfaces. I think my suggestion is more about naming. The exact interface design is something we can discuss separately (and which I have less strong an opinion). The reason why I personally prefer the name StrongBindingSet is that when I looked at the code, I told myself "ah, this actually is a binding set which also owns the impl objects". Because it lives next to WeakBindingSet, I think it is nice to have consistent names. Maybe you could tell me why you think the name StrongBindingSet doesn't precisely reflect what the class does? I may have missed something.
Description was changed from ========== Add mojo::ServiceSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::ServiceSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ========== to ========== Add mojo::StrongBindingSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::StrongBindingSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ==========
Description was changed from ========== Add mojo::StrongBindingSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::StrongBindingSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ========== to ========== Add mojo::StrongBindingSet and use it in GeolocationServiceContext. Currently, mojo service context classes each manage their service lifetimes. This causes duplicated code for tying service lifetime to the corresponding mojo connection. This change adds mojo::StrongBindingSet to abstract away those details. This also changes GeolocationServiceContext into a WebContentsUserData so it can be decoupled from WebContentsImpl and RenderFrameHostDelegate. BUG=556749 ==========
On 2015/12/02 06:04:13, yzshen1 wrote: > On 2015/12/02 05:30:46, Sam McNally wrote: > > On 2015/12/01 18:05:23, yzshen1 wrote: > > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_set.h > > > > File mojo/common/service_set.h (right): > > > > > > > > > > > > > > https://codereview.chromium.org/1411063007/diff/150001/mojo/common/service_se... > > > > mojo/common/service_set.h:34: class ServiceSet { > > > > On 2015/11/23 16:12:09, yzshen1 wrote: > > > > > On 2015/11/23 01:12:53, Sam McNally wrote: > > > > > > On 2015/11/19 17:34:24, yzshen1 wrote: > > > > > > > With a quick look, this looks similar to WeakBindingSet, except that > > > this > > > > > > class > > > > > > > also owns the impl objects. > > > > > > > > > > > > > > Can this be made a StrongBindingSet? Or one step further, unify > > > > > > > {Weak|Strong}BindingSet to share implementation, using different > > Traits > > > to > > > > > > deal > > > > > > > with impl ownership? > > > > > > > > > > > > It's similar, but I think the ownership here is different enough to > not > > > try > > > > to > > > > > > merge implementations, at least for now. > > > > > > > > > > What do you think about naming it StrongBindingSet and making the > > interface > > > > > consistent with WeakBindingSet? > > > > > > > > This class isn't publicly concerned with bindings. The public interface is > a > > > set > > > > of services whose lifetime is managed by the set. > > > > > > I still feel that the difference is not significant enough to justify > > > introducing a new concept in mojo/common. StrongBindingSet manages the > > lifetime > > > of the impl objects, too. And the learning cost is smaller because we > already > > > have StrongBinding, WeakBinding and WeakBindingSet. It seems natural to > > > introduce StrongBindingSet instead of ServiceSet. Besides, the name > ServiceSet > > > is a little too broad. > > > > > How would a StrongBindingSet providing similar functionality differ from this? > > The StrongBindingSet in the mojo repo lacks functionality like iteration, > > deletion and connection error notifications. > > I wasn't saying that we should copy it from the mojo repo. > We certainly can have a richer interface with the functionality you proposed. > > > > > > Trying to make this look like WeakBindingSet will produce a worse interface. > > They have different purposes so they have different interfaces. > > I think my suggestion is more about naming. The exact interface design is > something we can discuss separately (and which I have less strong an opinion). > > The reason why I personally prefer the name StrongBindingSet is that when I > looked at the code, I told myself "ah, this actually is a binding set which also > owns the impl objects". Because it lives next to WeakBindingSet, I think it is > nice to have consistent names. > > Maybe you could tell me why you think the name StrongBindingSet doesn't > precisely reflect what the class does? I may have missed something. That makes sense. Changed to StrongBindingSet.
This seems pretty convoluted and moving further away from conventional Mojo bindings. In general, we should use templates very sparingly. They seem clever once you've invested the time in figuring out what they're doing, but they are hard for casual readers to understand and especially challenging to debug. You should not view template use as a substitute for more straightforward code. Yuzhu explained what you were trying to do to me, let me play it back and offer what I'd consider a "conventional" solution: - You have some object (GeolocationServiceContext) which is owned by WebContentsImpl. This object acts as a factory for GeolocationServiceImpls, which are bound to some mojom interface, with corresponding uses in the renderer. - You want to tie the lifetime of the GeolocationServiceImpls to both the pipe and the context so that they are destroyed when the pipe closes or the context is destroyed. The conventional way of solving this would be to have GeolocationServiceImpl have a StrongBinding to the interface pipe, and to have GeolocationServiceContext keep a set of GeolocationServiceImpl* it created. When the context is destroyed, it enumerates the set and deletes the impls, which cause the binding to fall out of scope and close the pipe. Alternatively, when the pipe closes, the GeolocationServiceImpl dtor should notify the context which would remove it from the set. Simple.
On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > This seems pretty convoluted and moving further away from conventional Mojo > bindings. In general, we should use templates very sparingly. They seem clever > once you've invested the time in figuring out what they're doing, but they are > hard for casual readers to understand and especially challenging to debug. You > should not view template use as a substitute for more straightforward code. Is this where you draw the line for complexity? Have you looked at most of the mojo-related code? It's full of layers of inscrutable complexity. Why have WeakBindingSet? Or StrongBinding for that matter? TypeConverters are right out, obviously. > > Yuzhu explained what you were trying to do to me, let me play it back and offer > what I'd consider a "conventional" solution: > > - You have some object (GeolocationServiceContext) which is owned by > WebContentsImpl. This object acts as a factory for GeolocationServiceImpls, > which are bound to some mojom interface, with corresponding uses in the > renderer. > - You want to tie the lifetime of the GeolocationServiceImpls to both the pipe > and the context so that they are destroyed when the pipe closes or the context > is destroyed. > > The conventional way of solving this would be to have GeolocationServiceImpl > have a StrongBinding to the interface pipe, and to have > GeolocationServiceContext keep a set of GeolocationServiceImpl* it created. When > the context is destroyed, it enumerates the set and deletes the impls, which > cause the binding to fall out of scope and close the pipe. Alternatively, when > the pipe closes, the GeolocationServiceImpl dtor should notify the context which > would remove it from the set. Simple. Simple, but buggy: you're notifying GeolocationServiceContext when it's responsible for the deletion. Maybe it's harmless, or maybe it'll remove that GeolocationServiceImpl* from GeolocationServiceContext's set, invalidating the iterator its destructor was using. The point of this is to have an abstraction that can be reused instead of each service implementation copy-pasting or reinventing this pattern each time.
On Wed, Dec 2, 2015 at 10:29 PM, <sammc@chromium.org> wrote: > On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > >> This seems pretty convoluted and moving further away from conventional >> Mojo >> bindings. In general, we should use templates very sparingly. They seem >> clever >> once you've invested the time in figuring out what they're doing, but >> they are >> hard for casual readers to understand and especially challenging to >> debug. You >> should not view template use as a substitute for more straightforward >> code. >> > > Is this where you draw the line for complexity? Have you looked at most of > the > mojo-related code? It's full of layers of inscrutable complexity. Why have > WeakBindingSet? Or StrongBinding for that matter? TypeConverters are right > out, > obviously. If Mojo is inscrutably complex, we should fix it and not use it as a justification to add more :-) Ken's recent straw man for burying mojom types is a great example of a simplifying improvement. WeakBindingSet and StrongBinding seem pretty simple from a user perspective but maybe I'm just used to using them, so simplifying suggestions welcome. There are of course ownership issues. There are always ownership issues. > The conventional way of solving this would be to have >> GeolocationServiceImpl >> > have a StrongBinding to the interface pipe, and to have >> GeolocationServiceContext keep a set of GeolocationServiceImpl* it >> created. >> > When > >> the context is destroyed, it enumerates the set and deletes the impls, >> which >> cause the binding to fall out of scope and close the pipe. Alternatively, >> when >> the pipe closes, the GeolocationServiceImpl dtor should notify the context >> > which > >> would remove it from the set. Simple. >> > > Simple, but buggy: you're notifying GeolocationServiceContext when it's > responsible for the deletion. Maybe it's harmless, or maybe it'll remove > that > GeolocationServiceImpl* from GeolocationServiceContext's set, invalidating > the > iterator its destructor was using. > Presumably you can have some checking to avoid a cycle. -Ben -- You received this message because you are subscribed to the Google Groups "Chromium-reviews" group. To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org.
On 2015/12/03 06:41:19, chromium-reviews wrote: > On Wed, Dec 2, 2015 at 10:29 PM, <mailto:sammc@chromium.org> wrote: > > > On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > > > >> This seems pretty convoluted and moving further away from conventional > >> Mojo > >> bindings. In general, we should use templates very sparingly. They seem > >> clever > >> once you've invested the time in figuring out what they're doing, but > >> they are > >> hard for casual readers to understand and especially challenging to > >> debug. You > >> should not view template use as a substitute for more straightforward > >> code. > >> > > > > Is this where you draw the line for complexity? Have you looked at most of > > the > > mojo-related code? It's full of layers of inscrutable complexity. Why have > > WeakBindingSet? Or StrongBinding for that matter? TypeConverters are right > > out, > > obviously. > > > If Mojo is inscrutably complex, we should fix it and not use it as a > justification to add more :-) Ken's recent straw man for burying mojom > types is a great example of a simplifying improvement. WeakBindingSet and > StrongBinding seem pretty simple from a user perspective but maybe I'm just > used to using them, so simplifying suggestions welcome. There are of course > ownership issues. There are always ownership issues. > If we're just looking at public interfaces (the high-level ones at least), then sure, it's quite straightforward, but I would argue the same is true of StrongBindingSet. It's a std::set<Impl> that automatically deletes things for you when they're no longer needed and some of the method names are different; in fact, in the common case (a class implementing a single mojo interface) we could deduce the mojo interface type from the Impl type and make it just StrongBindingSet<Impl> instead of StrongBindingSet<Interface, Impl>. The theme of these things seems to be hiding away unnecessary complexity from the user. Two-way ownership from both a message pipe and a C++ owner seems like the sort of unnecessary complexity that can be hidden away. > > > The conventional way of solving this would be to have > >> GeolocationServiceImpl > >> > > have a StrongBinding to the interface pipe, and to have > >> GeolocationServiceContext keep a set of GeolocationServiceImpl* it > >> created. > >> > > When > > > >> the context is destroyed, it enumerates the set and deletes the impls, > >> which > >> cause the binding to fall out of scope and close the pipe. Alternatively, > >> when > >> the pipe closes, the GeolocationServiceImpl dtor should notify the context > >> > > which > > > >> would remove it from the set. Simple. > >> > > > > Simple, but buggy: you're notifying GeolocationServiceContext when it's > > responsible for the deletion. Maybe it's harmless, or maybe it'll remove > > that > > GeolocationServiceImpl* from GeolocationServiceContext's set, invalidating > > the > > iterator its destructor was using. > > > > Presumably you can have some checking to avoid a cycle. Indeed, once you know what the problem is it's an easy fix, but it's another thing to think about or to get wrong and waste time debugging when writing something that follows this pattern. > > -Ben > > -- > You received this message because you are subscribed to the Google Groups > "Chromium-reviews" group. > To unsubscribe from this group and stop receiving emails from it, send an email > to mailto:chromium-reviews+unsubscribe@chromium.org.
On 2015/12/04 00:57:21, Sam McNally wrote: > On 2015/12/03 06:41:19, chromium-reviews wrote: > > On Wed, Dec 2, 2015 at 10:29 PM, <mailto:sammc@chromium.org> wrote: > > > > > On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > > > > > >> This seems pretty convoluted and moving further away from conventional > > >> Mojo > > >> bindings. In general, we should use templates very sparingly. They seem > > >> clever > > >> once you've invested the time in figuring out what they're doing, but > > >> they are > > >> hard for casual readers to understand and especially challenging to > > >> debug. You > > >> should not view template use as a substitute for more straightforward > > >> code. > > >> > > > > > > Is this where you draw the line for complexity? Have you looked at most of > > > the > > > mojo-related code? It's full of layers of inscrutable complexity. Why have > > > WeakBindingSet? Or StrongBinding for that matter? TypeConverters are right > > > out, > > > obviously. > > > > > > If Mojo is inscrutably complex, we should fix it and not use it as a > > justification to add more :-) Ken's recent straw man for burying mojom > > types is a great example of a simplifying improvement. WeakBindingSet and > > StrongBinding seem pretty simple from a user perspective but maybe I'm just > > used to using them, so simplifying suggestions welcome. There are of course > > ownership issues. There are always ownership issues. > > > If we're just looking at public interfaces (the high-level ones at least), then > sure, it's quite straightforward, but I would argue the same is true of > StrongBindingSet. It's a std::set<Impl> that automatically deletes things for > you when they're no longer needed and some of the method names are different; in > fact, in the common case (a class implementing a single mojo interface) we could > deduce the mojo interface type from the Impl type and make it just > StrongBindingSet<Impl> instead of StrongBindingSet<Interface, Impl>. Why don't we wait to see how often this comes up in practice as we convert features. If this turns out to be a common pattern, then we can spend more time thinking about the most straightforward generic solution. But if it's just a few places, then manual bookkeeping is enough.
On 2015/12/04 18:17:50, jam wrote: > On 2015/12/04 00:57:21, Sam McNally wrote: > > On 2015/12/03 06:41:19, chromium-reviews wrote: > > > On Wed, Dec 2, 2015 at 10:29 PM, <mailto:sammc@chromium.org> wrote: > > > > > > > On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > > > > > > > >> This seems pretty convoluted and moving further away from conventional > > > >> Mojo > > > >> bindings. In general, we should use templates very sparingly. They seem > > > >> clever > > > >> once you've invested the time in figuring out what they're doing, but > > > >> they are > > > >> hard for casual readers to understand and especially challenging to > > > >> debug. You > > > >> should not view template use as a substitute for more straightforward > > > >> code. > > > >> > > > > > > > > Is this where you draw the line for complexity? Have you looked at most of > > > > the > > > > mojo-related code? It's full of layers of inscrutable complexity. Why have > > > > WeakBindingSet? Or StrongBinding for that matter? TypeConverters are right > > > > out, > > > > obviously. > > > > > > > > > If Mojo is inscrutably complex, we should fix it and not use it as a > > > justification to add more :-) Ken's recent straw man for burying mojom > > > types is a great example of a simplifying improvement. WeakBindingSet and > > > StrongBinding seem pretty simple from a user perspective but maybe I'm just > > > used to using them, so simplifying suggestions welcome. There are of course > > > ownership issues. There are always ownership issues. > > > > > If we're just looking at public interfaces (the high-level ones at least), > then > > sure, it's quite straightforward, but I would argue the same is true of > > StrongBindingSet. It's a std::set<Impl> that automatically deletes things for > > you when they're no longer needed and some of the method names are different; > in > > fact, in the common case (a class implementing a single mojo interface) we > could > > deduce the mojo interface type from the Impl type and make it just > > StrongBindingSet<Impl> instead of StrongBindingSet<Interface, Impl>. > > Why don't we wait to see how often this comes up in practice as we convert > features. If this turns out to be a common pattern, then we can spend more time > thinking about the most straightforward generic solution. But if it's just a few > places, then manual bookkeeping is enough. Here's a breakdown of mojo services that may be used in chrome: WeakBindingSet (a special case of a context where the service instances trivially forward to the context): - VRService - device::usb::PermissionProvider Context: - PermissionService - GeolocationService - WakeLockService (service impls receive a WeakPtr to the context rather than being owned by the context) - BackgroundSync - ServicePortService - WebUI (with correct lifetime) StrongBinding: - SerialService - serial::Connection - BatteryMonitor - MimeHandlerService - extensions::KeepAlive (+ observers to delete on extension unload) - VibrationManager (no-op non-android impl) - ServicePortDispatcher (browser -> child) - ImageDownloader (browser -> renderer) - BackgroundSyncClient (browser -> renderer) - ProxyResolverFactory (browser -> utility) - ResourceUsageReporter (browser -> utility) - WebUI (with potentially incorrect lifetime) StrongBinding-like: - ProxyResolver (browser -> utility) - device::usb::DeviceManager - device::usb::Device Something else: - PresentationService - MediaRouter - ProxyResolverRequestClient - ProxyResolverFactoryRequestClient
On 2015/12/07 00:42:04, Sam McNally wrote: > On 2015/12/04 18:17:50, jam wrote: > > On 2015/12/04 00:57:21, Sam McNally wrote: > > > On 2015/12/03 06:41:19, chromium-reviews wrote: > > > > On Wed, Dec 2, 2015 at 10:29 PM, <mailto:sammc@chromium.org> wrote: > > > > > > > > > On 2015/12/03 05:13:28, Ben Goodger (Google) wrote: > > > > > > > > > >> This seems pretty convoluted and moving further away from conventional > > > > >> Mojo > > > > >> bindings. In general, we should use templates very sparingly. They seem > > > > >> clever > > > > >> once you've invested the time in figuring out what they're doing, but > > > > >> they are > > > > >> hard for casual readers to understand and especially challenging to > > > > >> debug. You > > > > >> should not view template use as a substitute for more straightforward > > > > >> code. > > > > >> > > > > > > > > > > Is this where you draw the line for complexity? Have you looked at most > of > > > > > the > > > > > mojo-related code? It's full of layers of inscrutable complexity. Why > have > > > > > WeakBindingSet? Or StrongBinding for that matter? TypeConverters are > right > > > > > out, > > > > > obviously. > > > > > > > > > > > > If Mojo is inscrutably complex, we should fix it and not use it as a > > > > justification to add more :-) Ken's recent straw man for burying mojom > > > > types is a great example of a simplifying improvement. WeakBindingSet and > > > > StrongBinding seem pretty simple from a user perspective but maybe I'm > just > > > > used to using them, so simplifying suggestions welcome. There are of > course > > > > ownership issues. There are always ownership issues. > > > > > > > If we're just looking at public interfaces (the high-level ones at least), > > then > > > sure, it's quite straightforward, but I would argue the same is true of > > > StrongBindingSet. It's a std::set<Impl> that automatically deletes things > for > > > you when they're no longer needed and some of the method names are > different; > > in > > > fact, in the common case (a class implementing a single mojo interface) we > > could > > > deduce the mojo interface type from the Impl type and make it just > > > StrongBindingSet<Impl> instead of StrongBindingSet<Interface, Impl>. > > > > Why don't we wait to see how often this comes up in practice as we convert > > features. If this turns out to be a common pattern, then we can spend more > time > > thinking about the most straightforward generic solution. But if it's just a > few > > places, then manual bookkeeping is enough. > > Here's a breakdown of mojo services that may be used in chrome: > > WeakBindingSet (a special case of a context where the service instances > trivially forward to the context): > - VRService > - device::usb::PermissionProvider > > Context: > - PermissionService > - GeolocationService > - WakeLockService (service impls receive a WeakPtr to the context rather than > being owned by the context) > - BackgroundSync > - ServicePortService > - WebUI (with correct lifetime) > > StrongBinding: > - SerialService > - serial::Connection > - BatteryMonitor > - MimeHandlerService > - extensions::KeepAlive (+ observers to delete on extension unload) > - VibrationManager (no-op non-android impl) > - ServicePortDispatcher (browser -> child) > - ImageDownloader (browser -> renderer) > - BackgroundSyncClient (browser -> renderer) > - ProxyResolverFactory (browser -> utility) > - ResourceUsageReporter (browser -> utility) > - WebUI (with potentially incorrect lifetime) > > StrongBinding-like: > - ProxyResolver (browser -> utility) > - device::usb::DeviceManager > - device::usb::Device > > Something else: > - PresentationService > - MediaRouter > - ProxyResolverRequestClient > - ProxyResolverFactoryRequestClient Just to be clear, the "Context" services are the ones that could benefit from StrongBindingSet, and it looks like ProxyResolverRequestClient can be added to that list too.
ProxyResolverRequestClient: https://codereview.chromium.org/1516493003/ PermissionService: https://codereview.chromium.org/1513973002/ BackgroundSyncService: https://codereview.chromium.org/1507233003/ How many times does this pattern need to occur before StrongBindingSet can be considered?
mvanouwerkerk@chromium.org changed reviewers: - mvanouwerkerk@chromium.org
On 2015/12/15 06:01:58, Sam McNally wrote: > ProxyResolverRequestClient: https://codereview.chromium.org/1516493003/ > PermissionService: https://codereview.chromium.org/1513973002/ > BackgroundSyncService: https://codereview.chromium.org/1507233003/ > > How many times does this pattern need to occur before StrongBindingSet can be > considered? Was this patch meant to fix crbug.com/556749 ?
On 2016/02/12 16:40:51, Michael van Ouwerkerk wrote: > On 2015/12/15 06:01:58, Sam McNally wrote: > > ProxyResolverRequestClient: https://codereview.chromium.org/1516493003/ > > PermissionService: https://codereview.chromium.org/1513973002/ > > BackgroundSyncService: https://codereview.chromium.org/1507233003/ > > > > How many times does this pattern need to occur before StrongBindingSet can be > > considered? > > Was this patch meant to fix crbug.com/556749 ? Yes. There's also a straightforward fix here, which I abandoned when informed of this CL: https://codereview.chromium.org/1459343003/
On 2016/02/15 08:41:01, blundell wrote: > On 2016/02/12 16:40:51, Michael van Ouwerkerk wrote: > > On 2015/12/15 06:01:58, Sam McNally wrote: > > > ProxyResolverRequestClient: https://codereview.chromium.org/1516493003/ > > > PermissionService: https://codereview.chromium.org/1513973002/ > > > BackgroundSyncService: https://codereview.chromium.org/1507233003/ > > > > > > How many times does this pattern need to occur before StrongBindingSet can > be > > > considered? > > > > Was this patch meant to fix crbug.com/556749 ? > > Yes. There's also a straightforward fix here, which I abandoned when informed of > this CL: > > https://codereview.chromium.org/1459343003/ This CL isn't likely to land any time soon. You should probably land yours. |