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

Side by Side Diff: sync/tools/sync_listen_notifications.cc

Issue 17911005: Merge 208347 "Revert 208315 "Make use of InvalidationService"" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1547/src/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « sync/tools/sync_client.cc ('k') | sync/tools/testserver/xmppserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
17 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
18 #include "jingle/notifier/base/notification_method.h" 17 #include "jingle/notifier/base/notification_method.h"
19 #include "jingle/notifier/base/notifier_options.h" 18 #include "jingle/notifier/base/notifier_options.h"
20 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
21 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
22 #include "net/dns/host_resolver.h" 21 #include "net/dns/host_resolver.h"
23 #include "net/http/transport_security_state.h" 22 #include "net/http/transport_security_state.h"
24 #include "net/url_request/url_request_test_util.h" 23 #include "net/url_request/url_request_test_util.h"
25 #include "sync/internal_api/public/base/model_type.h" 24 #include "sync/internal_api/public/base/model_type.h"
26 #include "sync/internal_api/public/base/model_type_invalidation_map.h" 25 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
27 #include "sync/notifier/invalidation_handler.h" 26 #include "sync/notifier/invalidation_handler.h"
28 #include "sync/notifier/invalidation_state_tracker.h" 27 #include "sync/notifier/invalidation_state_tracker.h"
29 #include "sync/notifier/invalidation_util.h" 28 #include "sync/notifier/invalidation_util.h"
30 #include "sync/notifier/invalidator.h" 29 #include "sync/notifier/invalidator.h"
31 #include "sync/notifier/non_blocking_invalidator.h" 30 #include "sync/notifier/invalidator_factory.h"
32 #include "sync/tools/null_invalidation_state_tracker.h" 31 #include "sync/tools/null_invalidation_state_tracker.h"
33 32
34 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
35 #include "base/mac/scoped_nsautorelease_pool.h" 34 #include "base/mac/scoped_nsautorelease_pool.h"
36 #endif 35 #endif
37 36
38 // This is a simple utility that initializes a sync notifier and 37 // This is a simple utility that initializes a sync notifier and
39 // listens to any received notifications. 38 // listens to any received notifications.
40 39
41 namespace syncer { 40 namespace syncer {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 notifier_options.try_ssltcp_first = 127 notifier_options.try_ssltcp_first =
129 command_line.HasSwitch(kTrySslTcpFirstSwitch); 128 command_line.HasSwitch(kTrySslTcpFirstSwitch);
130 LOG_IF(INFO, notifier_options.try_ssltcp_first) 129 LOG_IF(INFO, notifier_options.try_ssltcp_first)
131 << "Trying SSL/TCP port before XMPP port for notifications."; 130 << "Trying SSL/TCP port before XMPP port for notifications.";
132 131
133 notifier_options.allow_insecure_connection = 132 notifier_options.allow_insecure_connection =
134 command_line.HasSwitch(kAllowInsecureConnectionSwitch); 133 command_line.HasSwitch(kAllowInsecureConnectionSwitch);
135 LOG_IF(INFO, notifier_options.allow_insecure_connection) 134 LOG_IF(INFO, notifier_options.allow_insecure_connection)
136 << "Allowing insecure XMPP connections."; 135 << "Allowing insecure XMPP connections.";
137 136
137 if (command_line.HasSwitch(kNotificationMethodSwitch)) {
138 notifier_options.notification_method =
139 notifier::StringToNotificationMethod(
140 command_line.GetSwitchValueASCII(kNotificationMethodSwitch));
141 }
142
138 return notifier_options; 143 return notifier_options;
139 } 144 }
140 145
141 int SyncListenNotificationsMain(int argc, char* argv[]) { 146 int SyncListenNotificationsMain(int argc, char* argv[]) {
142 using namespace syncer; 147 using namespace syncer;
143 #if defined(OS_MACOSX) 148 #if defined(OS_MACOSX)
144 base::mac::ScopedNSAutoreleasePool pool; 149 base::mac::ScopedNSAutoreleasePool pool;
145 #endif 150 #endif
146 base::AtExitManager exit_manager; 151 base::AtExitManager exit_manager;
147 CommandLine::Init(argc, argv); 152 CommandLine::Init(argc, argv);
148 logging::LoggingSettings settings; 153 logging::LoggingSettings settings;
149 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 154 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
150 logging::InitLogging(settings); 155 logging::InitLogging(settings);
151 156
152 base::MessageLoop ui_loop; 157 base::MessageLoop ui_loop;
153 base::Thread io_thread("IO thread"); 158 base::Thread io_thread("IO thread");
154 base::Thread::Options options; 159 base::Thread::Options options;
155 options.message_loop_type = base::MessageLoop::TYPE_IO; 160 options.message_loop_type = base::MessageLoop::TYPE_IO;
156 io_thread.StartWithOptions(options); 161 io_thread.StartWithOptions(options);
157 162
158 // Parse command line. 163 // Parse command line.
159 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 164 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
160 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); 165 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch);
161 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); 166 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch);
162 // TODO(akalin): Write a wrapper script that gets a token for an 167 // TODO(akalin): Write a wrapper script that gets a token for an
163 // email and password and passes that in to this utility. 168 // email and password and passes that in to this utility.
164 if (email.empty() || token.empty()) { 169 if (email.empty() || token.empty()) {
165 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" 170 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n"
166 "[--%s=host:port] [--%s] [--%s]\n" 171 "[--%s=host:port] [--%s] [--%s]\n"
172 "[--%s=(server|p2p)]\n\n"
167 "Run chrome and set a breakpoint on\n" 173 "Run chrome and set a breakpoint on\n"
168 "syncer::SyncManagerImpl::UpdateCredentials() " 174 "syncer::SyncManagerImpl::UpdateCredentials() "
169 "after logging into\n" 175 "after logging into\n"
170 "sync to get the token to pass into this utility.\n", 176 "sync to get the token to pass into this utility.\n",
171 argv[0], 177 argv[0],
172 kEmailSwitch, kTokenSwitch, kHostPortSwitch, 178 kEmailSwitch, kTokenSwitch, kHostPortSwitch,
173 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); 179 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch,
180 kNotificationMethodSwitch);
174 return -1; 181 return -1;
175 } 182 }
176 183
177 // Set up objects that monitor the network. 184 // Set up objects that monitor the network.
178 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( 185 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
179 net::NetworkChangeNotifier::Create()); 186 net::NetworkChangeNotifier::Create());
180 187
181 const notifier::NotifierOptions& notifier_options = 188 const notifier::NotifierOptions& notifier_options =
182 ParseNotifierOptions( 189 ParseNotifierOptions(
183 command_line, 190 command_line,
184 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); 191 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()));
185 const char kClientInfo[] = "sync_listen_notifications"; 192 const char kClientInfo[] = "sync_listen_notifications";
186 NullInvalidationStateTracker null_invalidation_state_tracker; 193 NullInvalidationStateTracker null_invalidation_state_tracker;
194 InvalidatorFactory invalidator_factory(
195 notifier_options, kClientInfo,
196 null_invalidation_state_tracker.AsWeakPtr());
187 scoped_ptr<Invalidator> invalidator( 197 scoped_ptr<Invalidator> invalidator(
188 new NonBlockingInvalidator( 198 invalidator_factory.CreateInvalidator());
189 notifier_options,
190 base::RandBytesAsString(8),
191 null_invalidation_state_tracker.GetAllInvalidationStates(),
192 null_invalidation_state_tracker.GetBootstrapData(),
193 WeakHandle<InvalidationStateTracker>(
194 null_invalidation_state_tracker.AsWeakPtr()),
195 kClientInfo));
196
197 NotificationPrinter notification_printer; 199 NotificationPrinter notification_printer;
198 200
199 invalidator->UpdateCredentials(email, token); 201 invalidator->UpdateCredentials(email, token);
200 202
201 // Listen for notifications for all known types. 203 // Listen for notifications for all known types.
202 invalidator->RegisterHandler(&notification_printer); 204 invalidator->RegisterHandler(&notification_printer);
203 invalidator->UpdateRegisteredIds( 205 invalidator->UpdateRegisteredIds(
204 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); 206 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All()));
205 207
206 ui_loop.Run(); 208 ui_loop.Run();
207 209
208 invalidator->UnregisterHandler(&notification_printer); 210 invalidator->UnregisterHandler(&notification_printer);
209 io_thread.Stop(); 211 io_thread.Stop();
210 return 0; 212 return 0;
211 } 213 }
212 214
213 } // namespace 215 } // namespace
214 } // namespace syncer 216 } // namespace syncer
215 217
216 int main(int argc, char* argv[]) { 218 int main(int argc, char* argv[]) {
217 return syncer::SyncListenNotificationsMain(argc, argv); 219 return syncer::SyncListenNotificationsMain(argc, argv);
218 } 220 }
OLDNEW
« no previous file with comments | « sync/tools/sync_client.cc ('k') | sync/tools/testserver/xmppserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698