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

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

Issue 8469013: Add remoting_me2me_host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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.
7
8 #include <stdlib.h>
9
10 #include <iostream>
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;
39 using remoting::DesktopEnvironment;
40 using remoting::kChromotingTokenDefaultServiceName;
41 using remoting::kXmppAuthServiceConfigPath;
42 using remoting::kXmppAuthTokenConfigPath;
43 using remoting::kXmppLoginConfigPath;
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");
55
56 class Me2MeHost {
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.
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);
95 host_config->SetString(kXmppAuthTokenConfigPath, value);
96 auth_config->GetString(kXmppLoginConfigPath, &value);
97 host_config->SetString(kXmppLoginConfigPath, value);
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;
108 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender;
109 scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier(
110 new remoting::SelfAccessVerifier());
111 if (!self_access_verifier->Init(host_config))
112 return 1;
113 access_verifier.reset(self_access_verifier.release());
114
115 // Construct a chromoting host.
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());
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.
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) {
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_;
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);
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));
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));
198 }
199
200 return me2me_host.Run();
201 }
OLDNEW
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698