| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "remoting/base/service_urls.h" | 5 #include "remoting/base/service_urls.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "google_apis/google_api_keys.h" |
| 9 | 10 |
| 10 // Configurable service data. | 11 // Configurable service data. |
| 11 const char kDirectoryBaseUrl[] = "https://www.googleapis.com/chromoting/v1"; | 12 const char kDirectoryBaseUrl[] = "https://www.googleapis.com/chromoting/v1"; |
| 12 const char kGcdBaseUrl[] = "https://www.googleapis.com/clouddevices/v1"; | 13 const char kGcdBaseUrl[] = "https://www.googleapis.com/clouddevices/v1"; |
| 13 const char kXmppServerAddress[] = "talk.google.com:443"; | 14 const char kXmppServerAddress[] = "talk.google.com:443"; |
| 14 const char kXmppServerAddressForMe2MeHost[] = "talk.google.com:5222"; | 15 const char kXmppServerAddressForMe2MeHost[] = "talk.google.com:5222"; |
| 15 const bool kXmppServerUseTls = true; | 16 const bool kXmppServerUseTls = true; |
| 16 const char kDirectoryBotJid[] = "remoting@bot.talk.google.com"; | 17 const char kDirectoryBotJid[] = "remoting@bot.talk.google.com"; |
| 17 const char kGcdJid[] = "clouddevices.gserviceaccount.com"; | 18 const char kGcdJid[] = "clouddevices.gserviceaccount.com"; |
| 19 const char kNetworkTraversalApiUrlBase[] = |
| 20 "https://networktraversal.googleapis.com/v1alpha/iceconfig?key="; |
| 18 | 21 |
| 19 // Command line switches. | 22 // Command line switches. |
| 20 #if !defined(NDEBUG) | 23 #if !defined(NDEBUG) |
| 21 const char kDirectoryBaseUrlSwitch[] = "directory-base-url"; | 24 const char kDirectoryBaseUrlSwitch[] = "directory-base-url"; |
| 22 const char kGcdBaseUrlSwitch[] = "gcd-base-url"; | 25 const char kGcdBaseUrlSwitch[] = "gcd-base-url"; |
| 23 const char kXmppServerAddressSwitch[] = "xmpp-server-address"; | 26 const char kXmppServerAddressSwitch[] = "xmpp-server-address"; |
| 24 const char kXmppServerDisableTlsSwitch[] = "disable-xmpp-server-tls"; | 27 const char kXmppServerDisableTlsSwitch[] = "disable-xmpp-server-tls"; |
| 25 const char kDirectoryBotJidSwitch[] = "directory-bot-jid"; | 28 const char kDirectoryBotJidSwitch[] = "directory-bot-jid"; |
| 26 const char kGcdJidSwitch[] = "gcd-jid"; | 29 const char kGcdJidSwitch[] = "gcd-jid"; |
| 30 const char kIceConfigUrl[] = "ice_config_url"; |
| 27 #endif // !defined(NDEBUG) | 31 #endif // !defined(NDEBUG) |
| 28 | 32 |
| 29 // Non-configurable service paths. | 33 // Non-configurable service paths. |
| 30 const char kDirectoryHostsSuffix[] = "/@me/hosts/"; | 34 const char kDirectoryHostsSuffix[] = "/@me/hosts/"; |
| 31 | 35 |
| 32 namespace remoting { | 36 namespace remoting { |
| 33 | 37 |
| 34 ServiceUrls::ServiceUrls() | 38 ServiceUrls::ServiceUrls() |
| 35 : directory_base_url_(kDirectoryBaseUrl), | 39 : directory_base_url_(kDirectoryBaseUrl), |
| 36 gcd_base_url_(kGcdBaseUrl), | 40 gcd_base_url_(kGcdBaseUrl), |
| 37 xmpp_server_address_(kXmppServerAddress), | 41 xmpp_server_address_(kXmppServerAddress), |
| 38 xmpp_server_address_for_me2me_host_(kXmppServerAddressForMe2MeHost), | 42 xmpp_server_address_for_me2me_host_(kXmppServerAddressForMe2MeHost), |
| 39 xmpp_server_use_tls_(kXmppServerUseTls), | 43 xmpp_server_use_tls_(kXmppServerUseTls), |
| 40 directory_bot_jid_(kDirectoryBotJid), | 44 directory_bot_jid_(kDirectoryBotJid), |
| 41 gcd_jid_(kGcdJid) { | 45 gcd_jid_(kGcdJid), |
| 46 ice_config_url_(kNetworkTraversalApiUrlBase + |
| 47 google_apis::GetRemotingAPIKey()) { |
| 42 #if !defined(NDEBUG) | 48 #if !defined(NDEBUG) |
| 43 // Allow debug builds to override urls via command line. | 49 // Allow debug builds to override urls via command line. |
| 44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 50 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 45 CHECK(command_line); | 51 CHECK(command_line); |
| 46 if (command_line->HasSwitch(kDirectoryBaseUrlSwitch)) { | 52 if (command_line->HasSwitch(kDirectoryBaseUrlSwitch)) { |
| 47 directory_base_url_ = command_line->GetSwitchValueASCII( | 53 directory_base_url_ = command_line->GetSwitchValueASCII( |
| 48 kDirectoryBaseUrlSwitch); | 54 kDirectoryBaseUrlSwitch); |
| 49 } | 55 } |
| 50 if (command_line->HasSwitch(kGcdBaseUrlSwitch)) { | 56 if (command_line->HasSwitch(kGcdBaseUrlSwitch)) { |
| 51 gcd_base_url_ = command_line->GetSwitchValueASCII(kGcdBaseUrlSwitch); | 57 gcd_base_url_ = command_line->GetSwitchValueASCII(kGcdBaseUrlSwitch); |
| 52 } | 58 } |
| 53 if (command_line->HasSwitch(kXmppServerAddressSwitch)) { | 59 if (command_line->HasSwitch(kXmppServerAddressSwitch)) { |
| 54 xmpp_server_address_ = command_line->GetSwitchValueASCII( | 60 xmpp_server_address_ = command_line->GetSwitchValueASCII( |
| 55 kXmppServerAddressSwitch); | 61 kXmppServerAddressSwitch); |
| 56 xmpp_server_address_for_me2me_host_ = xmpp_server_address_; | 62 xmpp_server_address_for_me2me_host_ = xmpp_server_address_; |
| 57 } | 63 } |
| 58 if (command_line->HasSwitch(kXmppServerDisableTlsSwitch)) { | 64 if (command_line->HasSwitch(kXmppServerDisableTlsSwitch)) { |
| 59 xmpp_server_use_tls_ = false; | 65 xmpp_server_use_tls_ = false; |
| 60 } | 66 } |
| 61 if (command_line->HasSwitch(kDirectoryBotJidSwitch)) { | 67 if (command_line->HasSwitch(kDirectoryBotJidSwitch)) { |
| 62 directory_bot_jid_ = command_line->GetSwitchValueASCII( | 68 directory_bot_jid_ = command_line->GetSwitchValueASCII( |
| 63 kDirectoryBotJidSwitch); | 69 kDirectoryBotJidSwitch); |
| 64 } | 70 } |
| 65 if (command_line->HasSwitch(kGcdJidSwitch)) { | 71 if (command_line->HasSwitch(kGcdJidSwitch)) { |
| 66 gcd_jid_ = command_line->GetSwitchValueASCII(kGcdJidSwitch); | 72 gcd_jid_ = command_line->GetSwitchValueASCII(kGcdJidSwitch); |
| 67 } | 73 } |
| 74 if (command_line->HasSwitch(kIceConfigUrl)) { |
| 75 ice_config_url_ = command_line->GetSwitchValueASCII(kIceConfigUrl); |
| 76 } |
| 68 #endif // !defined(NDEBUG) | 77 #endif // !defined(NDEBUG) |
| 69 | 78 |
| 70 directory_hosts_url_ = directory_base_url_ + kDirectoryHostsSuffix; | 79 directory_hosts_url_ = directory_base_url_ + kDirectoryHostsSuffix; |
| 71 } | 80 } |
| 72 | 81 |
| 73 ServiceUrls::~ServiceUrls() { | 82 ServiceUrls::~ServiceUrls() {} |
| 74 } | |
| 75 | 83 |
| 76 ServiceUrls* remoting::ServiceUrls::GetInstance() { | 84 ServiceUrls* remoting::ServiceUrls::GetInstance() { |
| 77 return base::Singleton<ServiceUrls>::get(); | 85 return base::Singleton<ServiceUrls>::get(); |
| 78 } | 86 } |
| 79 | 87 |
| 80 const std::string& ServiceUrls::directory_base_url() const { | |
| 81 return directory_base_url_; | |
| 82 } | |
| 83 | |
| 84 const std::string& ServiceUrls::directory_hosts_url() const { | |
| 85 return directory_hosts_url_; | |
| 86 } | |
| 87 | |
| 88 const std::string& ServiceUrls::gcd_base_url() const { | |
| 89 return gcd_base_url_; | |
| 90 } | |
| 91 | |
| 92 const std::string& ServiceUrls::xmpp_server_address() const { | |
| 93 return xmpp_server_address_; | |
| 94 } | |
| 95 | |
| 96 const std::string& ServiceUrls::xmpp_server_address_for_me2me_host() const { | |
| 97 return xmpp_server_address_for_me2me_host_; | |
| 98 } | |
| 99 | |
| 100 bool ServiceUrls::xmpp_server_use_tls() const { | |
| 101 return xmpp_server_use_tls_; | |
| 102 } | |
| 103 | |
| 104 const std::string& ServiceUrls::directory_bot_jid() const { | |
| 105 return directory_bot_jid_; | |
| 106 } | |
| 107 | |
| 108 const std::string& ServiceUrls::gcd_jid() const { | |
| 109 return directory_bot_jid_; | |
| 110 } | |
| 111 | |
| 112 } // namespace remoting | 88 } // namespace remoting |
| OLD | NEW |