1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/callback_forward.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/macros.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "mojo/public/cpp/system/core.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace base {
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class FilePath;
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace mojo {
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace shell {
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class Context;
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
22effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Abstraction for loading a service (from the file system) and running it (on
23effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// another thread or in a separate process).
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DynamicServiceRunner {
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~DynamicServiceRunner() {}
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Takes ownership of the file at |app_path|. Loads the app in that file and
2923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // runs it on some other thread/process. |app_completed_callback| is posted
3023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // (to the thread on which |Start()| was called) after |MojoMain()| completes.
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void Start(const base::FilePath& app_path,
320de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)                     ScopedMessagePipeHandle service_handle,
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     const base::Closure& app_completed_callback) = 0;
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DynamicServiceRunnerFactory {
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~DynamicServiceRunnerFactory() {}
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) = 0;
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// A generic factory.
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)template <class DynamicServiceRunnerImpl>
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DynamicServiceRunnerFactoryImpl : public DynamicServiceRunnerFactory {
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DynamicServiceRunnerFactoryImpl() {}
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~DynamicServiceRunnerFactoryImpl() {}
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE {
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return scoped_ptr<DynamicServiceRunner>(
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        new DynamicServiceRunnerImpl(context));
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace shell
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace mojo
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_
58