Index: chrome/browser/sync/notifier/sync_notifier_factory.cc |
diff --git a/chrome/browser/sync/notifier/sync_notifier_factory.cc b/chrome/browser/sync/notifier/sync_notifier_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6dd38b2913d3fab2a9273a5d2cf6757746735bd1 |
--- /dev/null |
+++ b/chrome/browser/sync/notifier/sync_notifier_factory.cc |
@@ -0,0 +1,99 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/notifier/sync_notifier_factory.h" |
+ |
+#include <string> |
+ |
+#include "base/command_line.h" |
+#include "base/string_number_conversions.h" |
+#include "base/string_util.h" |
+#include "chrome/browser/sync/notifier/sync_notifier.h" |
+#include "chrome/browser/sync/notifier/sync_notifier_impl.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "jingle/notifier/base/notifier_options.h" |
+#include "jingle/notifier/communicator/const_communicator.h" |
+#include "net/base/host_port_pair.h" |
+ |
+namespace sync_notifier { |
+namespace { |
+ |
+// TODO(akalin): Figure out whether this should be a method of |
+// HostPortPair. |
+net::HostPortPair StringToHostPortPair(const std::string& host_port_str, |
+ uint16 default_port) { |
+ std::string::size_type colon_index = host_port_str.find(':'); |
+ if (colon_index == std::string::npos) { |
+ return net::HostPortPair(host_port_str, default_port); |
+ } |
+ |
+ std::string host = host_port_str.substr(0, colon_index); |
+ std::string port_str = host_port_str.substr(colon_index + 1); |
+ int port = default_port; |
+ if (!base::StringToInt(port_str, &port) || |
+ (port <= 0) || (port > kuint16max)) { |
+ LOG(WARNING) << "Could not parse valid port from " << port_str |
+ << "; using port " << default_port; |
+ return net::HostPortPair(host, default_port); |
+ } |
+ |
+ return net::HostPortPair(host, port); |
+} |
+ |
+SyncNotifier* CreateDefaultSyncNotifier(const CommandLine& command_line) { |
+ // Contains options specific to how sync clients send and listen to |
+ // jingle notifications. |
+ notifier::NotifierOptions notifier_options; |
+ |
+ // Override the notification server host from the command-line, if provided. |
+ if (command_line.HasSwitch(switches::kSyncNotificationHost)) { |
+ std::string value(command_line.GetSwitchValueASCII( |
+ switches::kSyncNotificationHost)); |
+ if (!value.empty()) { |
+ notifier_options.xmpp_host_port = |
+ StringToHostPortPair(value, notifier::kDefaultXmppPort); |
+ } |
+ VLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() |
+ << " for test sync notification server."; |
+ } |
+ |
+ notifier_options.try_ssltcp_first = |
+ command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); |
+ if (notifier_options.try_ssltcp_first) |
+ VLOG(1) << "Trying SSL/TCP port before XMPP port for notifications."; |
+ |
+ notifier_options.invalidate_xmpp_login = |
+ command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); |
+ if (notifier_options.invalidate_xmpp_login) { |
+ VLOG(1) << "Invalidating sync XMPP login."; |
+ } |
+ |
+ notifier_options.allow_insecure_connection = |
+ command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); |
+ if (notifier_options.allow_insecure_connection) { |
+ VLOG(1) << "Allowing insecure XMPP connections."; |
+ } |
+ |
+ if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { |
+ const std::string notification_method_str( |
+ command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); |
+ notifier_options.notification_method = |
+ notifier::StringToNotificationMethod(notification_method_str); |
+ } |
+ |
+ return new SyncNotifierImpl(notifier_options); |
+} |
+} // namespace |
+ |
+SyncNotifierFactory::SyncNotifierFactory() { |
+} |
+ |
+SyncNotifierFactory::~SyncNotifierFactory() { |
+} |
+ |
+SyncNotifier* SyncNotifierFactory::CreateSyncNotifier( |
+ const CommandLine& command_line) { |
+ return CreateDefaultSyncNotifier(command_line); |
+} |
+} // namespace sync_notifier |