Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This is an application of a minimal host process in a Chromoting | 5 // This is an application of a minimal host process in a Chromoting |
| 6 // system. It serves the purpose of gluing different pieces together | 6 // system. It serves the purpose of gluing different pieces together |
| 7 // to make a functional host process for testing. | 7 // to make a functional host process for testing. |
| 8 // | 8 // |
| 9 // It peforms the following functionality: | 9 // It peforms the following functionality: |
| 10 // 1. Connect to the GTalk network and register the machine as a host. | 10 // 1. Connect to the GTalk network and register the machine as a host. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 const std::string kConfigSwitchName = "config"; | 64 const std::string kConfigSwitchName = "config"; |
| 65 | 65 |
| 66 int main(int argc, char** argv) { | 66 int main(int argc, char** argv) { |
| 67 // Needed for the Mac, so we don't leak objects when threads are created. | 67 // Needed for the Mac, so we don't leak objects when threads are created. |
| 68 base::mac::ScopedNSAutoreleasePool pool; | 68 base::mac::ScopedNSAutoreleasePool pool; |
| 69 | 69 |
| 70 CommandLine::Init(argc, argv); | 70 CommandLine::Init(argc, argv); |
| 71 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 71 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 72 | 72 |
| 73 base::AtExitManager exit_manager; | 73 base::AtExitManager exit_manager; |
| 74 | |
| 75 base::EnsureNSPRInit(); | 74 base::EnsureNSPRInit(); |
| 76 | 75 |
| 76 // Allocate a chromoting context and starts it. | |
| 77 remoting::ChromotingHostContext context; | |
| 78 context.Start(); | |
| 79 | |
| 77 scoped_ptr<remoting::Capturer> capturer; | 80 scoped_ptr<remoting::Capturer> capturer; |
| 78 scoped_ptr<remoting::EventExecutor> event_handler; | 81 scoped_ptr<remoting::protocol::InputStub> input_stub; |
| 79 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
| 80 capturer.reset(new remoting::CapturerGdi()); | 83 capturer.reset(new remoting::CapturerGdi()); |
| 81 event_handler.reset(new remoting::EventExecutorWin(capturer.get())); | 84 input_stub.reset(new remoting::EventExecutorWin( |
| 85 context.capture_message_loop_proxy(), capturer.get())); | |
| 82 #elif defined(OS_LINUX) | 86 #elif defined(OS_LINUX) |
| 83 capturer.reset(new remoting::CapturerLinux()); | 87 capturer.reset(new remoting::CapturerLinux()); |
| 84 event_handler.reset(new remoting::EventExecutorLinux(capturer.get())); | 88 input_stub.reset(new remoting::EventExecutorLinux( |
| 89 context.capture_message_loop_proxy(), capturer.get())); | |
| 85 #elif defined(OS_MACOSX) | 90 #elif defined(OS_MACOSX) |
| 86 capturer.reset(new remoting::CapturerMac()); | 91 capturer.reset(new remoting::CapturerMac()); |
| 87 event_handler.reset(new remoting::EventExecutorMac(capturer.get())); | 92 input_stub.reset(new remoting::EventExecutorMac( |
| 93 context.capture_message_loop_proxy(), capturer.get())); | |
| 88 #endif | 94 #endif |
| 89 | 95 |
| 90 // Check the argument to see if we should use a fake capturer. | 96 // Check the argument to see if we should use a fake capturer. |
| 91 bool fake = cmd_line->HasSwitch(kFakeSwitchName); | 97 bool fake = cmd_line->HasSwitch(kFakeSwitchName); |
| 92 | 98 |
| 93 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
| 94 std::wstring home_path = GetEnvironmentVar(kHomeDrive); | 100 std::wstring home_path = GetEnvironmentVar(kHomeDrive); |
| 95 home_path += GetEnvironmentVar(kHomePath); | 101 home_path += GetEnvironmentVar(kHomePath); |
| 96 #else | 102 #else |
| 97 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); | 103 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 110 | 116 |
| 111 base::Thread file_io_thread("FileIO"); | 117 base::Thread file_io_thread("FileIO"); |
| 112 file_io_thread.Start(); | 118 file_io_thread.Start(); |
| 113 | 119 |
| 114 scoped_refptr<remoting::JsonHostConfig> config( | 120 scoped_refptr<remoting::JsonHostConfig> config( |
| 115 new remoting::JsonHostConfig( | 121 new remoting::JsonHostConfig( |
| 116 config_path, file_io_thread.message_loop_proxy())); | 122 config_path, file_io_thread.message_loop_proxy())); |
| 117 | 123 |
| 118 if (!config->Read()) { | 124 if (!config->Read()) { |
| 119 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 125 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
| 126 context.Stop(); | |
|
awong
2010/11/12 01:40:10
Don't we want to do an explicit stop in the normal
Alpha Left Google
2010/11/12 22:56:40
Not sure what this means. But this error code path
awong
2010/11/12 23:29:04
Sorry...I just misread the code. Please ignore my
| |
| 120 return 1; | 127 return 1; |
| 121 } | 128 } |
| 122 | 129 |
| 123 // Allocate a chromoting context and starts it. | |
| 124 remoting::ChromotingHostContext context; | |
| 125 context.Start(); | |
| 126 | |
| 127 FilePath module_path; | 130 FilePath module_path; |
| 128 PathService::Get(base::DIR_MODULE, &module_path); | 131 PathService::Get(base::DIR_MODULE, &module_path); |
| 129 CHECK(media::InitializeMediaLibrary(module_path)) | 132 CHECK(media::InitializeMediaLibrary(module_path)) |
| 130 << "Cannot load media library"; | 133 << "Cannot load media library"; |
| 131 | 134 |
| 132 // Construct a chromoting host. | 135 // Construct a chromoting host. |
| 133 scoped_refptr<remoting::ChromotingHost> host( | 136 scoped_refptr<remoting::ChromotingHost> host( |
| 134 new remoting::ChromotingHost(&context, | 137 new remoting::ChromotingHost(&context, |
| 135 config, | 138 config, |
| 136 capturer.release(), | 139 capturer.release(), |
| 137 event_handler.release())); | 140 input_stub.release())); |
| 138 | 141 |
| 139 // Let the chromoting host run until the shutdown task is executed. | 142 // Let the chromoting host run until the shutdown task is executed. |
| 140 MessageLoop message_loop(MessageLoop::TYPE_UI); | 143 MessageLoop message_loop(MessageLoop::TYPE_UI); |
| 141 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); | 144 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
| 142 message_loop.Run(); | 145 message_loop.Run(); |
| 143 | 146 |
| 144 // And then stop the chromoting context. | 147 // And then stop the chromoting context. |
| 145 context.Stop(); | 148 context.Stop(); |
| 146 file_io_thread.Stop(); | 149 file_io_thread.Stop(); |
| 147 return 0; | 150 return 0; |
| 148 } | 151 } |
| OLD | NEW |