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