OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | 5 #ifndef MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
6 #define MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | 6 #define MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "mojo/public/cpp/application/interface_factory.h" | 9 #include "mojo/public/cpp/application/service_provider_impl.h" |
10 #include "mojo/public/interfaces/application/shell.mojom.h" | 10 #include "mojo/public/interfaces/application/shell.mojom.h" |
11 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" | 11 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
12 #include "mojo/services/network/interfaces/url_loader.mojom.h" | 12 #include "mojo/services/network/interfaces/url_loader.mojom.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 class ContentHandlerFactory : public InterfaceFactory<ContentHandler> { | 16 struct ConnectionContext; |
| 17 |
| 18 // TODO(vtl): Should this even be a class, now that InterfaceFactory is no more? |
| 19 class ContentHandlerFactory { |
17 public: | 20 public: |
18 class HandledApplicationHolder { | 21 class HandledApplicationHolder { |
19 public: | 22 public: |
20 virtual ~HandledApplicationHolder() {} | 23 virtual ~HandledApplicationHolder() {} |
21 }; | 24 }; |
22 | 25 |
23 class Delegate { | 26 class Delegate { |
24 public: | 27 public: |
25 virtual ~Delegate() {} | 28 virtual ~Delegate() {} |
26 // Implement this method to create the Application. This method will be | 29 // Implement this method to create the Application. This method will be |
(...skipping 13 matching lines...) Expand all Loading... |
40 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( | 43 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( |
41 InterfaceRequest<Application> application_request, | 44 InterfaceRequest<Application> application_request, |
42 URLResponsePtr response) = 0; | 45 URLResponsePtr response) = 0; |
43 | 46 |
44 private: | 47 private: |
45 void RunApplication(InterfaceRequest<Application> application_request, | 48 void RunApplication(InterfaceRequest<Application> application_request, |
46 URLResponsePtr response) override; | 49 URLResponsePtr response) override; |
47 }; | 50 }; |
48 | 51 |
49 explicit ContentHandlerFactory(Delegate* delegate); | 52 explicit ContentHandlerFactory(Delegate* delegate); |
50 ~ContentHandlerFactory() override; | 53 ~ContentHandlerFactory(); |
| 54 |
| 55 // Creates a content handler for the given connection (context and request). |
| 56 void Create(const ConnectionContext& connection_context, |
| 57 InterfaceRequest<ContentHandler> content_handler_request); |
| 58 |
| 59 // For use with |ServiceProviderImpl::AddService<ContentHandler>()|. |
| 60 ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> |
| 61 GetInterfaceRequestHandler(); |
51 | 62 |
52 private: | 63 private: |
53 // From InterfaceFactory: | |
54 void Create(const ConnectionContext& connection_context, | |
55 InterfaceRequest<ContentHandler> request) override; | |
56 | |
57 Delegate* delegate_; | 64 Delegate* delegate_; |
58 | 65 |
59 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); | 66 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); |
60 }; | 67 }; |
61 | 68 |
62 template <class A> | 69 template <class A> |
63 class HandledApplicationHolderImpl | 70 class HandledApplicationHolderImpl |
64 : public ContentHandlerFactory::HandledApplicationHolder { | 71 : public ContentHandlerFactory::HandledApplicationHolder { |
65 public: | 72 public: |
66 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} | 73 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} |
67 | 74 |
68 private: | 75 private: |
69 scoped_ptr<A> value_; | 76 scoped_ptr<A> value_; |
70 }; | 77 }; |
71 | 78 |
72 template <class A> | 79 template <class A> |
73 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 80 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> |
74 make_handled_factory_holder(A* value) { | 81 make_handled_factory_holder(A* value) { |
75 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); | 82 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); |
76 } | 83 } |
77 | 84 |
78 } // namespace mojo | 85 } // namespace mojo |
79 | 86 |
80 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | 87 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
OLD | NEW |