OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
Wez
2011/11/11 00:24:09
This file should really be remoting_me2me_host.cc,
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // This file implements a standalone host process for Me2Me, which is used for | |
6 // the Virtual Me2Me implementation. Currently, this is Linux-only. | |
Sergey Ulanov
2011/11/11 00:00:43
I don't think it is necessary to mention Virtual M
Wez
2011/11/11 00:24:09
nit: This host isn't intrinsically tied to the vir
Wez
2011/11/11 00:33:00
The paths are Posix-friendly, and might cause issu
Lambros
2011/11/15 23:27:36
Fixed comment.
Lambros
2011/11/15 23:27:36
Windows will need a different config-file location
| |
7 | |
8 #include <stdlib.h> | |
9 | |
10 #include <iostream> | |
Sergey Ulanov
2011/11/11 00:00:43
is this used anywhere?
Lambros
2011/11/15 23:27:36
Nope. Removed.
| |
11 #include <string> | |
12 | |
13 #include "base/at_exit.h" | |
14 #include "base/bind.h" | |
15 #include "base/callback.h" | |
16 #include "base/command_line.h" | |
17 #include "base/file_path.h" | |
18 #include "base/file_util.h" | |
19 #include "base/logging.h" | |
20 #include "base/message_loop.h" | |
21 #include "base/threading/thread.h" | |
22 #include "build/build_config.h" | |
23 #include "crypto/nss_util.h" | |
24 #include "remoting/base/constants.h" | |
25 #include "remoting/host/chromoting_host.h" | |
26 #include "remoting/host/chromoting_host_context.h" | |
27 #include "remoting/host/desktop_environment.h" | |
28 #include "remoting/host/event_executor.h" | |
29 #include "remoting/host/heartbeat_sender.h" | |
30 #include "remoting/host/host_config.h" | |
31 #include "remoting/host/json_host_config.h" | |
32 #include "remoting/host/self_access_verifier.h" | |
33 | |
34 #if defined(TOOLKIT_USES_GTK) | |
35 #include "ui/gfx/gtk_util.h" | |
36 #endif | |
37 | |
38 using remoting::ChromotingHost; | |
Sergey Ulanov
2011/11/11 00:00:43
Why not put this code in the remoting namespace? T
Lambros
2011/11/15 23:27:36
Done.
| |
39 using remoting::DesktopEnvironment; | |
40 using remoting::kChromotingTokenDefaultServiceName; | |
41 using remoting::kXmppAuthServiceConfigPath; | |
42 using remoting::kXmppAuthTokenConfigPath; | |
43 using remoting::kXmppLoginConfigPath; | |
Wez
2011/11/11 00:24:09
The names of these are confusing; "path" implies t
Lambros
2011/11/15 23:27:36
I didn't choose those names - they were already de
| |
44 using remoting::protocol::CandidateSessionConfig; | |
45 using remoting::protocol::ChannelConfig; | |
46 | |
47 const char kAuthConfigSwitchName[] = "auth-config"; | |
48 const char kHostConfigSwitchName[] = "host-config"; | |
49 const FilePath::CharType kDefaultConfigDir[] = | |
50 FILE_PATH_LITERAL(".config/chrome-remote-desktop"); | |
51 const FilePath::CharType kDefaultAuthConfigFile[] = | |
52 FILE_PATH_LITERAL("auth.json"); | |
53 const FilePath::CharType kDefaultHostConfigFile[] = | |
54 FILE_PATH_LITERAL("host.json"); | |
Wez
2011/11/11 00:24:09
nit: Add a comment preceding these definitions to
Lambros
2011/11/15 23:27:36
Done.
| |
55 | |
56 class Me2MeHost { | |
Sergey Ulanov
2011/11/11 00:00:43
I suggest that we call it simply HostProcess or so
Wez
2011/11/11 00:33:00
SGTM
Lambros
2011/11/15 23:27:36
Done.
| |
57 public: | |
58 Me2MeHost() {} | |
59 | |
60 int Run() { | |
61 // |message_loop| is declared early so that any code we call into which | |
62 // requires a current message-loop won't complain. | |
63 // It needs to be a UI message loop to keep runloops spinning on the Mac. | |
Wez
2011/11/11 00:24:09
This code isn't built for Mac right now, so do we
Lambros
2011/11/15 23:27:36
Without this, the host starts and immediately shut
Wez
2011/11/16 22:26:14
You mean you're not sure why we need a UI message-
| |
64 MessageLoop message_loop(MessageLoop::TYPE_UI); | |
65 | |
66 remoting::ChromotingHostContext context( | |
67 base::MessageLoopProxy::current()); | |
68 context.Start(); | |
69 | |
70 base::Thread file_io_thread("FileIO"); | |
71 file_io_thread.Start(); | |
72 | |
73 scoped_refptr<remoting::JsonHostConfig> host_config = | |
74 new remoting::JsonHostConfig( | |
75 host_config_path_, file_io_thread.message_loop_proxy()); | |
76 scoped_refptr<remoting::JsonHostConfig> auth_config = | |
77 new remoting::JsonHostConfig( | |
78 auth_config_path_, file_io_thread.message_loop_proxy()); | |
79 | |
80 std::string failed_path; | |
81 if (!host_config->Read()) { | |
82 failed_path = host_config_path_.value(); | |
83 } else if (!auth_config->Read()) { | |
84 failed_path = auth_config_path_.value(); | |
85 } | |
86 if (!failed_path.empty()) { | |
87 LOG(ERROR) << "Failed to read configuration file " << failed_path; | |
88 context.Stop(); | |
89 return 1; | |
90 } | |
91 | |
92 // Copy the needed keys from |auth_config| into |host_config|. | |
93 std::string value; | |
94 auth_config->GetString(kXmppAuthTokenConfigPath, &value); | |
Sergey Ulanov
2011/11/11 00:00:43
This looks like a hack to me. Since auth and host
Lambros
2011/11/15 23:27:36
I'm still working out how we can do this. There a
Wez
2011/11/16 22:26:14
I think it's reasonable for the Host to be configu
| |
95 host_config->SetString(kXmppAuthTokenConfigPath, value); | |
96 auth_config->GetString(kXmppLoginConfigPath, &value); | |
97 host_config->SetString(kXmppLoginConfigPath, value); | |
Wez
2011/11/11 00:24:09
Past this point |auth_config| isn't used, I don't
Lambros
2011/11/15 23:27:36
Done.
| |
98 | |
99 // For the Me2Me host, we assume we always use the ClientLogin token for | |
100 // chromiumsync because we do not have an HTTP stack with which we can | |
101 // easily request an OAuth2 access token even if we had a RefreshToken for | |
102 // the account. | |
103 host_config->SetString(kXmppAuthServiceConfigPath, | |
104 kChromotingTokenDefaultServiceName); | |
105 | |
106 // Initialize AccessVerifier. | |
107 scoped_ptr<remoting::AccessVerifier> access_verifier; | |
Wez
2011/11/11 00:24:09
Why do we need this separate reference for the acc
Lambros
2011/11/15 23:27:36
We don't, it was an artifact of copying remoting_s
| |
108 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender; | |
Wez
2011/11/11 00:24:09
Define this further down, where it is created. If
Lambros
2011/11/15 23:27:36
Done. Probably was an artifact of the way remotin
| |
109 scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier( | |
110 new remoting::SelfAccessVerifier()); | |
111 if (!self_access_verifier->Init(host_config)) | |
112 return 1; | |
Wez
2011/11/11 00:24:09
Wot no error message? ;)
Lambros
2011/11/15 23:27:36
The Init() method logs if there's an error, so the
Wez
2011/11/16 22:26:14
Yuk. We should move that logging out and let the
| |
113 access_verifier.reset(self_access_verifier.release()); | |
114 | |
115 // Construct a chromoting host. | |
Wez
2011/11/11 00:24:09
nit: the API is Create(), so perhaps "Create the D
Lambros
2011/11/15 23:27:36
Done.
| |
116 scoped_ptr<DesktopEnvironment> desktop_environment( | |
117 DesktopEnvironment::Create(&context)); | |
118 | |
119 host_ = ChromotingHost::Create(&context, host_config, | |
120 desktop_environment.get(), | |
121 access_verifier.release(), false); | |
122 | |
123 if (protocol_config_.get()) { | |
124 host_->set_protocol_config(protocol_config_.release()); | |
Wez
2011/11/11 00:24:09
Don't think we ever use this.
Lambros
2011/11/15 23:27:36
Done (removed all protocol_config stuff).
| |
125 } | |
126 | |
127 // Initialize HeartbeatSender. | |
128 heartbeat_sender.reset( | |
129 new remoting::HeartbeatSender(context.network_message_loop(), | |
130 host_config)); | |
131 if (!heartbeat_sender->Init()) | |
132 return 1; | |
133 host_->AddStatusObserver(heartbeat_sender.get()); | |
134 | |
135 // Let the chromoting host run until the shutdown task is executed. | |
Wez
2011/11/11 00:24:09
nit: "Run the ChromotingHost until the shutdown ta
Lambros
2011/11/15 23:27:36
Done.
| |
136 host_->Start(); | |
137 message_loop.MessageLoop::Run(); | |
138 | |
139 // And then stop the chromoting context. | |
140 context.Stop(); | |
141 file_io_thread.Stop(); | |
142 | |
143 host_ = NULL; | |
144 | |
145 return 0; | |
146 } | |
147 | |
148 void set_auth_config_path(const FilePath& config_path) { | |
149 auth_config_path_ = config_path; | |
150 } | |
151 | |
152 void set_host_config_path(const FilePath& config_path) { | |
153 host_config_path_ = config_path; | |
154 } | |
155 | |
156 void set_protocol_config(CandidateSessionConfig* protocol_config) { | |
Wez
2011/11/11 00:24:09
Don't think we ever use this?
Lambros
2011/11/15 23:27:36
Done.
| |
157 protocol_config_.reset(protocol_config); | |
158 } | |
159 | |
160 private: | |
161 FilePath auth_config_path_; | |
162 FilePath host_config_path_; | |
163 | |
164 scoped_ptr<CandidateSessionConfig> protocol_config_; | |
Wez
2011/11/11 00:24:09
I don't think we ever use this?
Lambros
2011/11/15 23:27:36
Done.
| |
165 | |
166 scoped_refptr<ChromotingHost> host_; | |
167 }; | |
168 | |
169 int main(int argc, char** argv) { | |
170 CommandLine::Init(argc, argv); | |
171 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
172 | |
173 base::AtExitManager exit_manager; | |
174 crypto::EnsureNSPRInit(); | |
175 | |
176 #if defined(TOOLKIT_USES_GTK) | |
177 gfx::GtkInitFromCommandLine(*cmd_line); | |
Wez
2011/11/11 00:24:09
nit: Add a comment to explain why we need this, an
Lambros
2011/11/15 23:27:36
I've explained GtkInit and AtExitManager, but I do
Wez
2011/11/16 22:26:14
EnsureNSPRInit() starts the Netscape Portable Runt
Lambros
2011/11/17 01:47:07
The (LazyInstance-created) NSSInitSingleton ctor d
Wez
2011/11/17 02:19:28
The main browser process doesn't run a sandbox, so
| |
178 #endif // TOOLKIT_USES_GTK | |
179 | |
180 Me2MeHost me2me_host; | |
181 | |
182 FilePath default_config_dir = | |
183 file_util::GetHomeDir().Append(kDefaultConfigDir); | |
184 | |
185 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | |
186 me2me_host.set_auth_config_path( | |
187 cmd_line->GetSwitchValuePath(kAuthConfigSwitchName)); | |
188 } else { | |
189 me2me_host.set_auth_config_path( | |
190 default_config_dir.Append(kDefaultAuthConfigFile)); | |
Wez
2011/11/11 00:24:09
nit: Default the config dir in Me2MeHost's ctor?
Lambros
2011/11/15 23:27:36
Nah, there's no need for a member here. The defau
| |
191 } | |
192 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | |
193 me2me_host.set_host_config_path( | |
194 cmd_line->GetSwitchValuePath(kHostConfigSwitchName)); | |
195 } else { | |
196 me2me_host.set_host_config_path( | |
197 default_config_dir.Append(kDefaultHostConfigFile)); | |
Wez
2011/11/11 00:24:09
nit: as above?
| |
198 } | |
Wez
2011/11/11 00:24:09
nit: Consider adding a comment before default_conf
Lambros
2011/11/15 23:27:36
Added ProcessCommandLine() method. Hopefully that
| |
199 | |
200 return me2me_host.Run(); | |
201 } | |
OLD | NEW |