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 3 // found in the LICENSE file. 4 5 #include "remoting/host/service_urls.h" 6 7 #include "base/command_line.h" 8 #include "base/logging.h" 9 10 namespace { 11 12 // Configurable service data. 13 const char kDirectoryBaseUrl[] = "https://www.googleapis.com/chromoting/v1"; 14 const char kXmppServerAddress[] = "talk.google.com:5222"; 15 const bool kXmppServerUseTls = true; 16 const char kDirectoryBotJid[] = "remoting (at) bot.talk.google.com"; 17 18 // Command line switches. 19 const char kDirectoryBaseUrlSwitch[] = "directory-base-url"; 20 const char kXmppServerAddressSwitch[] = "xmpp-server-address"; 21 const char kXmppServerDisableTlsSwitch[] = "disable-xmpp-server-tls"; 22 const char kDirectoryBotJidSwitch[] = "directory-bot-jid"; 23 24 // Non-configurable service paths. 25 const char kDirectoryHostsSuffix[] = "/@me/hosts/"; 26 27 } // namespace 28 29 namespace remoting { 30 31 ServiceUrls::ServiceUrls() 32 : directory_base_url_(kDirectoryBaseUrl), 33 xmpp_server_address_(kXmppServerAddress), 34 xmpp_server_use_tls_(kXmppServerUseTls), 35 directory_bot_jid_(kDirectoryBotJid) { 36 #if !defined(NDEBUG) 37 // Allow debug builds to override urls via command line. 38 CommandLine* command_line = CommandLine::ForCurrentProcess(); 39 CHECK(command_line); 40 if (command_line->HasSwitch(kDirectoryBaseUrlSwitch)) { 41 directory_base_url_ = command_line->GetSwitchValueASCII( 42 kDirectoryBaseUrlSwitch); 43 } 44 if (command_line->HasSwitch(kXmppServerAddressSwitch)) { 45 xmpp_server_address_ = command_line->GetSwitchValueASCII( 46 kXmppServerAddressSwitch); 47 } 48 if (command_line->HasSwitch(kXmppServerDisableTlsSwitch)) { 49 xmpp_server_use_tls_ = false; 50 } 51 if (command_line->HasSwitch(kDirectoryBotJidSwitch)) { 52 directory_bot_jid_ = command_line->GetSwitchValueASCII( 53 kDirectoryBotJidSwitch); 54 } 55 #endif // !defined(NDEBUG) 56 57 directory_hosts_url_ = directory_base_url_ + kDirectoryHostsSuffix; 58 } 59 60 ServiceUrls::~ServiceUrls() { 61 } 62 63 ServiceUrls* remoting::ServiceUrls::GetInstance() { 64 return Singleton<ServiceUrls>::get(); 65 } 66 67 const std::string& ServiceUrls::directory_base_url() const { 68 return directory_base_url_; 69 } 70 71 const std::string& ServiceUrls::directory_hosts_url() const { 72 return directory_hosts_url_; 73 } 74 75 const std::string& ServiceUrls::xmpp_server_address() const { 76 return xmpp_server_address_; 77 } 78 79 bool ServiceUrls::xmpp_server_use_tls() const { 80 return xmpp_server_use_tls_; 81 } 82 83 const std::string& ServiceUrls::directory_bot_jid() const { 84 return directory_bot_jid_; 85 } 86 87 } // namespace remoting 88