OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_STANDALONE_CONTEXT_H_ | 5 #ifndef MOJO_SHELL_STANDALONE_CONTEXT_H_ |
6 #define MOJO_SHELL_STANDALONE_CONTEXT_H_ | 6 #define MOJO_SHELL_STANDALONE_CONTEXT_H_ |
7 | 7 |
8 #include <set> | |
9 #include <string> | |
10 | |
11 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 9 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
15 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
16 #include "base/time/time.h" | 13 #include "base/time/time.h" |
17 #include "mojo/edk/embedder/process_delegate.h" | 14 #include "mojo/edk/embedder/process_delegate.h" |
18 #include "mojo/shell/application_manager.h" | 15 #include "mojo/shell/application_manager.h" |
19 #include "mojo/shell/standalone/tracer.h" | 16 #include "mojo/shell/standalone/tracer.h" |
20 #include "url/gurl.h" | 17 #include "url/gurl.h" |
21 | 18 |
22 namespace base { | 19 namespace base { |
23 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
24 } | 21 } |
25 | 22 |
26 namespace mojo { | 23 namespace mojo { |
27 namespace shell { | 24 namespace shell { |
28 class NativeApplicationLoader; | |
29 | 25 |
30 // The "global" context for the shell's main process. | 26 // The "global" context for the shell's main process. |
31 class Context : public edk::ProcessDelegate { | 27 class Context : public edk::ProcessDelegate { |
32 public: | 28 public: |
33 Context(); | 29 Context(); |
34 ~Context() override; | 30 ~Context() override; |
35 | 31 |
36 static void EnsureEmbedderIsInitialized(); | 32 static void EnsureEmbedderIsInitialized(); |
37 | 33 |
38 // This must be called with a message loop set up for the current thread, | 34 // This must be called with a message loop set up for the current thread, |
39 // which must remain alive until after Shutdown() is called. | 35 // which must remain alive until after Shutdown() is called. |
40 void Init(const base::FilePath& shell_file_root); | 36 void Init(const base::FilePath& shell_file_root); |
41 | 37 |
42 // If Init() was called and succeeded, this must be called before destruction. | 38 // If Init() was called and succeeded, this must be called before destruction. |
43 void Shutdown(); | 39 void Shutdown(); |
44 | 40 |
45 // NOTE: call either Run() or RunCommandLineApplication(), but not both. | 41 // Run the application specified on the command line. |
| 42 void RunCommandLineApplication(); |
| 43 |
| 44 private: |
| 45 // edk::ProcessDelegate: |
| 46 void OnShutdownComplete() override; |
46 | 47 |
47 // Runs the app specified by |url|. | 48 // Runs the app specified by |url|. |
48 void Run(const GURL& url); | 49 void Run(const GURL& url); |
49 | 50 |
50 // Run the application specified on the commandline. When the app finishes, | |
51 // |callback| is run if not null, otherwise the message loop is quit. | |
52 void RunCommandLineApplication(const base::Closure& callback); | |
53 | |
54 ApplicationManager* application_manager() { | |
55 return application_manager_.get(); | |
56 } | |
57 | |
58 private: | |
59 class NativeViewportApplicationLoader; | |
60 | |
61 // ProcessDelegate implementation. | |
62 void OnShutdownComplete() override; | |
63 | |
64 void OnApplicationEnd(const GURL& url); | |
65 | |
66 std::set<GURL> app_urls_; | |
67 | |
68 scoped_refptr<base::SingleThreadTaskRunner> shell_runner_; | 51 scoped_refptr<base::SingleThreadTaskRunner> shell_runner_; |
69 scoped_ptr<base::Thread> io_thread_; | 52 scoped_ptr<base::Thread> io_thread_; |
70 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | 53 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
71 | 54 |
72 // Ensure this is destructed before task_runners_ since it owns a message pipe | 55 // Ensure this is destructed before task_runners_ since it owns a message pipe |
73 // that needs the IO thread to destruct cleanly. | 56 // that needs the IO thread to destruct cleanly. |
74 Tracer tracer_; | 57 Tracer tracer_; |
75 scoped_ptr<ApplicationManager> application_manager_; | 58 scoped_ptr<ApplicationManager> application_manager_; |
76 base::Closure app_complete_callback_; | |
77 base::Time main_entry_time_; | 59 base::Time main_entry_time_; |
78 | 60 |
79 DISALLOW_COPY_AND_ASSIGN(Context); | 61 DISALLOW_COPY_AND_ASSIGN(Context); |
80 }; | 62 }; |
81 | 63 |
82 } // namespace shell | 64 } // namespace shell |
83 } // namespace mojo | 65 } // namespace mojo |
84 | 66 |
85 #endif // MOJO_SHELL_STANDALONE_CONTEXT_H_ | 67 #endif // MOJO_SHELL_STANDALONE_CONTEXT_H_ |
OLD | NEW |