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