Chromium Code Reviews| 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 SHELL_DYNAMIC_SERVICE_RUNNER_H_ | 5 #ifndef SHELL_DYNAMIC_SERVICE_RUNNER_H_ |
| 6 #define SHELL_DYNAMIC_SERVICE_RUNNER_H_ | 6 #define SHELL_DYNAMIC_SERVICE_RUNNER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/native_library.h" | 10 #include "base/native_library.h" |
| 11 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class FilePath; | 14 class FilePath; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace shell { | 18 namespace shell { |
| 19 | 19 |
| 20 class Context; | 20 class Context; |
| 21 | 21 |
| 22 // Abstraction for loading a service (from the file system) and running it (on | 22 // Abstraction for loading a service (from the file system) and running it (on |
| 23 // another thread or in a separate process). | 23 // another thread or in a separate process). |
| 24 class DynamicServiceRunner { | 24 class DynamicServiceRunner { |
| 25 public: | 25 public: |
| 26 virtual ~DynamicServiceRunner() {} | 26 virtual ~DynamicServiceRunner() {} |
| 27 | 27 |
| 28 // Takes ownership of the file at |app_path|. Loads the app in that file and | 28 // Loads the app in the file at |app_path| and runs it on some other |
| 29 // runs it on some other thread/process. |app_completed_callback| is posted | 29 // thread/process. If |clean_app_path| is |true|, takes ownership of the file. |
| 30 // (to the thread on which |Start()| was called) after |MojoMain()| completes. | 30 // |app_completed_callback| is posted (to the thread on which |Start()| was |
| 31 // called) after |MojoMain()| completes. | |
| 31 virtual void Start(const base::FilePath& app_path, | 32 virtual void Start(const base::FilePath& app_path, |
| 33 bool clean_app_path, | |
|
Aaron Boodman
2015/01/22 19:51:31
Recommend using an enum as suggested by eseidel fo
qsr
2015/01/26 09:12:13
Done.
| |
| 32 ScopedMessagePipeHandle service_handle, | 34 ScopedMessagePipeHandle service_handle, |
| 33 const base::Closure& app_completed_callback) = 0; | 35 const base::Closure& app_completed_callback) = 0; |
| 34 | 36 |
| 35 // Loads the service in the DSO specificed by |app_path| and prepares it for | 37 // Loads the service in the DSO specificed by |app_path| and prepares it for |
| 36 // execution. Runs the DSO's exported function MojoMain(). | 38 // execution. Runs the DSO's exported function MojoMain(). |
| 37 // The NativeLibrary is returned and ownership transferred to the caller. | 39 // The NativeLibrary is returned and ownership transferred to the caller. |
| 38 // This is so if it is unloaded at all, this can be done safely after this | 40 // This is so if it is unloaded at all, this can be done safely after this |
| 39 // thread is destroyed and any thread-local destructors have been executed. | 41 // thread is destroyed and any thread-local destructors have been executed. |
| 40 static base::NativeLibrary LoadAndRunService( | 42 static base::NativeLibrary LoadAndRunService( |
| 41 const base::FilePath& app_path, | 43 const base::FilePath& app_path, |
| 44 bool clean_app_path, | |
| 42 ScopedMessagePipeHandle service_handle); | 45 ScopedMessagePipeHandle service_handle); |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 class DynamicServiceRunnerFactory { | 48 class DynamicServiceRunnerFactory { |
| 46 public: | 49 public: |
| 47 virtual ~DynamicServiceRunnerFactory() {} | 50 virtual ~DynamicServiceRunnerFactory() {} |
| 48 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) = 0; | 51 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) = 0; |
| 49 }; | 52 }; |
| 50 | 53 |
| 51 // A generic factory. | 54 // A generic factory. |
| 52 template <class DynamicServiceRunnerImpl> | 55 template <class DynamicServiceRunnerImpl> |
| 53 class DynamicServiceRunnerFactoryImpl : public DynamicServiceRunnerFactory { | 56 class DynamicServiceRunnerFactoryImpl : public DynamicServiceRunnerFactory { |
| 54 public: | 57 public: |
| 55 DynamicServiceRunnerFactoryImpl() {} | 58 DynamicServiceRunnerFactoryImpl() {} |
| 56 virtual ~DynamicServiceRunnerFactoryImpl() {} | 59 virtual ~DynamicServiceRunnerFactoryImpl() {} |
| 57 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) override { | 60 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) override { |
| 58 return scoped_ptr<DynamicServiceRunner>( | 61 return scoped_ptr<DynamicServiceRunner>( |
| 59 new DynamicServiceRunnerImpl(context)); | 62 new DynamicServiceRunnerImpl(context)); |
| 60 } | 63 } |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 } // namespace shell | 66 } // namespace shell |
| 64 } // namespace mojo | 67 } // namespace mojo |
| 65 | 68 |
| 66 #endif // SHELL_DYNAMIC_SERVICE_RUNNER_H_ | 69 #endif // SHELL_DYNAMIC_SERVICE_RUNNER_H_ |
| OLD | NEW |