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.
5 #ifndef MOJO_APPLICATION_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_
6 #define MOJO_APPLICATION_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "mojo/application/public/cpp/interface_factory.h"
10 #include "mojo/application/public/interfaces/content_handler.mojom.h"
11 #include "mojo/application/public/interfaces/shell.mojom.h"
12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
16 class ContentHandlerFactory
: public InterfaceFactory
<ContentHandler
> {
18 class HandledApplicationHolder
{
20 virtual ~HandledApplicationHolder() {}
25 virtual ~Delegate() {}
26 // Implement this method to create the Application. This method will be
27 // called on a new thread. Leaving this method will quit the application.
28 virtual void RunApplication(
29 InterfaceRequest
<Application
> application_request
,
30 URLResponsePtr response
) = 0;
33 class ManagedDelegate
: public Delegate
{
35 ~ManagedDelegate() override
{}
36 // Implement this method to create the Application for the given content.
37 // This method will be called on a new thread. The application will be run
38 // on this new thread, and the returned value will be kept alive until the
40 virtual scoped_ptr
<HandledApplicationHolder
> CreateApplication(
41 InterfaceRequest
<Application
> application_request
,
42 URLResponsePtr response
) = 0;
45 void RunApplication(InterfaceRequest
<Application
> application_request
,
46 URLResponsePtr response
) override
;
49 explicit ContentHandlerFactory(Delegate
* delegate
);
50 ~ContentHandlerFactory() override
;
53 // From InterfaceFactory:
54 void Create(ApplicationConnection
* connection
,
55 InterfaceRequest
<ContentHandler
> request
) override
;
59 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory
);
63 class HandledApplicationHolderImpl
64 : public ContentHandlerFactory::HandledApplicationHolder
{
66 explicit HandledApplicationHolderImpl(A
* value
) : value_(value
) {}
73 scoped_ptr
<ContentHandlerFactory::HandledApplicationHolder
>
74 make_handled_factory_holder(A
* value
) {
75 return make_scoped_ptr(new HandledApplicationHolderImpl
<A
>(value
));
80 #endif // MOJO_APPLICATION_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_