OLD | NEW |
(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 #include "chrome/browser/sync/notifier/sync_notifier_factory.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/sync/notifier/sync_notifier.h" |
| 13 #include "chrome/browser/sync/notifier/sync_notifier_impl.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "jingle/notifier/base/notifier_options.h" |
| 16 #include "jingle/notifier/communicator/const_communicator.h" |
| 17 #include "net/base/host_port_pair.h" |
| 18 |
| 19 namespace sync_notifier { |
| 20 namespace { |
| 21 |
| 22 // TODO(akalin): Figure out whether this should be a method of |
| 23 // HostPortPair. |
| 24 net::HostPortPair StringToHostPortPair(const std::string& host_port_str, |
| 25 uint16 default_port) { |
| 26 std::string::size_type colon_index = host_port_str.find(':'); |
| 27 if (colon_index == std::string::npos) { |
| 28 return net::HostPortPair(host_port_str, default_port); |
| 29 } |
| 30 |
| 31 std::string host = host_port_str.substr(0, colon_index); |
| 32 std::string port_str = host_port_str.substr(colon_index + 1); |
| 33 int port = default_port; |
| 34 if (!base::StringToInt(port_str, &port) || |
| 35 (port <= 0) || (port > kuint16max)) { |
| 36 LOG(WARNING) << "Could not parse valid port from " << port_str |
| 37 << "; using port " << default_port; |
| 38 return net::HostPortPair(host, default_port); |
| 39 } |
| 40 |
| 41 return net::HostPortPair(host, port); |
| 42 } |
| 43 |
| 44 SyncNotifier* CreateDefaultSyncNotifier(const CommandLine& command_line) { |
| 45 // Contains options specific to how sync clients send and listen to |
| 46 // jingle notifications. |
| 47 notifier::NotifierOptions notifier_options; |
| 48 |
| 49 // Override the notification server host from the command-line, if provided. |
| 50 if (command_line.HasSwitch(switches::kSyncNotificationHost)) { |
| 51 std::string value(command_line.GetSwitchValueASCII( |
| 52 switches::kSyncNotificationHost)); |
| 53 if (!value.empty()) { |
| 54 notifier_options.xmpp_host_port = |
| 55 StringToHostPortPair(value, notifier::kDefaultXmppPort); |
| 56 } |
| 57 VLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() |
| 58 << " for test sync notification server."; |
| 59 } |
| 60 |
| 61 notifier_options.try_ssltcp_first = |
| 62 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); |
| 63 if (notifier_options.try_ssltcp_first) |
| 64 VLOG(1) << "Trying SSL/TCP port before XMPP port for notifications."; |
| 65 |
| 66 notifier_options.invalidate_xmpp_login = |
| 67 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); |
| 68 if (notifier_options.invalidate_xmpp_login) { |
| 69 VLOG(1) << "Invalidating sync XMPP login."; |
| 70 } |
| 71 |
| 72 notifier_options.allow_insecure_connection = |
| 73 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); |
| 74 if (notifier_options.allow_insecure_connection) { |
| 75 VLOG(1) << "Allowing insecure XMPP connections."; |
| 76 } |
| 77 |
| 78 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { |
| 79 const std::string notification_method_str( |
| 80 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); |
| 81 notifier_options.notification_method = |
| 82 notifier::StringToNotificationMethod(notification_method_str); |
| 83 } |
| 84 |
| 85 return new SyncNotifierImpl(notifier_options); |
| 86 } |
| 87 } // namespace |
| 88 |
| 89 SyncNotifierFactory::SyncNotifierFactory() { |
| 90 } |
| 91 |
| 92 SyncNotifierFactory::~SyncNotifierFactory() { |
| 93 } |
| 94 |
| 95 SyncNotifier* SyncNotifierFactory::CreateSyncNotifier( |
| 96 const CommandLine& command_line) { |
| 97 return CreateDefaultSyncNotifier(command_line); |
| 98 } |
| 99 } // namespace sync_notifier |
OLD | NEW |