| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/invalidation/invalidation_service_util.h" | 5 #include "components/invalidation/invalidation_service_util.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "components/invalidation/invalidation_switches.h" | 11 #include "components/invalidation/invalidation_switches.h" |
| 12 | 12 |
| 13 namespace invalidation { | 13 namespace invalidation { |
| 14 | 14 |
| 15 notifier::NotifierOptions ParseNotifierOptions( | 15 notifier::NotifierOptions ParseNotifierOptions( |
| 16 const CommandLine& command_line) { | 16 const CommandLine& command_line) { |
| 17 notifier::NotifierOptions notifier_options; | 17 notifier::NotifierOptions notifier_options; |
| 18 | 18 |
| 19 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { | 19 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { |
| 20 notifier_options.xmpp_host_port = | 20 notifier_options.xmpp_host_port = |
| 21 net::HostPortPair::FromString( | 21 net::HostPortPair::FromString( |
| 22 command_line.GetSwitchValueASCII( | 22 command_line.GetSwitchValueASCII( |
| 23 switches::kSyncNotificationHostPort)); | 23 switches::kSyncNotificationHostPort)); |
| 24 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() | 24 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() |
| 25 << " for test sync notification server."; | 25 << " for test sync notification server."; |
| 26 } | 26 } |
| 27 | 27 |
| 28 notifier_options.try_ssltcp_first = | |
| 29 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
| 30 DVLOG_IF(1, notifier_options.try_ssltcp_first) | |
| 31 << "Trying SSL/TCP port before XMPP port for notifications."; | |
| 32 | |
| 33 notifier_options.invalidate_xmpp_login = | |
| 34 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
| 35 DVLOG_IF(1, notifier_options.invalidate_xmpp_login) | |
| 36 << "Invalidating sync XMPP login."; | |
| 37 | |
| 38 notifier_options.allow_insecure_connection = | 28 notifier_options.allow_insecure_connection = |
| 39 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | 29 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); |
| 40 DVLOG_IF(1, notifier_options.allow_insecure_connection) | 30 DVLOG_IF(1, notifier_options.allow_insecure_connection) |
| 41 << "Allowing insecure XMPP connections."; | 31 << "Allowing insecure XMPP connections."; |
| 42 | 32 |
| 43 return notifier_options; | 33 return notifier_options; |
| 44 } | 34 } |
| 45 | 35 |
| 46 std::string GenerateInvalidatorClientId() { | 36 std::string GenerateInvalidatorClientId() { |
| 47 // Generate a GUID with 128 bits worth of base64-encoded randomness. | 37 // Generate a GUID with 128 bits worth of base64-encoded randomness. |
| 48 // This format is similar to that of sync's cache_guid. | 38 // This format is similar to that of sync's cache_guid. |
| 49 const int kGuidBytes = 128 / 8; | 39 const int kGuidBytes = 128 / 8; |
| 50 std::string guid; | 40 std::string guid; |
| 51 base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid); | 41 base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid); |
| 52 DCHECK(!guid.empty()); | 42 DCHECK(!guid.empty()); |
| 53 return guid; | 43 return guid; |
| 54 } | 44 } |
| 55 | 45 |
| 56 } // namespace invalidation | 46 } // namespace invalidation |
| OLD | NEW |