| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 file implements a standalone host process for Me2Me, which is currently | 5 // This file implements a standalone host process for Me2Me, which is currently |
| 6 // used for the Linux-only Virtual Me2Me build. | 6 // used for the Linux-only Virtual Me2Me build. |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "crypto/nss_util.h" | 22 #include "crypto/nss_util.h" |
| 23 #include "remoting/base/constants.h" | 23 #include "remoting/base/constants.h" |
| 24 #include "remoting/host/capturer.h" | 24 #include "remoting/host/capturer.h" |
| 25 #include "remoting/host/chromoting_host.h" | 25 #include "remoting/host/chromoting_host.h" |
| 26 #include "remoting/host/chromoting_host_context.h" | 26 #include "remoting/host/chromoting_host_context.h" |
| 27 #include "remoting/host/desktop_environment.h" | 27 #include "remoting/host/desktop_environment.h" |
| 28 #include "remoting/host/event_executor.h" | 28 #include "remoting/host/event_executor.h" |
| 29 #include "remoting/host/heartbeat_sender.h" | 29 #include "remoting/host/heartbeat_sender.h" |
| 30 #include "remoting/host/host_config.h" | 30 #include "remoting/host/host_config.h" |
| 31 #include "remoting/host/json_host_config.h" | 31 #include "remoting/host/json_host_config.h" |
| 32 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 32 | 33 |
| 33 #if defined(TOOLKIT_USES_GTK) | 34 #if defined(TOOLKIT_USES_GTK) |
| 34 #include "ui/gfx/gtk_util.h" | 35 #include "ui/gfx/gtk_util.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 // These are used for parsing the config-file locations from the command line, | 39 // These are used for parsing the config-file locations from the command line, |
| 39 // and for defining the default locations if the switches are not present. | 40 // and for defining the default locations if the switches are not present. |
| 40 const char kAuthConfigSwitchName[] = "auth-config"; | 41 const char kAuthConfigSwitchName[] = "auth-config"; |
| 41 const char kHostConfigSwitchName[] = "host-config"; | 42 const char kHostConfigSwitchName[] = "host-config"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 context.Start(); | 85 context.Start(); |
| 85 | 86 |
| 86 base::Thread file_io_thread("FileIO"); | 87 base::Thread file_io_thread("FileIO"); |
| 87 file_io_thread.Start(); | 88 file_io_thread.Start(); |
| 88 | 89 |
| 89 if (!LoadConfig(file_io_thread.message_loop_proxy())) { | 90 if (!LoadConfig(file_io_thread.message_loop_proxy())) { |
| 90 context.Stop(); | 91 context.Stop(); |
| 91 return 1; | 92 return 1; |
| 92 } | 93 } |
| 93 | 94 |
| 95 // Use an XMPP connection to the Talk network for session signalling. |
| 96 std::string xmpp_login; |
| 97 std::string xmpp_auth_token; |
| 98 if (!auth_config_->GetString(kXmppLoginConfigPath, &xmpp_login) || |
| 99 !auth_config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token)) { |
| 100 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 101 return 1; |
| 102 } |
| 103 |
| 104 std::string xmpp_auth_service; |
| 105 if (!auth_config_->GetString(remoting::kXmppAuthServiceConfigPath, |
| 106 &xmpp_auth_service)) { |
| 107 // For the me2me host, we assume we use the ClientLogin token for |
| 108 // chromiumsync because we do not have an HTTP stack with which we can |
| 109 // easily request an OAuth2 access token even if we had a RefreshToken for |
| 110 // the account. |
| 111 xmpp_auth_service = remoting::kChromotingTokenDefaultServiceName; |
| 112 } |
| 113 |
| 114 // Create and start XMPP connection. |
| 115 scoped_ptr<SignalStrategy> signal_strategy( |
| 116 new XmppSignalStrategy(context.jingle_thread(), xmpp_login, |
| 117 xmpp_auth_token, xmpp_auth_service)); |
| 118 |
| 94 // Create the DesktopEnvironment and ChromotingHost. | 119 // Create the DesktopEnvironment and ChromotingHost. |
| 95 scoped_ptr<DesktopEnvironment> desktop_environment( | 120 scoped_ptr<DesktopEnvironment> desktop_environment( |
| 96 DesktopEnvironment::Create(&context)); | 121 DesktopEnvironment::Create(&context)); |
| 97 | 122 |
| 98 host_ = ChromotingHost::Create( | 123 host_ = new ChromotingHost( |
| 99 &context, host_config_, desktop_environment.get(), false); | 124 &context, host_config_, signal_strategy.get(), |
| 125 desktop_environment.get(), false); |
| 100 | 126 |
| 101 // Initialize HeartbeatSender. | 127 // Initialize HeartbeatSender. |
| 102 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender( | 128 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender( |
| 103 new remoting::HeartbeatSender(context.network_message_loop(), | 129 new remoting::HeartbeatSender()); |
| 104 host_config_)); | 130 if (!heartbeat_sender->Init(signal_strategy.get(), host_config_)) { |
| 105 if (!heartbeat_sender->Init()) { | |
| 106 context.Stop(); | 131 context.Stop(); |
| 107 return 1; | 132 return 1; |
| 108 } | 133 } |
| 109 host_->AddStatusObserver(heartbeat_sender.get()); | 134 |
| 135 // Post a task to start XMPP connection. |
| 136 context.network_message_loop()->PostTask( |
| 137 FROM_HERE, base::Bind(&remoting::SignalStrategy::Connect, |
| 138 base::Unretained(signal_strategy.get()))); |
| 110 | 139 |
| 111 // Run the ChromotingHost until the shutdown task is executed. | 140 // Run the ChromotingHost until the shutdown task is executed. |
| 112 host_->Start(); | 141 host_->Start(); |
| 113 | 142 |
| 114 // Set an empty shared-secret for Me2Me. | 143 // Set an empty shared-secret for Me2Me. |
| 115 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific | 144 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific |
| 116 // AuthenticatorFactory - crbug.com/105214. | 145 // AuthenticatorFactory - crbug.com/105214. |
| 117 context.network_message_loop()->PostTask( | 146 context.network_message_loop()->PostTask( |
| 118 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(), | 147 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(), |
| 119 "")); | 148 "")); |
| 120 | 149 |
| 121 message_loop.MessageLoop::Run(); | 150 message_loop.MessageLoop::Run(); |
| 122 | 151 |
| 123 // And then stop the chromoting context. | 152 // And then stop the chromoting context. |
| 124 context.Stop(); | 153 context.Stop(); |
| 125 file_io_thread.Stop(); | 154 file_io_thread.Stop(); |
| 126 | 155 |
| 127 host_ = NULL; | 156 host_ = NULL; |
| 128 | 157 |
| 129 return 0; | 158 return 0; |
| 130 } | 159 } |
| 131 | 160 |
| 132 private: | 161 private: |
| 133 // Read Host config from disk, returning true if successful. | 162 // Read Host config from disk, returning true if successful. |
| 134 bool LoadConfig(base::MessageLoopProxy* message_loop_proxy) { | 163 bool LoadConfig(base::MessageLoopProxy* message_loop_proxy) { |
| 135 host_config_ = | 164 host_config_ = |
| 136 new remoting::JsonHostConfig(host_config_path_, message_loop_proxy); | 165 new remoting::JsonHostConfig(host_config_path_, message_loop_proxy); |
| 137 scoped_refptr<remoting::JsonHostConfig> auth_config = | 166 auth_config_ = |
| 138 new remoting::JsonHostConfig(auth_config_path_, message_loop_proxy); | 167 new remoting::JsonHostConfig(auth_config_path_, message_loop_proxy); |
| 139 | 168 |
| 140 std::string failed_path; | 169 std::string failed_path; |
| 141 if (!host_config_->Read()) { | 170 if (!host_config_->Read()) { |
| 142 failed_path = host_config_path_.value(); | 171 failed_path = host_config_path_.value(); |
| 143 } else if (!auth_config->Read()) { | 172 } else if (!auth_config_->Read()) { |
| 144 failed_path = auth_config_path_.value(); | 173 failed_path = auth_config_path_.value(); |
| 145 } | 174 } |
| 146 if (!failed_path.empty()) { | 175 if (!failed_path.empty()) { |
| 147 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 176 LOG(ERROR) << "Failed to read configuration file " << failed_path; |
| 148 return false; | 177 return false; |
| 149 } | 178 } |
| 150 | 179 |
| 151 // Copy the needed keys from |auth_config| into |host_config|. | |
| 152 std::string value; | |
| 153 auth_config->GetString(kXmppAuthTokenConfigPath, &value); | |
| 154 host_config_->SetString(kXmppAuthTokenConfigPath, value); | |
| 155 auth_config->GetString(kXmppLoginConfigPath, &value); | |
| 156 host_config_->SetString(kXmppLoginConfigPath, value); | |
| 157 | |
| 158 // For the Me2Me host, we assume we always use the ClientLogin token for | |
| 159 // chromiumsync because we do not have an HTTP stack with which we can | |
| 160 // easily request an OAuth2 access token even if we had a RefreshToken for | |
| 161 // the account. | |
| 162 host_config_->SetString(kXmppAuthServiceConfigPath, | |
| 163 kChromotingTokenDefaultServiceName); | |
| 164 return true; | 180 return true; |
| 165 } | 181 } |
| 166 | 182 |
| 167 FilePath auth_config_path_; | 183 FilePath auth_config_path_; |
| 168 FilePath host_config_path_; | 184 FilePath host_config_path_; |
| 169 | 185 |
| 186 scoped_refptr<remoting::JsonHostConfig> auth_config_; |
| 170 scoped_refptr<remoting::JsonHostConfig> host_config_; | 187 scoped_refptr<remoting::JsonHostConfig> host_config_; |
| 171 | 188 |
| 172 scoped_refptr<ChromotingHost> host_; | 189 scoped_refptr<ChromotingHost> host_; |
| 173 }; | 190 }; |
| 174 | 191 |
| 175 } // namespace remoting | 192 } // namespace remoting |
| 176 | 193 |
| 177 int main(int argc, char** argv) { | 194 int main(int argc, char** argv) { |
| 178 CommandLine::Init(argc, argv); | 195 CommandLine::Init(argc, argv); |
| 179 | 196 |
| 180 // This object instance is required by Chrome code (for example, | 197 // This object instance is required by Chrome code (for example, |
| 181 // LazyInstance, MessageLoop). | 198 // LazyInstance, MessageLoop). |
| 182 base::AtExitManager exit_manager; | 199 base::AtExitManager exit_manager; |
| 183 | 200 |
| 184 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 201 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 185 | 202 |
| 186 #if defined(TOOLKIT_USES_GTK) | 203 #if defined(TOOLKIT_USES_GTK) |
| 187 // Required for any calls into GTK functions, such as the Disconnect and | 204 // Required for any calls into GTK functions, such as the Disconnect and |
| 188 // Continue windows, though these should not be used for the Me2Me case | 205 // Continue windows, though these should not be used for the Me2Me case |
| 189 // (crbug.com/104377). | 206 // (crbug.com/104377). |
| 190 gfx::GtkInitFromCommandLine(*cmd_line); | 207 gfx::GtkInitFromCommandLine(*cmd_line); |
| 191 #endif // TOOLKIT_USES_GTK | 208 #endif // TOOLKIT_USES_GTK |
| 192 | 209 |
| 193 remoting::HostProcess me2me_host; | 210 remoting::HostProcess me2me_host; |
| 194 me2me_host.InitWithCommandLine(cmd_line); | 211 me2me_host.InitWithCommandLine(cmd_line); |
| 195 | 212 |
| 196 return me2me_host.Run(); | 213 return me2me_host.Run(); |
| 197 } | 214 } |
| OLD | NEW |