Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: mojo/shell/dynamic_service_runner.h

Issue 691653002: Factor out loading & running of DSOs (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Extra import Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_ 5 #ifndef MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_
6 #define MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_ 6 #define MOJO_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 "mojo/public/cpp/system/core.h" 11 #include "mojo/public/cpp/system/core.h"
11 12
12 namespace base { 13 namespace base {
13 class FilePath; 14 class FilePath;
14 } 15 }
15 16
16 namespace mojo { 17 namespace mojo {
17 namespace shell { 18 namespace shell {
18 19
19 class Context; 20 class Context;
20 21
21 // 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
22 // another thread or in a separate process). 23 // another thread or in a separate process).
23 class DynamicServiceRunner { 24 class DynamicServiceRunner {
24 public: 25 public:
25 virtual ~DynamicServiceRunner() {} 26 virtual ~DynamicServiceRunner() {}
26 27
27 // Takes ownership of the file at |app_path|. Loads the app in that file and 28 // Takes ownership of the file at |app_path|. Loads the app in that file and
28 // runs it on some other thread/process. |app_completed_callback| is posted 29 // runs it on some other thread/process. |app_completed_callback| is posted
29 // (to the thread on which |Start()| was called) after |MojoMain()| completes. 30 // (to the thread on which |Start()| was called) after |MojoMain()| completes.
30 virtual void Start(const base::FilePath& app_path, 31 virtual void Start(const base::FilePath& app_path,
31 ScopedMessagePipeHandle service_handle, 32 ScopedMessagePipeHandle service_handle,
32 const base::Closure& app_completed_callback) = 0; 33 const base::Closure& app_completed_callback) = 0;
34
35 // Loads the service in the DSO specificed by |app_path| and prepares it for
36 // execution. Runs the exported function MojoMain() and blocks until it
viettrungluu 2014/10/29 23:11:43 Just say "Runs the DSO's exported MojoMain() on th
DaveMoore 2014/10/30 15:32:56 Done.
37 // returns.
38 // The NativeLibrary is returned and ownership transfered to the caller.
viettrungluu 2014/10/29 23:11:43 "transfered" -> "transferred"
DaveMoore 2014/10/30 15:32:56 Done.
39 // This is primarilly so if it is to be unloaded through
viettrungluu 2014/10/29 23:11:43 "primarilly" -> "primarily" Maybe just say: This
DaveMoore 2014/10/30 15:32:56 Done.
40 // base::UnloadNativeLibrary it can be done so safely after the thread that
41 // the library was loaded on has been destroyed, after safely executing any
42 // thread local destructors.
43 static base::NativeLibrary LoadAndRunService(
44 const base::FilePath& app_path,
45 ScopedMessagePipeHandle service_handle);
33 }; 46 };
34 47
35 class DynamicServiceRunnerFactory { 48 class DynamicServiceRunnerFactory {
36 public: 49 public:
37 virtual ~DynamicServiceRunnerFactory() {} 50 virtual ~DynamicServiceRunnerFactory() {}
38 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) = 0; 51 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) = 0;
39 }; 52 };
40 53
41 // A generic factory. 54 // A generic factory.
42 template <class DynamicServiceRunnerImpl> 55 template <class DynamicServiceRunnerImpl>
43 class DynamicServiceRunnerFactoryImpl : public DynamicServiceRunnerFactory { 56 class DynamicServiceRunnerFactoryImpl : public DynamicServiceRunnerFactory {
44 public: 57 public:
45 DynamicServiceRunnerFactoryImpl() {} 58 DynamicServiceRunnerFactoryImpl() {}
46 virtual ~DynamicServiceRunnerFactoryImpl() {} 59 virtual ~DynamicServiceRunnerFactoryImpl() {}
47 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) override { 60 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) override {
48 return scoped_ptr<DynamicServiceRunner>( 61 return scoped_ptr<DynamicServiceRunner>(
49 new DynamicServiceRunnerImpl(context)); 62 new DynamicServiceRunnerImpl(context));
50 } 63 }
51 }; 64 };
52 65
53 } // namespace shell 66 } // namespace shell
54 } // namespace mojo 67 } // namespace mojo
55 68
56 #endif // MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_ 69 #endif // MOJO_SHELL_DYNAMIC_SERVICE_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698