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

Unified Diff: services/media/factory_service/factory_service.h

Issue 1945903006: Motown: Move responsibility for binding to MediaFactoryService::Product (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Change per feedback - rename Abort to UnbindAndReleaseFromOwner Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | services/media/factory_service/factory_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/media/factory_service/factory_service.h
diff --git a/services/media/factory_service/factory_service.h b/services/media/factory_service/factory_service.h
index 62ebc72c9fa01eac06b370eb470b2eecb986370f..309a4ed8e356a224efda4dd046988f3ac04008ce 100644
--- a/services/media/factory_service/factory_service.h
+++ b/services/media/factory_service/factory_service.h
@@ -20,12 +20,12 @@ class MediaFactoryService : public ApplicationDelegate,
public MediaFactory {
public:
// Provides common behavior for all objects created by the factory service.
- class Product : public std::enable_shared_from_this<Product> {
+ class ProductBase : public std::enable_shared_from_this<ProductBase> {
public:
- virtual ~Product();
+ virtual ~ProductBase();
protected:
- Product(MediaFactoryService* owner);
+ ProductBase(MediaFactoryService* owner);
// Returns the ApplicationImpl.
ApplicationImpl* app() {
@@ -43,6 +43,33 @@ class MediaFactoryService : public ApplicationDelegate,
MediaFactoryService* owner_;
};
+ template <typename Interface>
+ class Product : public ProductBase {
+ public:
+ virtual ~Product() {}
+
+ protected:
+ Product(Interface* impl,
+ InterfaceRequest<Interface> request,
+ MediaFactoryService* owner)
+ : ProductBase(owner), binding_(impl, request.Pass()) {
+ DCHECK(impl);
+ binding_.set_connection_error_handler([this]() { ReleaseFromOwner(); });
+ }
+
+ // Closes the binding and calls ReleaseFromOwner.
+ void UnbindAndReleaseFromOwner() {
+ if (binding_.is_bound()) {
+ binding_.Close();
+ }
+
+ ReleaseFromOwner();
+ }
+
+ private:
+ Binding<Interface> binding_;
+ };
+
MediaFactoryService();
~MediaFactoryService() override;
@@ -80,9 +107,20 @@ class MediaFactoryService : public ApplicationDelegate,
private:
BindingSet<MediaFactory> bindings_;
ApplicationImpl* app_;
- std::unordered_set<std::shared_ptr<Product>> products_;
+ std::unordered_set<std::shared_ptr<ProductBase>> products_;
};
+// For use by products when handling mojo requests.
+// Checks the condition, and, if it's false, unbinds, releases from the owner
+// and calls return. Doesn't support stream arguments.
+// TODO(dalesat): Support stream arguments.
+#define RCHECK(condition) \
+ if (!(condition)) { \
+ LOG(ERROR) << "request precondition failed: " #condition "."; \
+ UnbindAndReleaseFromOwner(); \
+ return; \
+ }
+
} // namespace media
} // namespace mojo
« no previous file with comments | « no previous file | services/media/factory_service/factory_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698