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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | services/media/factory_service/factory_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_ 5 #ifndef MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_
6 #define MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_ 6 #define MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_
7 7
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "mojo/common/binding_set.h" 10 #include "mojo/common/binding_set.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" 13 #include "mojo/services/media/control/interfaces/media_factory.mojom.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace media { 16 namespace media {
17 17
18 class MediaFactoryService : public ApplicationDelegate, 18 class MediaFactoryService : public ApplicationDelegate,
19 public InterfaceFactory<MediaFactory>, 19 public InterfaceFactory<MediaFactory>,
20 public MediaFactory { 20 public MediaFactory {
21 public: 21 public:
22 // Provides common behavior for all objects created by the factory service. 22 // Provides common behavior for all objects created by the factory service.
23 class Product : public std::enable_shared_from_this<Product> { 23 class ProductBase : public std::enable_shared_from_this<ProductBase> {
24 public: 24 public:
25 virtual ~Product(); 25 virtual ~ProductBase();
26 26
27 protected: 27 protected:
28 Product(MediaFactoryService* owner); 28 ProductBase(MediaFactoryService* owner);
29 29
30 // Returns the ApplicationImpl. 30 // Returns the ApplicationImpl.
31 ApplicationImpl* app() { 31 ApplicationImpl* app() {
32 DCHECK(owner_->app_); 32 DCHECK(owner_->app_);
33 return owner_->app_; 33 return owner_->app_;
34 } 34 }
35 35
36 // Tells the factory service to release this product. 36 // Tells the factory service to release this product.
37 void ReleaseFromOwner() { 37 void ReleaseFromOwner() {
38 size_t erased = owner_->products_.erase(shared_from_this()); 38 size_t erased = owner_->products_.erase(shared_from_this());
39 DCHECK(erased); 39 DCHECK(erased);
40 } 40 }
41 41
42 private: 42 private:
43 MediaFactoryService* owner_; 43 MediaFactoryService* owner_;
44 }; 44 };
45 45
46 template <typename Interface>
47 class Product : public ProductBase {
48 public:
49 virtual ~Product() {}
50
51 protected:
52 Product(Interface* impl,
53 InterfaceRequest<Interface> request,
54 MediaFactoryService* owner)
55 : ProductBase(owner), binding_(impl, request.Pass()) {
56 DCHECK(impl);
57 binding_.set_connection_error_handler([this]() { ReleaseFromOwner(); });
58 }
59
60 // Closes the binding and calls ReleaseFromOwner.
61 void Abort() {
62 if (binding_.is_bound()) {
63 binding_.Close();
64 }
65
66 ReleaseFromOwner();
67 }
68
69 private:
70 Binding<Interface> binding_;
71 };
72
46 MediaFactoryService(); 73 MediaFactoryService();
47 74
48 ~MediaFactoryService() override; 75 ~MediaFactoryService() override;
49 76
50 // ApplicationDelegate implementation. 77 // ApplicationDelegate implementation.
51 void Initialize(ApplicationImpl* app) override; 78 void Initialize(ApplicationImpl* app) override;
52 79
53 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; 80 bool ConfigureIncomingConnection(ApplicationConnection* connection) override;
54 81
55 // InterfaceFactory<MediaFactory> implementation. 82 // InterfaceFactory<MediaFactory> implementation.
(...skipping 17 matching lines...) Expand all
73 100
74 void CreateDecoder(MediaTypePtr input_media_type, 101 void CreateDecoder(MediaTypePtr input_media_type,
75 InterfaceRequest<MediaTypeConverter> decoder) override; 102 InterfaceRequest<MediaTypeConverter> decoder) override;
76 103
77 void CreateNetworkReader(const String& url, 104 void CreateNetworkReader(const String& url,
78 InterfaceRequest<SeekingReader> reader) override; 105 InterfaceRequest<SeekingReader> reader) override;
79 106
80 private: 107 private:
81 BindingSet<MediaFactory> bindings_; 108 BindingSet<MediaFactory> bindings_;
82 ApplicationImpl* app_; 109 ApplicationImpl* app_;
83 std::unordered_set<std::shared_ptr<Product>> products_; 110 std::unordered_set<std::shared_ptr<ProductBase>> products_;
84 }; 111 };
85 112
113 // For use by products when handling mojo requests.
114 // Checks the condition, and, if it's false, aborts and calls return. Doesn't
115 // support stream arguments.
116 // TODO(dalesat): Support stream arguments.
117 #define RCHECK(condition) \
118 if (!(condition)) { \
119 LOG(ERROR) << "request precondition failed: " #condition "."; \
120 Abort(); \
kulakowski 2016/05/05 21:46:18 Ah. |abort| is overloaded. I think this (and the c
dalesat 2016/05/05 22:41:06 Done.
121 return; \
122 }
123
86 } // namespace media 124 } // namespace media
87 } // namespace mojo 125 } // namespace mojo
88 126
89 #endif // MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_ 127 #endif // MOJO_SERVICES_MEDIA_FACTORY_FACTORY_SERVICE_H_
OLDNEW
« 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