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 MOJO_APPS_JS_JS_APP_H_ | 5 #ifndef MOJO_APPS_JS_JS_APP_H_ |
6 #define MOJO_APPS_JS_JS_APP_H_ | 6 #define MOJO_APPS_JS_JS_APP_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/single_thread_task_runner.h" | |
10 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
11 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
12 #include "gin/shell_runner.h" | 11 #include "gin/shell_runner.h" |
13 #include "mojo/apps/js/mojo_runner_delegate.h" | 12 #include "mojo/apps/js/mojo_runner_delegate.h" |
14 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" | 13 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" |
15 | 14 |
16 namespace mojo { | 15 namespace mojo { |
17 namespace apps { | 16 namespace apps { |
18 | 17 |
19 class JSApp; | 18 class JSApp; |
20 class ApplicationDelegateImpl; | 19 class ApplicationDelegateImpl; |
21 | 20 |
22 // Each JavaScript app started by content handler runs on its own thread and | 21 // Each JavaScript app started by content handler runs on its own thread and |
23 // in its own V8 isolate. This class represents one running JS app. | 22 // in its own V8 isolate. This class represents one running JS app. |
24 // | |
25 // The lifetime of this class is defined by the content handler's internal | |
26 // "app_vector" list. | |
27 | 23 |
28 class JSApp { | 24 class JSApp { |
29 public: | 25 public: |
30 JSApp(ApplicationDelegateImpl* content_handler_app, | 26 JSApp(ApplicationDelegateImpl* app_delegate_impl); |
31 const std::string& url, | 27 virtual ~JSApp(); |
32 URLResponsePtr content); | |
33 ~JSApp(); | |
34 | 28 |
| 29 // Launch this app on a new thread. This method can be called on any thread. |
| 30 // This method causes Load() and then Run() to run on a new thread. |
35 bool Start(); | 31 bool Start(); |
| 32 |
| 33 |
| 34 // Subclasses must return the JS source code for this app's main script and |
| 35 // the filename or URL that identifies the script's origin. This method will |
| 36 // be called from this app's thread. |
| 37 virtual bool Load(std::string* source, std::string* file_name) = 0; |
| 38 |
| 39 // Called by the JS mojo module to quit this JS app. See mojo_module.cc. |
36 void Quit(); | 40 void Quit(); |
| 41 |
| 42 // Called by the JS mojo module to connect to a Mojo service. |
37 Handle ConnectToService(const std::string& application_url, | 43 Handle ConnectToService(const std::string& application_url, |
38 const std::string& interface_name); | 44 const std::string& interface_name); |
39 | 45 |
40 private: | 46 private: |
41 void Run(); | 47 void Run(); |
42 void Terminate(); | 48 void Terminate(); |
43 | 49 |
44 // Used to CHECK that we're running on the correct thread. | 50 // Used to CHECK that we're running on the correct thread. |
45 bool on_content_handler_thread() const; | 51 bool on_app_delegate_impl_thread() const; |
46 bool on_js_app_thread() const; | 52 bool on_js_app_thread() const; |
47 | 53 |
48 ApplicationDelegateImpl* content_handler_app_; | 54 ApplicationDelegateImpl* app_delegate_impl_; |
49 std::string url_; | |
50 URLResponsePtr content_; | |
51 base::Thread thread_; | 55 base::Thread thread_; |
52 scoped_refptr<base::SingleThreadTaskRunner> content_handler_task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> app_delegate_impl_task_runner_; |
53 scoped_refptr<base::SingleThreadTaskRunner> js_app_task_runner_; | 57 scoped_refptr<base::SingleThreadTaskRunner> js_app_task_runner_; |
54 MojoRunnerDelegate runner_delegate_; | 58 MojoRunnerDelegate runner_delegate_; |
55 scoped_ptr<gin::IsolateHolder> isolate_holder_; | 59 scoped_ptr<gin::IsolateHolder> isolate_holder_; |
56 scoped_ptr<gin::ShellRunner> shell_runner_; | 60 scoped_ptr<gin::ShellRunner> shell_runner_; |
57 | 61 |
58 DISALLOW_COPY_AND_ASSIGN(JSApp); | 62 DISALLOW_COPY_AND_ASSIGN(JSApp); |
59 }; | 63 }; |
60 | 64 |
61 } // namespace apps | 65 } // namespace apps |
62 } // namespace mojo | 66 } // namespace mojo |
63 | 67 |
64 #endif // MOJO_APPS_JS_JS_APP_H_ | 68 #endif // MOJO_APPS_JS_JS_APP_H_ |
OLD | NEW |