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