Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/sync/notifier/sync_notifier_factory.cc

Issue 6621062: Refactor sync notifier out of sync api. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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,
22 uint16 default_port) {
23 std::string::size_type colon_index = host_port_str.find(':');
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() {
42 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.
43
44 // Contains options specific to how sync clients send and listen to
45 // jingle notifications.
46 notifier::NotifierOptions* notifier_options =
47 new notifier::NotifierOptions();
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 (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.
86 }
87 } // namespace
88
89 SyncNotifier* SyncNotifierFactory::CreateSyncNotifier() {
90 return CreateDefaultSyncNotifier();
91 }
92
93 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698