| 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 #include "chrome/service/remoting/chromoting_host_manager.h" | 5 #include "chrome/service/remoting/chromoting_host_manager.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/common/guid.h" | 9 #include "chrome/common/guid.h" |
| 10 #include "chrome/common/remoting/chromoting_host_info.h" | 10 #include "chrome/common/remoting/chromoting_host_info.h" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/host/chromoting_host_context.h" | 13 #include "remoting/host/chromoting_host_context.h" |
| 14 #include "remoting/host/heartbeat_sender.h" |
| 15 #include "remoting/host/host_key_pair.h" |
| 14 #include "remoting/host/json_host_config.h" | 16 #include "remoting/host/json_host_config.h" |
| 15 | 17 |
| 16 namespace remoting { | 18 namespace remoting { |
| 17 | 19 |
| 18 ChromotingHostManager::ChromotingHostManager(Observer* observer) | 20 ChromotingHostManager::ChromotingHostManager(Observer* observer) |
| 19 : observer_(observer), | 21 : observer_(observer), |
| 20 main_message_loop_(NULL) { | 22 main_message_loop_(NULL) { |
| 21 } | 23 } |
| 22 | 24 |
| 23 void ChromotingHostManager::Initialize( | 25 void ChromotingHostManager::Initialize( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 174 |
| 173 // Start the chromoting context first. | 175 // Start the chromoting context first. |
| 174 chromoting_context_.reset( | 176 chromoting_context_.reset( |
| 175 new remoting::ChromotingHostContext(main_message_loop_)); | 177 new remoting::ChromotingHostContext(main_message_loop_)); |
| 176 chromoting_context_->Start(); | 178 chromoting_context_->Start(); |
| 177 | 179 |
| 178 // Create a chromoting host object. | 180 // Create a chromoting host object. |
| 179 chromoting_host_ = remoting::ChromotingHost::Create(chromoting_context_.get(), | 181 chromoting_host_ = remoting::ChromotingHost::Create(chromoting_context_.get(), |
| 180 chromoting_config_); | 182 chromoting_config_); |
| 181 | 183 |
| 184 // Initialize HeartbeatSender. |
| 185 scoped_refptr<remoting::HeartbeatSender> heartbeat_sender = |
| 186 new remoting::HeartbeatSender(chromoting_context_->network_message_loop(), |
| 187 chromoting_config_); |
| 188 if (!heartbeat_sender->Init()) |
| 189 LOG(ERROR) << "Failed to initialize heartbeat sender."; |
| 190 chromoting_host_->AddStatusObserver(heartbeat_sender); |
| 191 |
| 192 |
| 182 // Then start the chromoting host. | 193 // Then start the chromoting host. |
| 183 // When ChromotingHost is shutdown because of failure or a request that | 194 // When ChromotingHost is shutdown because of failure or a request that |
| 184 // we made OnChromotingShutdown() is calls. | 195 // we made OnChromotingShutdown() is calls. |
| 185 chromoting_host_->Start( | 196 chromoting_host_->Start( |
| 186 NewRunnableMethod(this, &ChromotingHostManager::OnShutdown)); | 197 NewRunnableMethod(this, &ChromotingHostManager::OnShutdown)); |
| 187 } | 198 } |
| 188 | 199 |
| 189 void ChromotingHostManager::OnShutdown() { | 200 void ChromotingHostManager::OnShutdown() { |
| 190 if (MessageLoop::current() != main_message_loop_) { | 201 if (MessageLoop::current() != main_message_loop_) { |
| 191 main_message_loop_->PostTask(FROM_HERE, | 202 main_message_loop_->PostTask(FROM_HERE, |
| 192 NewRunnableMethod(this, &ChromotingHostManager::OnShutdown)); | 203 NewRunnableMethod(this, &ChromotingHostManager::OnShutdown)); |
| 193 return; | 204 return; |
| 194 } | 205 } |
| 195 chromoting_context_->Stop(); | 206 chromoting_context_->Stop(); |
| 196 chromoting_context_.reset(); | 207 chromoting_context_.reset(); |
| 197 chromoting_host_ = NULL; | 208 chromoting_host_ = NULL; |
| 198 | 209 |
| 199 if (shutdown_task_.get()) { | 210 if (shutdown_task_.get()) { |
| 200 shutdown_task_->Run(); | 211 shutdown_task_->Run(); |
| 201 shutdown_task_.reset(); | 212 shutdown_task_.reset(); |
| 202 } | 213 } |
| 203 } | 214 } |
| 204 | 215 |
| 205 } // namespace remoting | 216 } // namespace remoting |
| OLD | NEW |