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

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: Split Login method and remove notification logic from syncapi. 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(const CommandLine& command_line) {
42 // Contains options specific to how sync clients send and listen to
43 // jingle notifications.
44 notifier::NotifierOptions* notifier_options =
akalin 2011/03/11 04:17:14 i think it's fine to pass this by value (i.e., not
Agrawal 2011/03/11 21:42:20 Ok. Now I am creating notifier_options_ on the sta
45 new notifier::NotifierOptions();
46
47 // Override the notification server host from the command-line, if provided.
48 if (command_line.HasSwitch(switches::kSyncNotificationHost)) {
49 std::string value(command_line.GetSwitchValueASCII(
50 switches::kSyncNotificationHost));
51 if (!value.empty()) {
52 notifier_options->xmpp_host_port =
53 StringToHostPortPair(value, notifier::kDefaultXmppPort);
54 }
55 VLOG(1) << "Using " << notifier_options->xmpp_host_port.ToString()
56 << " for test sync notification server.";
57 }
58
59 notifier_options->try_ssltcp_first =
60 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp);
61 if (notifier_options->try_ssltcp_first)
62 VLOG(1) << "Trying SSL/TCP port before XMPP port for notifications.";
63
64 notifier_options->invalidate_xmpp_login =
65 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin);
66 if (notifier_options->invalidate_xmpp_login) {
67 VLOG(1) << "Invalidating sync XMPP login.";
68 }
69
70 notifier_options->allow_insecure_connection =
71 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection);
72 if (notifier_options->allow_insecure_connection) {
73 VLOG(1) << "Allowing insecure XMPP connections.";
74 }
75
76 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) {
77 const std::string notification_method_str(
78 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod));
79 notifier_options->notification_method =
80 notifier::StringToNotificationMethod(notification_method_str);
81 }
82
83 return new SyncNotifierImpl(notifier_options);
84 }
85 } // namespace
86
87 SyncNotifier* SyncNotifierFactory::CreateSyncNotifier(
88 const CommandLine& command_line) {
89 return CreateDefaultSyncNotifier(command_line);
90 }
91
92 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698