| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 5 #include <cstddef> |
| 6 #include <cstdio> | 6 #include <cstdio> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/rand_util.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "jingle/notifier/base/notification_method.h" | 18 #include "jingle/notifier/base/notification_method.h" |
| 18 #include "jingle/notifier/base/notifier_options.h" | 19 #include "jingle/notifier/base/notifier_options.h" |
| 19 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 21 #include "net/dns/host_resolver.h" | 22 #include "net/dns/host_resolver.h" |
| 22 #include "net/http/transport_security_state.h" | 23 #include "net/http/transport_security_state.h" |
| 23 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
| 24 #include "sync/internal_api/public/base/model_type.h" | 25 #include "sync/internal_api/public/base/model_type.h" |
| 25 #include "sync/internal_api/public/base/model_type_invalidation_map.h" | 26 #include "sync/internal_api/public/base/model_type_invalidation_map.h" |
| 26 #include "sync/notifier/invalidation_handler.h" | 27 #include "sync/notifier/invalidation_handler.h" |
| 27 #include "sync/notifier/invalidation_state_tracker.h" | 28 #include "sync/notifier/invalidation_state_tracker.h" |
| 28 #include "sync/notifier/invalidation_util.h" | 29 #include "sync/notifier/invalidation_util.h" |
| 29 #include "sync/notifier/invalidator.h" | 30 #include "sync/notifier/invalidator.h" |
| 30 #include "sync/notifier/invalidator_factory.h" | 31 #include "sync/notifier/non_blocking_invalidator.h" |
| 31 #include "sync/tools/null_invalidation_state_tracker.h" | 32 #include "sync/tools/null_invalidation_state_tracker.h" |
| 32 | 33 |
| 33 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| 34 #include "base/mac/scoped_nsautorelease_pool.h" | 35 #include "base/mac/scoped_nsautorelease_pool.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 // This is a simple utility that initializes a sync notifier and | 38 // This is a simple utility that initializes a sync notifier and |
| 38 // listens to any received notifications. | 39 // listens to any received notifications. |
| 39 | 40 |
| 40 namespace syncer { | 41 namespace syncer { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 notifier_options.try_ssltcp_first = | 128 notifier_options.try_ssltcp_first = |
| 128 command_line.HasSwitch(kTrySslTcpFirstSwitch); | 129 command_line.HasSwitch(kTrySslTcpFirstSwitch); |
| 129 LOG_IF(INFO, notifier_options.try_ssltcp_first) | 130 LOG_IF(INFO, notifier_options.try_ssltcp_first) |
| 130 << "Trying SSL/TCP port before XMPP port for notifications."; | 131 << "Trying SSL/TCP port before XMPP port for notifications."; |
| 131 | 132 |
| 132 notifier_options.allow_insecure_connection = | 133 notifier_options.allow_insecure_connection = |
| 133 command_line.HasSwitch(kAllowInsecureConnectionSwitch); | 134 command_line.HasSwitch(kAllowInsecureConnectionSwitch); |
| 134 LOG_IF(INFO, notifier_options.allow_insecure_connection) | 135 LOG_IF(INFO, notifier_options.allow_insecure_connection) |
| 135 << "Allowing insecure XMPP connections."; | 136 << "Allowing insecure XMPP connections."; |
| 136 | 137 |
| 137 if (command_line.HasSwitch(kNotificationMethodSwitch)) { | |
| 138 notifier_options.notification_method = | |
| 139 notifier::StringToNotificationMethod( | |
| 140 command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); | |
| 141 } | |
| 142 | |
| 143 return notifier_options; | 138 return notifier_options; |
| 144 } | 139 } |
| 145 | 140 |
| 146 int SyncListenNotificationsMain(int argc, char* argv[]) { | 141 int SyncListenNotificationsMain(int argc, char* argv[]) { |
| 147 using namespace syncer; | 142 using namespace syncer; |
| 148 #if defined(OS_MACOSX) | 143 #if defined(OS_MACOSX) |
| 149 base::mac::ScopedNSAutoreleasePool pool; | 144 base::mac::ScopedNSAutoreleasePool pool; |
| 150 #endif | 145 #endif |
| 151 base::AtExitManager exit_manager; | 146 base::AtExitManager exit_manager; |
| 152 CommandLine::Init(argc, argv); | 147 CommandLine::Init(argc, argv); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 165 | 160 |
| 166 // Parse command line. | 161 // Parse command line. |
| 167 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 162 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 168 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); | 163 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); |
| 169 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); | 164 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); |
| 170 // TODO(akalin): Write a wrapper script that gets a token for an | 165 // TODO(akalin): Write a wrapper script that gets a token for an |
| 171 // email and password and passes that in to this utility. | 166 // email and password and passes that in to this utility. |
| 172 if (email.empty() || token.empty()) { | 167 if (email.empty() || token.empty()) { |
| 173 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" | 168 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" |
| 174 "[--%s=host:port] [--%s] [--%s]\n" | 169 "[--%s=host:port] [--%s] [--%s]\n" |
| 175 "[--%s=(server|p2p)]\n\n" | |
| 176 "Run chrome and set a breakpoint on\n" | 170 "Run chrome and set a breakpoint on\n" |
| 177 "syncer::SyncManagerImpl::UpdateCredentials() " | 171 "syncer::SyncManagerImpl::UpdateCredentials() " |
| 178 "after logging into\n" | 172 "after logging into\n" |
| 179 "sync to get the token to pass into this utility.\n", | 173 "sync to get the token to pass into this utility.\n", |
| 180 argv[0], | 174 argv[0], |
| 181 kEmailSwitch, kTokenSwitch, kHostPortSwitch, | 175 kEmailSwitch, kTokenSwitch, kHostPortSwitch, |
| 182 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, | 176 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); |
| 183 kNotificationMethodSwitch); | |
| 184 return -1; | 177 return -1; |
| 185 } | 178 } |
| 186 | 179 |
| 187 // Set up objects that monitor the network. | 180 // Set up objects that monitor the network. |
| 188 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | 181 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( |
| 189 net::NetworkChangeNotifier::Create()); | 182 net::NetworkChangeNotifier::Create()); |
| 190 | 183 |
| 191 const notifier::NotifierOptions& notifier_options = | 184 const notifier::NotifierOptions& notifier_options = |
| 192 ParseNotifierOptions( | 185 ParseNotifierOptions( |
| 193 command_line, | 186 command_line, |
| 194 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); | 187 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); |
| 195 const char kClientInfo[] = "sync_listen_notifications"; | 188 const char kClientInfo[] = "sync_listen_notifications"; |
| 196 NullInvalidationStateTracker null_invalidation_state_tracker; | 189 NullInvalidationStateTracker null_invalidation_state_tracker; |
| 197 InvalidatorFactory invalidator_factory( | |
| 198 notifier_options, kClientInfo, | |
| 199 null_invalidation_state_tracker.AsWeakPtr()); | |
| 200 scoped_ptr<Invalidator> invalidator( | 190 scoped_ptr<Invalidator> invalidator( |
| 201 invalidator_factory.CreateInvalidator()); | 191 new NonBlockingInvalidator( |
| 192 notifier_options, |
| 193 base::RandBytesAsString(8), |
| 194 null_invalidation_state_tracker.GetAllInvalidationStates(), |
| 195 null_invalidation_state_tracker.GetBootstrapData(), |
| 196 WeakHandle<InvalidationStateTracker>( |
| 197 null_invalidation_state_tracker.AsWeakPtr()), |
| 198 kClientInfo)); |
| 199 |
| 202 NotificationPrinter notification_printer; | 200 NotificationPrinter notification_printer; |
| 203 | 201 |
| 204 invalidator->UpdateCredentials(email, token); | 202 invalidator->UpdateCredentials(email, token); |
| 205 | 203 |
| 206 // Listen for notifications for all known types. | 204 // Listen for notifications for all known types. |
| 207 invalidator->RegisterHandler(¬ification_printer); | 205 invalidator->RegisterHandler(¬ification_printer); |
| 208 invalidator->UpdateRegisteredIds( | 206 invalidator->UpdateRegisteredIds( |
| 209 ¬ification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); | 207 ¬ification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); |
| 210 | 208 |
| 211 ui_loop.Run(); | 209 ui_loop.Run(); |
| 212 | 210 |
| 213 invalidator->UnregisterHandler(¬ification_printer); | 211 invalidator->UnregisterHandler(¬ification_printer); |
| 214 io_thread.Stop(); | 212 io_thread.Stop(); |
| 215 return 0; | 213 return 0; |
| 216 } | 214 } |
| 217 | 215 |
| 218 } // namespace | 216 } // namespace |
| 219 } // namespace syncer | 217 } // namespace syncer |
| 220 | 218 |
| 221 int main(int argc, char* argv[]) { | 219 int main(int argc, char* argv[]) { |
| 222 return syncer::SyncListenNotificationsMain(argc, argv); | 220 return syncer::SyncListenNotificationsMain(argc, argv); |
| 223 } | 221 } |
| OLD | NEW |