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_IN_PROCESS_DYNAMIC_SERVICE_RUNNER_H_ 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define MOJO_SHELL_IN_PROCESS_DYNAMIC_SERVICE_RUNNER_H_ 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/callback.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/files/file_path.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/macros.h" 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/scoped_native_library.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/threading/simple_thread.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "mojo/shell/dynamic_service_runner.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace mojo { 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace shell { 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// An implementation of |DynamicServiceRunner| that loads/runs the given app 19effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// (from the file system) on a separate thread (in the current process). 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class InProcessDynamicServiceRunner 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : public DynamicServiceRunner, 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public base::DelegateSimpleThread::Delegate { 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) explicit InProcessDynamicServiceRunner(Context* context); 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ~InProcessDynamicServiceRunner(); 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |DynamicServiceRunner| method: 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void Start(const base::FilePath& app_path, 290de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) ScopedMessagePipeHandle service_handle, 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::Closure& app_completed_callback) OVERRIDE; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private: 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |base::DelegateSimpleThread::Delegate| method: 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void Run() OVERRIDE; 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::FilePath app_path_; 370de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) ScopedMessagePipeHandle service_handle_; 3823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) base::Callback<bool(void)> app_completed_callback_runner_; 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::ScopedNativeLibrary app_library_; 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_ptr<base::DelegateSimpleThread> thread_; 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(InProcessDynamicServiceRunner); 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}; 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)typedef DynamicServiceRunnerFactoryImpl<InProcessDynamicServiceRunner> 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) InProcessDynamicServiceRunnerFactory; 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace shell 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace mojo 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif // MOJO_SHELL_IN_PROCESS_DYNAMIC_SERVICE_RUNNER_H_ 53