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

Side by Side Diff: services/util/cpp/factory_service_base.h

Issue 2010283006: Almost done: ApplicationDelegate -> ApplicationImplBase conversion. (Closed) Base URL: https://github.com/domokit/mojo.git@work798-x-work797-x-work796_no_run_main_app
Patch Set: rebased Created 4 years, 6 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
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_UTIL_CPP_FACTORY_SERVICE_BASE_H_ 5 #ifndef MOJO_SERVICES_UTIL_CPP_FACTORY_SERVICE_BASE_H_
6 #define MOJO_SERVICES_UTIL_CPP_FACTORY_SERVICE_BASE_H_ 6 #define MOJO_SERVICES_UTIL_CPP_FACTORY_SERVICE_BASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <unordered_set> 9 #include <unordered_set>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "mojo/public/cpp/application/application_delegate.h" 12 #include "mojo/public/cpp/application/application_impl_base.h"
13 #include "mojo/public/cpp/application/application_impl.h"
14 13
15 namespace mojo { 14 namespace mojo {
16 namespace util { 15 namespace util {
17 16
18 class FactoryServiceBase : public ApplicationDelegate { 17 class FactoryServiceBase : public ApplicationImplBase {
19 public: 18 public:
20 // Provides common behavior for all objects created by the factory service. 19 // Provides common behavior for all objects created by the factory service.
21 class ProductBase : public std::enable_shared_from_this<ProductBase> { 20 class ProductBase : public std::enable_shared_from_this<ProductBase> {
22 public: 21 public:
23 virtual ~ProductBase(); 22 virtual ~ProductBase();
24 23
25 protected: 24 protected:
26 ProductBase(FactoryServiceBase* owner); 25 explicit ProductBase(FactoryServiceBase* owner);
27 26
28 // Returns the ApplicationImpl. 27 // Returns the owner.
29 ApplicationImpl* app() { 28 FactoryServiceBase* owner() { return owner_; }
30 DCHECK(owner_->app());
31 return owner_->app();
32 }
33 29
34 // Tells the factory service to release this product. 30 // Tells the factory service to release this product.
35 void ReleaseFromOwner() { 31 void ReleaseFromOwner() {
36 size_t erased = owner_->products_.erase(shared_from_this()); 32 size_t erased = owner_->products_.erase(shared_from_this());
37 DCHECK(erased); 33 DCHECK(erased);
38 } 34 }
39 35
40 private: 36 private:
41 FactoryServiceBase* owner_; 37 FactoryServiceBase* owner_;
42 }; 38 };
(...skipping 22 matching lines...) Expand all
65 } 61 }
66 62
67 private: 63 private:
68 Binding<Interface> binding_; 64 Binding<Interface> binding_;
69 }; 65 };
70 66
71 FactoryServiceBase(); 67 FactoryServiceBase();
72 68
73 ~FactoryServiceBase() override; 69 ~FactoryServiceBase() override;
74 70
75 ApplicationImpl* app() { return app_; }
76
77 // ApplicationDelegate implementation.
78 void Initialize(ApplicationImpl* app) override;
79
80 protected: 71 protected:
81 template <typename ProductImpl> 72 template <typename ProductImpl>
82 void AddProduct(std::shared_ptr<ProductImpl> product) { 73 void AddProduct(std::shared_ptr<ProductImpl> product) {
83 products_.insert(std::static_pointer_cast<ProductBase>(product)); 74 products_.insert(std::static_pointer_cast<ProductBase>(product));
84 } 75 }
85 76
86 private: 77 private:
87 ApplicationImpl* app_;
88 std::unordered_set<std::shared_ptr<ProductBase>> products_; 78 std::unordered_set<std::shared_ptr<ProductBase>> products_;
89 }; 79 };
90 80
91 // For use by products when handling mojo requests. 81 // For use by products when handling mojo requests.
92 // Checks the condition, and, if it's false, unbinds, releases from the owner 82 // Checks the condition, and, if it's false, unbinds, releases from the owner
93 // and calls return. Doesn't support stream arguments. 83 // and calls return. Doesn't support stream arguments.
94 // TODO(dalesat): Support stream arguments. 84 // TODO(dalesat): Support stream arguments.
95 #define RCHECK(condition) \ 85 #define RCHECK(condition) \
96 if (!(condition)) { \ 86 if (!(condition)) { \
97 LOG(ERROR) << "request precondition failed: " #condition "."; \ 87 LOG(ERROR) << "request precondition failed: " #condition "."; \
98 UnbindAndReleaseFromOwner(); \ 88 UnbindAndReleaseFromOwner(); \
99 return; \ 89 return; \
100 } 90 }
101 91
102 } // namespace util 92 } // namespace util
103 } // namespace mojo 93 } // namespace mojo
104 94
105 #endif // MOJO_SERVICES_UTIL_CPP_FACTORY_SERVICE_BASE_H_ 95 #endif // MOJO_SERVICES_UTIL_CPP_FACTORY_SERVICE_BASE_H_
OLDNEW
« no previous file with comments | « services/ui/view_manager/view_associate_table.h ('k') | services/util/cpp/factory_service_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698