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

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

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 5 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
« 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"
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
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);
153 logging::LoggingSettings settings; 148 logging::LoggingSettings settings;
154 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 149 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
155 logging::InitLogging(settings); 150 logging::InitLogging(settings);
156 151
157 base::MessageLoop ui_loop; 152 base::MessageLoop ui_loop;
158 base::Thread io_thread("IO thread"); 153 base::Thread io_thread("IO thread");
159 base::Thread::Options options; 154 base::Thread::Options options;
160 options.message_loop_type = base::MessageLoop::TYPE_IO; 155 options.message_loop_type = base::MessageLoop::TYPE_IO;
161 io_thread.StartWithOptions(options); 156 io_thread.StartWithOptions(options);
162 157
163 // Parse command line. 158 // Parse command line.
164 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 159 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
165 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); 160 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch);
166 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); 161 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch);
167 // TODO(akalin): Write a wrapper script that gets a token for an 162 // TODO(akalin): Write a wrapper script that gets a token for an
168 // email and password and passes that in to this utility. 163 // email and password and passes that in to this utility.
169 if (email.empty() || token.empty()) { 164 if (email.empty() || token.empty()) {
170 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" 165 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n"
171 "[--%s=host:port] [--%s] [--%s]\n" 166 "[--%s=host:port] [--%s] [--%s]\n"
172 "[--%s=(server|p2p)]\n\n"
173 "Run chrome and set a breakpoint on\n" 167 "Run chrome and set a breakpoint on\n"
174 "syncer::SyncManagerImpl::UpdateCredentials() " 168 "syncer::SyncManagerImpl::UpdateCredentials() "
175 "after logging into\n" 169 "after logging into\n"
176 "sync to get the token to pass into this utility.\n", 170 "sync to get the token to pass into this utility.\n",
177 argv[0], 171 argv[0],
178 kEmailSwitch, kTokenSwitch, kHostPortSwitch, 172 kEmailSwitch, kTokenSwitch, kHostPortSwitch,
179 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, 173 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch);
180 kNotificationMethodSwitch);
181 return -1; 174 return -1;
182 } 175 }
183 176
184 // Set up objects that monitor the network. 177 // Set up objects that monitor the network.
185 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( 178 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
186 net::NetworkChangeNotifier::Create()); 179 net::NetworkChangeNotifier::Create());
187 180
188 const notifier::NotifierOptions& notifier_options = 181 const notifier::NotifierOptions& notifier_options =
189 ParseNotifierOptions( 182 ParseNotifierOptions(
190 command_line, 183 command_line,
191 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); 184 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()));
192 const char kClientInfo[] = "sync_listen_notifications"; 185 const char kClientInfo[] = "sync_listen_notifications";
193 NullInvalidationStateTracker null_invalidation_state_tracker; 186 NullInvalidationStateTracker null_invalidation_state_tracker;
194 InvalidatorFactory invalidator_factory(
195 notifier_options, kClientInfo,
196 null_invalidation_state_tracker.AsWeakPtr());
197 scoped_ptr<Invalidator> invalidator( 187 scoped_ptr<Invalidator> invalidator(
198 invalidator_factory.CreateInvalidator()); 188 new NonBlockingInvalidator(
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
199 NotificationPrinter notification_printer; 197 NotificationPrinter notification_printer;
200 198
201 invalidator->UpdateCredentials(email, token); 199 invalidator->UpdateCredentials(email, token);
202 200
203 // Listen for notifications for all known types. 201 // Listen for notifications for all known types.
204 invalidator->RegisterHandler(&notification_printer); 202 invalidator->RegisterHandler(&notification_printer);
205 invalidator->UpdateRegisteredIds( 203 invalidator->UpdateRegisteredIds(
206 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); 204 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All()));
207 205
208 ui_loop.Run(); 206 ui_loop.Run();
209 207
210 invalidator->UnregisterHandler(&notification_printer); 208 invalidator->UnregisterHandler(&notification_printer);
211 io_thread.Stop(); 209 io_thread.Stop();
212 return 0; 210 return 0;
213 } 211 }
214 212
215 } // namespace 213 } // namespace
216 } // namespace syncer 214 } // namespace syncer
217 215
218 int main(int argc, char* argv[]) { 216 int main(int argc, char* argv[]) {
219 return syncer::SyncListenNotificationsMain(argc, argv); 217 return syncer::SyncListenNotificationsMain(argc, argv);
220 } 218 }
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