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

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

Issue 8511029: Initial check-in of Linux virtual Me2Me. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address .cc comments. 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 currently
6 // used for the Linux-only Virtual Me2Me build.
7
8 #include <stdlib.h>
9
10 #include <string>
11
12 #include "base/at_exit.h"
13 #include "base/bind.h"
14 #include "base/callback.h"
15 #include "base/command_line.h"
16 #include "base/file_path.h"
17 #include "base/file_util.h"
18 #include "base/logging.h"
19 #include "base/message_loop.h"
20 #include "base/threading/thread.h"
21 #include "build/build_config.h"
22 #include "crypto/nss_util.h"
23 #include "remoting/base/constants.h"
24 #include "remoting/host/chromoting_host.h"
25 #include "remoting/host/chromoting_host_context.h"
26 #include "remoting/host/desktop_environment.h"
27 #include "remoting/host/event_executor.h"
28 #include "remoting/host/heartbeat_sender.h"
29 #include "remoting/host/host_config.h"
30 #include "remoting/host/json_host_config.h"
31 #include "remoting/host/self_access_verifier.h"
32
33 #if defined(TOOLKIT_USES_GTK)
34 #include "ui/gfx/gtk_util.h"
35 #endif
36
37 namespace {
38 // 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 const char kAuthConfigSwitchName[] = "auth-config";
41 const char kHostConfigSwitchName[] = "host-config";
42 const FilePath::CharType kDefaultConfigDir[] =
43 FILE_PATH_LITERAL(".config/chrome-remote-desktop");
44 const FilePath::CharType kDefaultAuthConfigFile[] =
45 FILE_PATH_LITERAL("auth.json");
46 const FilePath::CharType kDefaultHostConfigFile[] =
47 FILE_PATH_LITERAL("host.json");
48 }
49
50 namespace remoting {
51
52 class HostProcess {
53 public:
54 HostProcess() {}
55
56 void InitWithCommandLine(const CommandLine* cmd_line) {
57 FilePath default_config_dir =
58 file_util::GetHomeDir().Append(kDefaultConfigDir);
59
60 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
61 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
62 } else {
63 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile);
64 }
65
66 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
67 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
68 } else {
69 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
70 }
71 }
72
73 int Run() {
74 // |message_loop| is declared early so that any code we call into which
75 // requires a current message-loop won't complain.
76 // It needs to be a UI message loop to keep runloops spinning on the Mac.
77 MessageLoop message_loop(MessageLoop::TYPE_UI);
78
79 remoting::ChromotingHostContext context(base::MessageLoopProxy::current());
80 context.Start();
81
82 base::Thread file_io_thread("FileIO");
83 file_io_thread.Start();
84
85 if (!LoadConfig(file_io_thread.message_loop_proxy())) {
86 context.Stop();
87 return 1;
88 }
89
90 // Initialize AccessVerifier.
91 scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier(
92 new remoting::SelfAccessVerifier());
93 if (!self_access_verifier->Init(host_config_)) {
94 context.Stop();
95 return 1;
96 }
97
98 // Create the DesktopEnvironment and ChromotingHost.
99 scoped_ptr<DesktopEnvironment> desktop_environment(
100 DesktopEnvironment::Create(&context));
101
102 host_ = ChromotingHost::Create(&context, host_config_,
103 desktop_environment.get(),
104 self_access_verifier.release(), false);
105
106 // Initialize HeartbeatSender.
107 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender(
108 new remoting::HeartbeatSender(context.network_message_loop(),
109 host_config_));
110 if (!heartbeat_sender->Init()) {
111 context.Stop();
112 return 1;
113 }
114 host_->AddStatusObserver(heartbeat_sender.get());
115
116 // Run the ChromotingHost until the shutdown task is executed.
117 host_->Start();
118 message_loop.MessageLoop::Run();
119
120 // And then stop the chromoting context.
121 context.Stop();
122 file_io_thread.Stop();
123
124 host_ = NULL;
125
126 return 0;
127 }
128
129 private:
130 // Read Host config from disk, returning true if successful.
131 bool LoadConfig(base::MessageLoopProxy* message_loop_proxy) {
132 host_config_ =
133 new remoting::JsonHostConfig(host_config_path_, message_loop_proxy);
134 scoped_refptr<remoting::JsonHostConfig> auth_config =
135 new remoting::JsonHostConfig(auth_config_path_, message_loop_proxy);
136
137 std::string failed_path;
138 if (!host_config_->Read()) {
139 failed_path = host_config_path_.value();
140 } else if (!auth_config->Read()) {
141 failed_path = auth_config_path_.value();
142 }
143 if (!failed_path.empty()) {
144 LOG(ERROR) << "Failed to read configuration file " << failed_path;
145 return false;
146 }
147
148 // Copy the needed keys from |auth_config| into |host_config|.
149 std::string value;
150 auth_config->GetString(kXmppAuthTokenConfigPath, &value);
151 host_config_->SetString(kXmppAuthTokenConfigPath, value);
152 auth_config->GetString(kXmppLoginConfigPath, &value);
153 host_config_->SetString(kXmppLoginConfigPath, value);
154
155 // For the Me2Me host, we assume we always use the ClientLogin token for
156 // chromiumsync because we do not have an HTTP stack with which we can
157 // easily request an OAuth2 access token even if we had a RefreshToken for
158 // the account.
159 host_config_->SetString(kXmppAuthServiceConfigPath,
160 kChromotingTokenDefaultServiceName);
161 return true;
162 }
163
164 FilePath auth_config_path_;
165 FilePath host_config_path_;
166
167 scoped_refptr<remoting::JsonHostConfig> host_config_;
168
169 scoped_refptr<ChromotingHost> host_;
170 };
171
172 } // namespace remoting
173
174 int main(int argc, char** argv) {
175 CommandLine::Init(argc, argv);
176
177 // This object instance is required by Chrome code (for example,
178 // LazyInstance, MessageLoop).
179 base::AtExitManager exit_manager;
180
181 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
182
183 #if defined(TOOLKIT_USES_GTK)
184 // Required for any calls into GTK functions, such as the Disconnect and
185 // Continue windows, though these should not be used for the Me2Me case
186 // (crbug.com/104377).
187 gfx::GtkInitFromCommandLine(*cmd_line);
188 #endif // TOOLKIT_USES_GTK
189
190 remoting::HostProcess me2me_host;
191 me2me_host.InitWithCommandLine(cmd_line);
192
193 return me2me_host.Run();
194 }
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