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

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

Issue 2007593004: Motown: Factor FactoryServiceBase out of MediaFactoryService (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 | « services/media/factory_service/BUILD.gn ('k') | 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 f2a7fd518c938185b884d1afd6f8906682a65327..8b4f520337dc72d6269f55fa99877724eadf3357 100644
--- a/services/media/factory_service/factory_service.h
+++ b/services/media/factory_service/factory_service.h
@@ -5,77 +5,23 @@
#ifndef MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_
#define MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_
-#include <unordered_set>
-
#include "mojo/common/binding_set.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/services/media/control/interfaces/media_factory.mojom.h"
+#include "services/util/cpp/factory_service_base.h"
namespace mojo {
namespace media {
-class MediaFactoryService : public ApplicationDelegate,
+class MediaFactoryService : public util::FactoryServiceBase,
public MediaFactory {
public:
- // Provides common behavior for all objects created by the factory service.
- class ProductBase : public std::enable_shared_from_this<ProductBase> {
- public:
- virtual ~ProductBase();
-
- protected:
- ProductBase(MediaFactoryService* owner);
-
- // Returns the ApplicationImpl.
- ApplicationImpl* app() {
- DCHECK(owner_->app_);
- return owner_->app_;
- }
-
- // Tells the factory service to release this product.
- void ReleaseFromOwner() {
- size_t erased = owner_->products_.erase(shared_from_this());
- DCHECK(erased);
- }
-
- private:
- 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;
// ApplicationDelegate implementation.
- void Initialize(ApplicationImpl* app) override;
-
bool ConfigureIncomingConnection(
ServiceProviderImpl* service_provider_impl) override;
@@ -102,21 +48,8 @@ class MediaFactoryService : public ApplicationDelegate,
private:
BindingSet<MediaFactory> bindings_;
- ApplicationImpl* app_;
- 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 | « services/media/factory_service/BUILD.gn ('k') | services/media/factory_service/factory_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698