| 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/service_provider_impl.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 struct ConnectionContext; | 16 struct ConnectionContext; |
| 17 | 17 |
| 18 // TODO(vtl): Should this even be a class, now that InterfaceFactory is no more? | 18 // TODO(vtl): Nuke this class. Now it's only a "namespace" for stuff, most of |
| 19 // which is overcomplicated. |
| 19 class ContentHandlerFactory { | 20 class ContentHandlerFactory { |
| 20 public: | 21 public: |
| 21 class HandledApplicationHolder { | 22 class HandledApplicationHolder { |
| 22 public: | 23 public: |
| 23 virtual ~HandledApplicationHolder() {} | 24 virtual ~HandledApplicationHolder() {} |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 class Delegate { | 27 class Delegate { |
| 27 public: | 28 public: |
| 28 virtual ~Delegate() {} | 29 virtual ~Delegate() {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 42 // application ends. | 43 // application ends. |
| 43 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( | 44 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( |
| 44 InterfaceRequest<Application> application_request, | 45 InterfaceRequest<Application> application_request, |
| 45 URLResponsePtr response) = 0; | 46 URLResponsePtr response) = 0; |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 void RunApplication(InterfaceRequest<Application> application_request, | 49 void RunApplication(InterfaceRequest<Application> application_request, |
| 49 URLResponsePtr response) override; | 50 URLResponsePtr response) override; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 explicit ContentHandlerFactory(Delegate* delegate); | |
| 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>()|. | 53 // For use with |ServiceProviderImpl::AddService<ContentHandler>()|. |
| 60 ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> | 54 static ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> |
| 61 GetInterfaceRequestHandler(); | 55 GetInterfaceRequestHandler(Delegate* delegate); |
| 62 | |
| 63 private: | |
| 64 Delegate* delegate_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); | |
| 67 }; | 56 }; |
| 68 | 57 |
| 69 template <class A> | 58 template <class A> |
| 70 class HandledApplicationHolderImpl | 59 class HandledApplicationHolderImpl |
| 71 : public ContentHandlerFactory::HandledApplicationHolder { | 60 : public ContentHandlerFactory::HandledApplicationHolder { |
| 72 public: | 61 public: |
| 73 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} | 62 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} |
| 74 | 63 |
| 75 private: | 64 private: |
| 76 scoped_ptr<A> value_; | 65 scoped_ptr<A> value_; |
| 77 }; | 66 }; |
| 78 | 67 |
| 79 template <class A> | 68 template <class A> |
| 80 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 69 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> |
| 81 make_handled_factory_holder(A* value) { | 70 make_handled_factory_holder(A* value) { |
| 82 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); | 71 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); |
| 83 } | 72 } |
| 84 | 73 |
| 85 } // namespace mojo | 74 } // namespace mojo |
| 86 | 75 |
| 87 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | 76 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
| OLD | NEW |