Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 9004050: Move signaling connection creation out of ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
Wez 2012/01/03 16:25:04 nit: Lose extra newline?
Sergey Ulanov 2012/01/03 21:51:02 Done.
96 // Use an XMPP connection to the Talk network for session signalling.
97 std::string xmpp_login;
98 std::string xmpp_auth_token;
99 if (!auth_config_->GetString(kXmppLoginConfigPath, &xmpp_login) ||
100 !auth_config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token)) {
101 LOG(ERROR) << "XMPP credentials are not defined in the config.";
102 return 1;
103 }
104
105 std::string xmpp_auth_service;
106 if (!auth_config_->GetString(remoting::kXmppAuthServiceConfigPath,
107 &xmpp_auth_service)) {
108 // For the me2me host, we assume we use the ClientLogin token for
109 // chromiumsync because we do not have an HTTP stack with which we can
110 // easily request an OAuth2 access token even if we had a RefreshToken for
111 // the account.
Wez 2012/01/03 16:25:04 Sorry, I'm not sure whether this comment belongs i
Sergey Ulanov 2012/01/03 21:51:02 It belongs inside because the if just tries to rea
112 xmpp_auth_service = remoting::kChromotingTokenDefaultServiceName;
113 }
114
115 // Create and start XMPP connection.
116 scoped_ptr<SignalStrategy> signal_strategy(
117 new XmppSignalStrategy(context.jingle_thread(), xmpp_login,
118 xmpp_auth_token, xmpp_auth_service));
119
94 // Create the DesktopEnvironment and ChromotingHost. 120 // Create the DesktopEnvironment and ChromotingHost.
95 scoped_ptr<DesktopEnvironment> desktop_environment( 121 scoped_ptr<DesktopEnvironment> desktop_environment(
96 DesktopEnvironment::Create(&context)); 122 DesktopEnvironment::Create(&context));
97 123
98 host_ = ChromotingHost::Create( 124 host_ = new ChromotingHost(
99 &context, host_config_, desktop_environment.get(), false); 125 &context, host_config_, signal_strategy.get(),
126 desktop_environment.get(), false);
100 127
101 // Initialize HeartbeatSender. 128 // Initialize HeartbeatSender.
102 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender( 129 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender(
103 new remoting::HeartbeatSender(context.network_message_loop(), 130 new remoting::HeartbeatSender());
104 host_config_)); 131 if (!heartbeat_sender->Init(signal_strategy.get(), host_config_)) {
105 if (!heartbeat_sender->Init()) {
106 context.Stop(); 132 context.Stop();
107 return 1; 133 return 1;
108 } 134 }
109 host_->AddStatusObserver(heartbeat_sender.get()); 135
136 // Post a task to start XMPP connection.
137 context.network_message_loop()->PostTask(
138 FROM_HERE, base::Bind(&remoting::SignalStrategy::Connect,
139 base::Unretained(signal_strategy.get())));
110 140
111 // Run the ChromotingHost until the shutdown task is executed. 141 // Run the ChromotingHost until the shutdown task is executed.
112 host_->Start(); 142 host_->Start();
113 143
114 // Set an empty shared-secret for Me2Me. 144 // Set an empty shared-secret for Me2Me.
115 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific 145 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific
116 // AuthenticatorFactory - crbug.com/105214. 146 // AuthenticatorFactory - crbug.com/105214.
117 context.network_message_loop()->PostTask( 147 context.network_message_loop()->PostTask(
118 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(), 148 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(),
119 "")); 149 ""));
120 150
121 message_loop.MessageLoop::Run(); 151 message_loop.MessageLoop::Run();
122 152
123 // And then stop the chromoting context. 153 // And then stop the chromoting context.
124 context.Stop(); 154 context.Stop();
125 file_io_thread.Stop(); 155 file_io_thread.Stop();
126 156
127 host_ = NULL; 157 host_ = NULL;
128 158
129 return 0; 159 return 0;
130 } 160 }
131 161
132 private: 162 private:
133 // Read Host config from disk, returning true if successful. 163 // Read Host config from disk, returning true if successful.
134 bool LoadConfig(base::MessageLoopProxy* message_loop_proxy) { 164 bool LoadConfig(base::MessageLoopProxy* message_loop_proxy) {
135 host_config_ = 165 host_config_ =
136 new remoting::JsonHostConfig(host_config_path_, message_loop_proxy); 166 new remoting::JsonHostConfig(host_config_path_, message_loop_proxy);
137 scoped_refptr<remoting::JsonHostConfig> auth_config = 167 auth_config_ =
138 new remoting::JsonHostConfig(auth_config_path_, message_loop_proxy); 168 new remoting::JsonHostConfig(auth_config_path_, message_loop_proxy);
139 169
140 std::string failed_path; 170 std::string failed_path;
141 if (!host_config_->Read()) { 171 if (!host_config_->Read()) {
142 failed_path = host_config_path_.value(); 172 failed_path = host_config_path_.value();
143 } else if (!auth_config->Read()) { 173 } else if (!auth_config_->Read()) {
144 failed_path = auth_config_path_.value(); 174 failed_path = auth_config_path_.value();
145 } 175 }
146 if (!failed_path.empty()) { 176 if (!failed_path.empty()) {
147 LOG(ERROR) << "Failed to read configuration file " << failed_path; 177 LOG(ERROR) << "Failed to read configuration file " << failed_path;
148 return false; 178 return false;
149 } 179 }
150 180
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; 181 return true;
165 } 182 }
166 183
167 FilePath auth_config_path_; 184 FilePath auth_config_path_;
168 FilePath host_config_path_; 185 FilePath host_config_path_;
169 186
187 scoped_refptr<remoting::JsonHostConfig> auth_config_;
170 scoped_refptr<remoting::JsonHostConfig> host_config_; 188 scoped_refptr<remoting::JsonHostConfig> host_config_;
171 189
172 scoped_refptr<ChromotingHost> host_; 190 scoped_refptr<ChromotingHost> host_;
173 }; 191 };
174 192
175 } // namespace remoting 193 } // namespace remoting
176 194
177 int main(int argc, char** argv) { 195 int main(int argc, char** argv) {
178 CommandLine::Init(argc, argv); 196 CommandLine::Init(argc, argv);
179 197
180 // This object instance is required by Chrome code (for example, 198 // This object instance is required by Chrome code (for example,
181 // LazyInstance, MessageLoop). 199 // LazyInstance, MessageLoop).
182 base::AtExitManager exit_manager; 200 base::AtExitManager exit_manager;
183 201
184 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 202 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
185 203
186 #if defined(TOOLKIT_USES_GTK) 204 #if defined(TOOLKIT_USES_GTK)
187 // Required for any calls into GTK functions, such as the Disconnect and 205 // 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 206 // Continue windows, though these should not be used for the Me2Me case
189 // (crbug.com/104377). 207 // (crbug.com/104377).
190 gfx::GtkInitFromCommandLine(*cmd_line); 208 gfx::GtkInitFromCommandLine(*cmd_line);
191 #endif // TOOLKIT_USES_GTK 209 #endif // TOOLKIT_USES_GTK
192 210
193 remoting::HostProcess me2me_host; 211 remoting::HostProcess me2me_host;
194 me2me_host.InitWithCommandLine(cmd_line); 212 me2me_host.InitWithCommandLine(cmd_line);
195 213
196 return me2me_host.Run(); 214 return me2me_host.Run();
197 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698