Chromium Code Reviews| 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..2ba7879b5642f516a588c518c3b9efab0eb37c56 |
| --- /dev/null |
| +++ b/chrome/browser/sync/notifier/sync_notifier_factory.cc |
| @@ -0,0 +1,93 @@ |
| +// 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 "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" |
| + |
| +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 = *CommandLine::ForCurrentProcess(); |
|
akalin
2011/03/08 02:48:30
It would help testability to make command_line be
Agrawal
2011/03/08 23:07:28
Done.
|
| + |
| + // Contains options specific to how sync clients send and listen to |
| + // jingle notifications. |
| + notifier::NotifierOptions* notifier_options = |
| + new notifier::NotifierOptions(); |
| + |
| + // 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 (SyncNotifier*) new SyncNotifierImpl(notifier_options); |
|
akalin
2011/03/08 02:48:30
no need for this cast
Agrawal
2011/03/08 23:07:28
Done.
|
| +} |
| +} // namespace |
| + |
| +SyncNotifier* SyncNotifierFactory::CreateSyncNotifier() { |
| + return CreateDefaultSyncNotifier(); |
| +} |
| + |
| +} // namespace sync_notifier |