OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const char kHostConfigSwitchName[] = "host-config"; | 61 const char kHostConfigSwitchName[] = "host-config"; |
62 | 62 |
63 const FilePath::CharType kDefaultAuthConfigFile[] = | 63 const FilePath::CharType kDefaultAuthConfigFile[] = |
64 FILE_PATH_LITERAL("auth.json"); | 64 FILE_PATH_LITERAL("auth.json"); |
65 const FilePath::CharType kDefaultHostConfigFile[] = | 65 const FilePath::CharType kDefaultHostConfigFile[] = |
66 FILE_PATH_LITERAL("host.json"); | 66 FILE_PATH_LITERAL("host.json"); |
67 | 67 |
68 const int kMinPortNumber = 12400; | 68 const int kMinPortNumber = 12400; |
69 const int kMaxPortNumber = 12409; | 69 const int kMaxPortNumber = 12409; |
70 | 70 |
| 71 const char kUnofficialOAuth2ClientId[] = |
| 72 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; |
| 73 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; |
| 74 |
| 75 const char kOfficialOAuth2ClientId[] = |
| 76 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; |
| 77 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; |
| 78 |
71 } // namespace | 79 } // namespace |
72 | 80 |
73 namespace remoting { | 81 namespace remoting { |
74 | 82 |
75 class HostProcess | 83 class HostProcess |
76 : public HeartbeatSender::Listener { | 84 : public HeartbeatSender::Listener { |
77 public: | 85 public: |
78 HostProcess() | 86 HostProcess() |
79 : message_loop_(MessageLoop::TYPE_UI), | 87 : message_loop_(MessageLoop::TYPE_UI), |
| 88 #ifdef OFFICIAL_BUILD |
| 89 oauth_use_official_client_id_(true), |
| 90 #else |
| 91 oauth_use_official_client_id_(false), |
| 92 #endif |
80 allow_nat_traversal_(true), | 93 allow_nat_traversal_(true), |
81 restarting_(false), | 94 restarting_(false), |
82 shutting_down_(false), | 95 shutting_down_(false), |
83 exit_code_(kSuccessExitCode) { | 96 exit_code_(kSuccessExitCode) { |
84 context_.reset( | 97 context_.reset( |
85 new ChromotingHostContext(message_loop_.message_loop_proxy())); | 98 new ChromotingHostContext(message_loop_.message_loop_proxy())); |
86 context_->Start(); | 99 context_->Start(); |
87 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 100 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
88 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | 101 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( |
89 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | 102 FROM_HERE, base::TimeDelta::FromSeconds(2), this, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 253 |
241 // Use an XMPP connection to the Talk network for session signalling. | 254 // Use an XMPP connection to the Talk network for session signalling. |
242 if (!auth_config.GetString(kXmppLoginConfigPath, &xmpp_login_) || | 255 if (!auth_config.GetString(kXmppLoginConfigPath, &xmpp_login_) || |
243 !(auth_config.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || | 256 !(auth_config.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || |
244 auth_config.GetString(kOAuthRefreshTokenConfigPath, | 257 auth_config.GetString(kOAuthRefreshTokenConfigPath, |
245 &oauth_refresh_token_))) { | 258 &oauth_refresh_token_))) { |
246 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 259 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
247 return false; | 260 return false; |
248 } | 261 } |
249 | 262 |
| 263 // It is okay to not have this value and we will use the default value |
| 264 // depending on whether this is an official build or not. |
| 265 // If the client-Id type to use is not specified we default based on |
| 266 // the build type. |
| 267 auth_config.GetBoolean(kOAuthUseOfficialClientIdConfigPath, |
| 268 &oauth_use_official_client_id_); |
| 269 |
250 if (!oauth_refresh_token_.empty()) { | 270 if (!oauth_refresh_token_.empty()) { |
251 xmpp_auth_token_ = ""; // This will be set to the access token later. | 271 xmpp_auth_token_ = ""; // This will be set to the access token later. |
252 xmpp_auth_service_ = "oauth2"; | 272 xmpp_auth_service_ = "oauth2"; |
253 } else if (!auth_config.GetString(kXmppAuthServiceConfigPath, | 273 } else if (!auth_config.GetString(kXmppAuthServiceConfigPath, |
254 &xmpp_auth_service_)) { | 274 &xmpp_auth_service_)) { |
255 // For the me2me host, we default to ClientLogin token for chromiumsync | 275 // For the me2me host, we default to ClientLogin token for chromiumsync |
256 // because earlier versions of the host had no HTTP stack with which to | 276 // because earlier versions of the host had no HTTP stack with which to |
257 // request an OAuth2 access token. | 277 // request an OAuth2 access token. |
258 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; | 278 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
259 } | 279 } |
(...skipping 28 matching lines...) Expand all Loading... |
288 | 308 |
289 if (!signal_strategy_.get()) { | 309 if (!signal_strategy_.get()) { |
290 signal_strategy_.reset( | 310 signal_strategy_.reset( |
291 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login_, | 311 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login_, |
292 xmpp_auth_token_, xmpp_auth_service_)); | 312 xmpp_auth_token_, xmpp_auth_service_)); |
293 | 313 |
294 signaling_connector_.reset( | 314 signaling_connector_.reset( |
295 new SignalingConnector(signal_strategy_.get())); | 315 new SignalingConnector(signal_strategy_.get())); |
296 | 316 |
297 if (!oauth_refresh_token_.empty()) { | 317 if (!oauth_refresh_token_.empty()) { |
| 318 OAuthClientInfo client_info = { |
| 319 kUnofficialOAuth2ClientId, |
| 320 kUnofficialOAuth2ClientSecret |
| 321 }; |
| 322 |
| 323 #ifdef OFFICIAL_BUILD |
| 324 if (oauth_use_official_client_id_) { |
| 325 OAuthClientInfo official_client_info = { |
| 326 kOfficialOAuth2ClientId, |
| 327 kOfficialOAuth2ClientSecret |
| 328 }; |
| 329 |
| 330 client_info = official_client_info; |
| 331 } |
| 332 #endif // OFFICIAL_BUILD |
| 333 |
298 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( | 334 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( |
299 new SignalingConnector::OAuthCredentials( | 335 new SignalingConnector::OAuthCredentials( |
300 xmpp_login_, oauth_refresh_token_)); | 336 xmpp_login_, oauth_refresh_token_, client_info)); |
301 signaling_connector_->EnableOAuth( | 337 signaling_connector_->EnableOAuth( |
302 oauth_credentials.Pass(), | 338 oauth_credentials.Pass(), |
303 base::Bind(&HostProcess::OnOAuthFailed, base::Unretained(this)), | 339 base::Bind(&HostProcess::OnOAuthFailed, base::Unretained(this)), |
304 context_->url_request_context_getter()); | 340 context_->url_request_context_getter()); |
305 } | 341 } |
306 } | 342 } |
307 | 343 |
308 if (!desktop_environment_.get()) { | 344 if (!desktop_environment_.get()) { |
309 desktop_environment_ = | 345 desktop_environment_ = |
310 DesktopEnvironment::CreateForService(context_.get()); | 346 DesktopEnvironment::CreateForService(context_.get()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 FilePath host_config_path_; | 432 FilePath host_config_path_; |
397 | 433 |
398 std::string host_id_; | 434 std::string host_id_; |
399 HostKeyPair key_pair_; | 435 HostKeyPair key_pair_; |
400 protocol::SharedSecretHash host_secret_hash_; | 436 protocol::SharedSecretHash host_secret_hash_; |
401 std::string xmpp_login_; | 437 std::string xmpp_login_; |
402 std::string xmpp_auth_token_; | 438 std::string xmpp_auth_token_; |
403 std::string xmpp_auth_service_; | 439 std::string xmpp_auth_service_; |
404 | 440 |
405 std::string oauth_refresh_token_; | 441 std::string oauth_refresh_token_; |
| 442 bool oauth_use_official_client_id_; |
406 | 443 |
407 scoped_ptr<policy_hack::NatPolicy> nat_policy_; | 444 scoped_ptr<policy_hack::NatPolicy> nat_policy_; |
408 bool allow_nat_traversal_; | 445 bool allow_nat_traversal_; |
409 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | 446 scoped_ptr<base::files::FilePathWatcher> config_watcher_; |
410 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | 447 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; |
411 | 448 |
412 bool restarting_; | 449 bool restarting_; |
413 bool shutting_down_; | 450 bool shutting_down_; |
414 | 451 |
415 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 452 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 int CALLBACK WinMain(HINSTANCE instance, | 503 int CALLBACK WinMain(HINSTANCE instance, |
467 HINSTANCE previous_instance, | 504 HINSTANCE previous_instance, |
468 LPSTR command_line, | 505 LPSTR command_line, |
469 int show_command) { | 506 int show_command) { |
470 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 507 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
471 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 508 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
472 return main(0, NULL); | 509 return main(0, NULL); |
473 } | 510 } |
474 | 511 |
475 #endif // defined(OS_WIN) | 512 #endif // defined(OS_WIN) |
OLD | NEW |