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

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

Issue 9956148: Add file thread in MessageHostContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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. 5 // This file implements a standalone host process for Me2Me.
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const int kMaxPortNumber = 12409; 70 const int kMaxPortNumber = 12409;
71 71
72 } // namespace 72 } // namespace
73 73
74 namespace remoting { 74 namespace remoting {
75 75
76 class HostProcess : public OAuthClient::Delegate { 76 class HostProcess : public OAuthClient::Delegate {
77 public: 77 public:
78 HostProcess() 78 HostProcess()
79 : message_loop_(MessageLoop::TYPE_UI), 79 : message_loop_(MessageLoop::TYPE_UI),
80 file_io_thread_("FileIO"),
81 allow_nat_traversal_(true), 80 allow_nat_traversal_(true),
82 restarting_(false) { 81 restarting_(false) {
83 file_io_thread_.StartWithOptions( 82 context_.reset(
84 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 83 new ChromotingHostContext(message_loop_.message_loop_proxy()));
85
86 context_.reset(new ChromotingHostContext(
87 file_io_thread_.message_loop_proxy(),
88 message_loop_.message_loop_proxy()));
89 context_->Start(); 84 context_->Start();
90 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 85 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
91 } 86 }
92 87
93 void InitWithCommandLine(const CommandLine* cmd_line) { 88 void InitWithCommandLine(const CommandLine* cmd_line) {
94 FilePath default_config_dir = remoting::GetConfigDir(); 89 FilePath default_config_dir = remoting::GetConfigDir();
95 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { 90 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
96 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); 91 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
97 } else { 92 } else {
98 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); 93 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile);
99 } 94 }
100 95
101 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 96 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
102 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 97 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
103 } else { 98 } else {
104 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 99 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
105 } 100 }
106 101
107 #if defined(OS_LINUX) 102 #if defined(OS_LINUX)
108 Capturer::EnableXDamage(true); 103 Capturer::EnableXDamage(true);
109 #endif 104 #endif
110 } 105 }
111 106
112 void ConfigUpdated() { 107 void ConfigUpdated() {
113 // The auth tokens can't be updated once the host is running, so we don't 108 // The auth tokens can't be updated once the host is running, so we don't
114 // need to check the pending state, but it's a required parameter. 109 // need to check the pending state, but it's a required parameter.
115 bool tokens_pending; 110 bool tokens_pending;
116 if (LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { 111 if (LoadConfig(&tokens_pending)) {
117 context_->network_message_loop()->PostTask( 112 context_->network_message_loop()->PostTask(
118 FROM_HERE, 113 FROM_HERE,
119 base::Bind(&HostProcess::CreateAuthenticatorFactory, 114 base::Bind(&HostProcess::CreateAuthenticatorFactory,
120 base::Unretained(this))); 115 base::Unretained(this)));
121 } else { 116 } else {
122 LOG(ERROR) << "Invalid configuration."; 117 LOG(ERROR) << "Invalid configuration.";
123 } 118 }
124 } 119 }
125 120
126 #if defined(OS_MACOSX) 121 #if defined(OS_MACOSX)
127 void ListenForConfigChanges() { 122 void ListenForConfigChanges() {
128 remoting::RegisterHupSignalHandler( 123 remoting::RegisterHupSignalHandler(
129 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); 124 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)));
130 } 125 }
131 #endif 126 #endif
132 127
133 void CreateAuthenticatorFactory() { 128 void CreateAuthenticatorFactory() {
134 scoped_ptr<protocol::AuthenticatorFactory> factory( 129 scoped_ptr<protocol::AuthenticatorFactory> factory(
135 new protocol::Me2MeHostAuthenticatorFactory( 130 new protocol::Me2MeHostAuthenticatorFactory(
136 xmpp_login_, key_pair_.GenerateCertificate(), 131 xmpp_login_, key_pair_.GenerateCertificate(),
137 *key_pair_.private_key(), host_secret_hash_)); 132 *key_pair_.private_key(), host_secret_hash_));
138 host_->SetAuthenticatorFactory(factory.Pass()); 133 host_->SetAuthenticatorFactory(factory.Pass());
139 } 134 }
140 135
141 int Run() { 136 int Run() {
142 bool tokens_pending = false; 137 bool tokens_pending = false;
143 if (!LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { 138 if (!LoadConfig(&tokens_pending)) {
144 return kInvalidHostConfigurationExitCode; 139 return kInvalidHostConfigurationExitCode;
145 } 140 }
146 if (tokens_pending) { 141 if (tokens_pending) {
147 // If we have an OAuth refresh token, then XmppSignalStrategy can't 142 // If we have an OAuth refresh token, then XmppSignalStrategy can't
148 // handle it directly, so refresh it asynchronously. A task will be 143 // handle it directly, so refresh it asynchronously. A task will be
149 // posted on the message loop to start watching the NAT policy when 144 // posted on the message loop to start watching the NAT policy when
150 // the access token is available. 145 // the access token is available.
151 // 146 //
152 // TODO(sergeyu): Move this code to SignalingConnector. 147 // TODO(sergeyu): Move this code to SignalingConnector.
153 oauth_client_.Start(oauth_refresh_token_, this, 148 oauth_client_.Start(oauth_refresh_token_, this,
154 message_loop_.message_loop_proxy()); 149 message_loop_.message_loop_proxy());
155 } else { 150 } else {
156 StartWatchingNatPolicy(); 151 StartWatchingNatPolicy();
157 } 152 }
158 153
159 #if defined(OS_MACOSX) 154 #if defined(OS_MACOSX)
160 file_io_thread_.message_loop_proxy()->PostTask( 155 context_->file_message_loop()->PostTask(
161 FROM_HERE, 156 FROM_HERE,
162 base::Bind(&HostProcess::ListenForConfigChanges, 157 base::Bind(&HostProcess::ListenForConfigChanges,
163 base::Unretained(this))); 158 base::Unretained(this)));
164 #endif 159 #endif
165 message_loop_.Run(); 160 message_loop_.Run();
166 161
167 return kSuccessExitCode; 162 return kSuccessExitCode;
168 } 163 }
169 164
170 // Overridden from OAuthClient::Delegate 165 // Overridden from OAuthClient::Delegate
(...skipping 14 matching lines...) Expand all
185 } 180 }
186 } 181 }
187 182
188 virtual void OnOAuthError() OVERRIDE { 183 virtual void OnOAuthError() OVERRIDE {
189 LOG(ERROR) << "OAuth: invalid credentials."; 184 LOG(ERROR) << "OAuth: invalid credentials.";
190 } 185 }
191 186
192 private: 187 private:
193 void StartWatchingNatPolicy() { 188 void StartWatchingNatPolicy() {
194 nat_policy_.reset( 189 nat_policy_.reset(
195 policy_hack::NatPolicy::Create(file_io_thread_.message_loop_proxy())); 190 policy_hack::NatPolicy::Create(
191 context_->file_message_loop()->message_loop_proxy()));
196 nat_policy_->StartWatching( 192 nat_policy_->StartWatching(
197 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); 193 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this)));
198 } 194 }
199 195
200 // Read Host config from disk, returning true if successful. 196 // Read Host config from disk, returning true if successful.
201 bool LoadConfig(base::MessageLoopProxy* io_message_loop, 197 bool LoadConfig(bool* tokens_pending) {
202 bool* tokens_pending) {
203 JsonHostConfig host_config(host_config_path_); 198 JsonHostConfig host_config(host_config_path_);
204 JsonHostConfig auth_config(auth_config_path_); 199 JsonHostConfig auth_config(auth_config_path_);
205 200
206 FilePath failed_path; 201 FilePath failed_path;
207 if (!host_config.Read()) { 202 if (!host_config.Read()) {
208 failed_path = host_config_path_; 203 failed_path = host_config_path_;
209 } else if (!auth_config.Read()) { 204 } else if (!auth_config.Read()) {
210 failed_path = auth_config_path_; 205 failed_path = auth_config_path_;
211 } 206 }
212 if (!failed_path.empty()) { 207 if (!failed_path.empty()) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 331
337 host_ = NULL; 332 host_ = NULL;
338 log_to_server_.reset(); 333 log_to_server_.reset();
339 host_event_logger_.reset(); 334 host_event_logger_.reset();
340 heartbeat_sender_.reset(); 335 heartbeat_sender_.reset();
341 336
342 StartHost(); 337 StartHost();
343 } 338 }
344 339
345 MessageLoop message_loop_; 340 MessageLoop message_loop_;
346 base::Thread file_io_thread_;
347 scoped_ptr<ChromotingHostContext> context_; 341 scoped_ptr<ChromotingHostContext> context_;
348 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 342 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
349 343
350 FilePath auth_config_path_; 344 FilePath auth_config_path_;
351 FilePath host_config_path_; 345 FilePath host_config_path_;
352 346
353 std::string host_id_; 347 std::string host_id_;
354 HostKeyPair key_pair_; 348 HostKeyPair key_pair_;
355 protocol::SharedSecretHash host_secret_hash_; 349 protocol::SharedSecretHash host_secret_hash_;
356 std::string xmpp_login_; 350 std::string xmpp_login_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 int CALLBACK WinMain(HINSTANCE instance, 408 int CALLBACK WinMain(HINSTANCE instance,
415 HINSTANCE previous_instance, 409 HINSTANCE previous_instance,
416 LPSTR command_line, 410 LPSTR command_line,
417 int show_command) { 411 int show_command) {
418 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 412 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
419 // the command line from GetCommandLineW(), so we can safely pass NULL here. 413 // the command line from GetCommandLineW(), so we can safely pass NULL here.
420 return main(0, NULL); 414 return main(0, NULL);
421 } 415 }
422 416
423 #endif 417 #endif
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698