OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <iostream> |
| 6 |
5 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
6 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" |
9 #include "base/i18n/icu_util.h" | 12 #include "base/i18n/icu_util.h" |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/threading/worker_pool.h" |
| 16 #include "mojo/common/data_pipe_utils.h" |
12 #include "sky/shell/platform_view.h" | 17 #include "sky/shell/platform_view.h" |
13 #include "sky/shell/service_provider.h" | 18 #include "sky/shell/service_provider.h" |
14 #include "sky/shell/shell.h" | 19 #include "sky/shell/shell.h" |
15 #include "sky/shell/shell_view.h" | 20 #include "sky/shell/shell_view.h" |
| 21 #include "sky/shell/switches.h" |
16 | 22 |
17 namespace sky { | 23 namespace sky { |
18 namespace shell { | 24 namespace shell { |
| 25 namespace { |
19 | 26 |
20 const char kMain[] = "main"; | 27 void Ignored(bool) { |
21 const char kPackageRoot[] = "package-root"; | 28 } |
| 29 |
| 30 void Usage() { |
| 31 std::cerr << "Usage: sky_shell" |
| 32 << " [--" << switches::kPackageRoot << "]" |
| 33 << " [--" << switches::kSnapshot << "]" |
| 34 << " <sky-app>" << std::endl; |
| 35 } |
22 | 36 |
23 void Init() { | 37 void Init() { |
24 Shell::Init(make_scoped_ptr(new ServiceProviderContext( | 38 Shell::Init(make_scoped_ptr(new ServiceProviderContext( |
25 base::MessageLoop::current()->task_runner()))); | 39 base::MessageLoop::current()->task_runner()))); |
26 | 40 |
27 // TODO(abarth): Currently we leak the ShellView. | 41 // TODO(abarth): Currently we leak the ShellView. |
28 ShellView* shell_view = new ShellView(Shell::Shared()); | 42 ShellView* shell_view = new ShellView(Shell::Shared()); |
29 | 43 |
30 ViewportObserverPtr viewport_observer; | 44 ViewportObserverPtr viewport_observer; |
31 shell_view->view()->ConnectToViewportObserver(GetProxy(&viewport_observer)); | 45 shell_view->view()->ConnectToViewportObserver(GetProxy(&viewport_observer)); |
32 | 46 |
33 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); | 47 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
34 | 48 |
35 std::string main = command_line.GetSwitchValueASCII(kMain); | 49 std::string main = command_line.GetArgs()[0]; |
36 std::string package_root = command_line.GetSwitchValueASCII(kPackageRoot); | 50 if (command_line.HasSwitch(switches::kSnapshot)) { |
| 51 base::FilePath snapshot = |
| 52 command_line.GetSwitchValuePath(switches::kSnapshot); |
| 53 mojo::DataPipe pipe; |
| 54 viewport_observer->RunFromSnapshot(main, pipe.consumer_handle.Pass()); |
| 55 scoped_refptr<base::TaskRunner> runner = |
| 56 base::WorkerPool::GetTaskRunner(true); |
| 57 mojo::common::CopyFromFile(snapshot, pipe.producer_handle.Pass(), 0, |
| 58 runner.get(), base::Bind(&Ignored)); |
| 59 return; |
| 60 } |
37 | 61 |
38 viewport_observer->RunFromFile(main, package_root); | 62 if (command_line.HasSwitch(switches::kPackageRoot)) { |
| 63 std::string package_root = |
| 64 command_line.GetSwitchValueASCII(switches::kPackageRoot); |
| 65 viewport_observer->RunFromFile(main, package_root); |
| 66 return; |
| 67 } |
| 68 |
| 69 std::cerr << "One of --" << switches::kPackageRoot << " or --" |
| 70 << switches::kSnapshot << " is required." << std::endl; |
39 } | 71 } |
40 | 72 |
| 73 } // namespace |
41 } // namespace shell | 74 } // namespace shell |
42 } // namespace sky | 75 } // namespace sky |
43 | 76 |
44 int main(int argc, const char* argv[]) { | 77 int main(int argc, const char* argv[]) { |
45 base::AtExitManager exit_manager; | 78 base::AtExitManager exit_manager; |
46 base::CommandLine::Init(argc, argv); | 79 base::CommandLine::Init(argc, argv); |
47 | 80 |
| 81 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
| 82 |
| 83 if (command_line.HasSwitch(sky::shell::switches::kHelp) || |
| 84 command_line.GetArgs().empty()) { |
| 85 sky::shell::Usage(); |
| 86 return 0; |
| 87 } |
| 88 |
48 base::MessageLoop message_loop; | 89 base::MessageLoop message_loop; |
49 | 90 |
50 base::i18n::InitializeICU(); | 91 base::i18n::InitializeICU(); |
51 | 92 |
52 message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::Init)); | 93 message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::Init)); |
53 message_loop.Run(); | 94 message_loop.Run(); |
54 | 95 |
55 return 0; | 96 return 0; |
56 } | 97 } |
OLD | NEW |