OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
| 6 #define MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "mojo/public/cpp/application/interface_factory.h" |
| 10 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 11 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" |
| 12 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" |
| 13 |
| 14 namespace mojo { |
| 15 |
| 16 class ContentHandlerFactory : public InterfaceFactory<ContentHandler> { |
| 17 public: |
| 18 class HandledApplicationHolder { |
| 19 public: |
| 20 virtual ~HandledApplicationHolder() {} |
| 21 }; |
| 22 |
| 23 class Delegate { |
| 24 public: |
| 25 virtual ~Delegate() {} |
| 26 // Implement this method to create the Application for the given |
| 27 // content. This method will be called on a new thread. The application will |
| 28 // be run on this new thread, and the returned |
| 29 // value will be kept alive until the application ends. |
| 30 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( |
| 31 ShellPtr shell, |
| 32 URLResponsePtr response) = 0; |
| 33 }; |
| 34 |
| 35 explicit ContentHandlerFactory(Delegate* delegate); |
| 36 virtual ~ContentHandlerFactory(); |
| 37 |
| 38 private: |
| 39 // From InterfaceFactory: |
| 40 virtual void Create(ApplicationConnection* connection, |
| 41 InterfaceRequest<ContentHandler> request) override; |
| 42 |
| 43 Delegate* delegate_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); |
| 46 }; |
| 47 |
| 48 template <class A> |
| 49 class HandledApplicationHolderImpl |
| 50 : public ContentHandlerFactory::HandledApplicationHolder { |
| 51 public: |
| 52 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} |
| 53 |
| 54 private: |
| 55 scoped_ptr<A> value_; |
| 56 }; |
| 57 |
| 58 template <class A> |
| 59 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> |
| 60 make_handled_factory_holder(A* value) { |
| 61 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); |
| 62 } |
| 63 |
| 64 } // namespace mojo |
| 65 |
| 66 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ |
OLD | NEW |