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

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

Issue 10795018: [Sync] Remove unneeded 'using syncer::' lines and 'syncer::' scopings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indent Created 8 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 | Annotate | Revision Log
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/base64.h" 10 #include "base/base64.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
47 #include "base/mac/scoped_nsautorelease_pool.h" 47 #include "base/mac/scoped_nsautorelease_pool.h"
48 #endif 48 #endif
49 49
50 // This is a simple utility that initializes a sync client and 50 // This is a simple utility that initializes a sync client and
51 // prints out any events. 51 // prints out any events.
52 52
53 // TODO(akalin): Refactor to combine shared code with 53 // TODO(akalin): Refactor to combine shared code with
54 // sync_listen_notifications. 54 // sync_listen_notifications.
55 namespace syncer {
55 namespace { 56 namespace {
56 57
57 const char kEmailSwitch[] = "email"; 58 const char kEmailSwitch[] = "email";
58 const char kTokenSwitch[] = "token"; 59 const char kTokenSwitch[] = "token";
59 const char kXmppHostPortSwitch[] = "xmpp-host-port"; 60 const char kXmppHostPortSwitch[] = "xmpp-host-port";
60 const char kXmppTrySslTcpFirstSwitch[] = "xmpp-try-ssltcp-first"; 61 const char kXmppTrySslTcpFirstSwitch[] = "xmpp-try-ssltcp-first";
61 const char kXmppAllowInsecureConnectionSwitch[] = 62 const char kXmppAllowInsecureConnectionSwitch[] =
62 "xmpp-allow-insecure-connection"; 63 "xmpp-allow-insecure-connection";
63 const char kNotificationMethodSwitch[] = "notification-method"; 64 const char kNotificationMethodSwitch[] = "notification-method";
64 65
65 class NullInvalidationStateTracker 66 class NullInvalidationStateTracker
66 : public base::SupportsWeakPtr<NullInvalidationStateTracker>, 67 : public base::SupportsWeakPtr<NullInvalidationStateTracker>,
67 public syncer::InvalidationStateTracker { 68 public InvalidationStateTracker {
68 public: 69 public:
69 NullInvalidationStateTracker() {} 70 NullInvalidationStateTracker() {}
70 virtual ~NullInvalidationStateTracker() {} 71 virtual ~NullInvalidationStateTracker() {}
71 72
72 virtual syncer::InvalidationVersionMap 73 virtual InvalidationVersionMap GetAllMaxVersions() const OVERRIDE {
73 GetAllMaxVersions() const OVERRIDE { 74 return InvalidationVersionMap();
74 return syncer::InvalidationVersionMap();
75 } 75 }
76 76
77 virtual void SetMaxVersion( 77 virtual void SetMaxVersion(
78 const invalidation::ObjectId& id, 78 const invalidation::ObjectId& id,
79 int64 max_invalidation_version) OVERRIDE { 79 int64 max_invalidation_version) OVERRIDE {
80 VLOG(1) << "Setting max invalidation version for " 80 VLOG(1) << "Setting max invalidation version for "
81 << syncer::ObjectIdToString(id) << " to " 81 << ObjectIdToString(id) << " to " << max_invalidation_version;
82 << max_invalidation_version;
83 } 82 }
84 83
85 virtual std::string GetInvalidationState() const OVERRIDE { 84 virtual std::string GetInvalidationState() const OVERRIDE {
86 return std::string(); 85 return std::string();
87 } 86 }
88 87
89 virtual void SetInvalidationState(const std::string& state) OVERRIDE { 88 virtual void SetInvalidationState(const std::string& state) OVERRIDE {
90 std::string base64_state; 89 std::string base64_state;
91 CHECK(base::Base64Encode(state, &base64_state)); 90 CHECK(base::Base64Encode(state, &base64_state));
92 VLOG(1) << "Setting invalidation state to: " << base64_state; 91 VLOG(1) << "Setting invalidation state to: " << base64_state;
(...skipping 29 matching lines...) Expand all
122 return context_.get(); 121 return context_.get();
123 } 122 }
124 123
125 private: 124 private:
126 virtual ~MyTestURLRequestContextGetter() {} 125 virtual ~MyTestURLRequestContextGetter() {}
127 126
128 scoped_ptr<MyTestURLRequestContext> context_; 127 scoped_ptr<MyTestURLRequestContext> context_;
129 }; 128 };
130 129
131 // TODO(akalin): Use system encryptor once it's moved to sync/. 130 // TODO(akalin): Use system encryptor once it's moved to sync/.
132 class NullEncryptor : public syncer::Encryptor { 131 class NullEncryptor : public Encryptor {
133 public: 132 public:
134 virtual ~NullEncryptor() {} 133 virtual ~NullEncryptor() {}
135 134
136 virtual bool EncryptString(const std::string& plaintext, 135 virtual bool EncryptString(const std::string& plaintext,
137 std::string* ciphertext) OVERRIDE { 136 std::string* ciphertext) OVERRIDE {
138 *ciphertext = plaintext; 137 *ciphertext = plaintext;
139 return true; 138 return true;
140 } 139 }
141 140
142 virtual bool DecryptString(const std::string& ciphertext, 141 virtual bool DecryptString(const std::string& ciphertext,
143 std::string* plaintext) OVERRIDE { 142 std::string* plaintext) OVERRIDE {
144 *plaintext = ciphertext; 143 *plaintext = ciphertext;
145 return true; 144 return true;
146 } 145 }
147 }; 146 };
148 147
149 std::string ValueToString(const Value& value) { 148 std::string ValueToString(const Value& value) {
150 std::string str; 149 std::string str;
151 base::JSONWriter::Write(&value, &str); 150 base::JSONWriter::Write(&value, &str);
152 return str; 151 return str;
153 } 152 }
154 153
155 class LoggingChangeDelegate : public syncer::SyncManager::ChangeDelegate { 154 class LoggingChangeDelegate : public SyncManager::ChangeDelegate {
156 public: 155 public:
157 virtual ~LoggingChangeDelegate() {} 156 virtual ~LoggingChangeDelegate() {}
158 157
159 virtual void OnChangesApplied( 158 virtual void OnChangesApplied(
160 syncer::ModelType model_type, 159 ModelType model_type,
161 const syncer::BaseTransaction* trans, 160 const BaseTransaction* trans,
162 const syncer::ImmutableChangeRecordList& changes) OVERRIDE { 161 const ImmutableChangeRecordList& changes) OVERRIDE {
163 LOG(INFO) << "Changes applied for " 162 LOG(INFO) << "Changes applied for "
164 << syncer::ModelTypeToString(model_type); 163 << ModelTypeToString(model_type);
165 size_t i = 1; 164 size_t i = 1;
166 size_t change_count = changes.Get().size(); 165 size_t change_count = changes.Get().size();
167 for (syncer::ChangeRecordList::const_iterator it = 166 for (ChangeRecordList::const_iterator it =
168 changes.Get().begin(); it != changes.Get().end(); ++it) { 167 changes.Get().begin(); it != changes.Get().end(); ++it) {
169 scoped_ptr<base::DictionaryValue> change_value(it->ToValue()); 168 scoped_ptr<base::DictionaryValue> change_value(it->ToValue());
170 LOG(INFO) << "Change (" << i << "/" << change_count << "): " 169 LOG(INFO) << "Change (" << i << "/" << change_count << "): "
171 << ValueToString(*change_value); 170 << ValueToString(*change_value);
172 if (it->action != syncer::ChangeRecord::ACTION_DELETE) { 171 if (it->action != ChangeRecord::ACTION_DELETE) {
173 syncer::ReadNode node(trans); 172 ReadNode node(trans);
174 CHECK_EQ(node.InitByIdLookup(it->id), syncer::BaseNode::INIT_OK); 173 CHECK_EQ(node.InitByIdLookup(it->id), BaseNode::INIT_OK);
175 scoped_ptr<base::DictionaryValue> details(node.GetDetailsAsValue()); 174 scoped_ptr<base::DictionaryValue> details(node.GetDetailsAsValue());
176 VLOG(1) << "Details: " << ValueToString(*details); 175 VLOG(1) << "Details: " << ValueToString(*details);
177 } 176 }
178 ++i; 177 ++i;
179 } 178 }
180 } 179 }
181 180
182 virtual void OnChangesComplete(syncer::ModelType model_type) OVERRIDE { 181 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {
183 LOG(INFO) << "Changes complete for " 182 LOG(INFO) << "Changes complete for "
184 << syncer::ModelTypeToString(model_type); 183 << ModelTypeToString(model_type);
185 } 184 }
186 }; 185 };
187 186
188 class LoggingUnrecoverableErrorHandler 187 class LoggingUnrecoverableErrorHandler
189 : public syncer::UnrecoverableErrorHandler { 188 : public UnrecoverableErrorHandler {
190 public: 189 public:
191 virtual ~LoggingUnrecoverableErrorHandler() {} 190 virtual ~LoggingUnrecoverableErrorHandler() {}
192 191
193 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, 192 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here,
194 const std::string& message) OVERRIDE { 193 const std::string& message) OVERRIDE {
195 if (LOG_IS_ON(ERROR)) { 194 if (LOG_IS_ON(ERROR)) {
196 logging::LogMessage(from_here.file_name(), from_here.line_number(), 195 logging::LogMessage(from_here.file_name(), from_here.line_number(),
197 logging::LOG_ERROR).stream() 196 logging::LOG_ERROR).stream()
198 << message; 197 << message;
199 } 198 }
200 } 199 }
201 }; 200 };
202 201
203 class LoggingJsEventHandler 202 class LoggingJsEventHandler
204 : public syncer::JsEventHandler, 203 : public JsEventHandler,
205 public base::SupportsWeakPtr<LoggingJsEventHandler> { 204 public base::SupportsWeakPtr<LoggingJsEventHandler> {
206 public: 205 public:
207 virtual ~LoggingJsEventHandler() {} 206 virtual ~LoggingJsEventHandler() {}
208 207
209 virtual void HandleJsEvent( 208 virtual void HandleJsEvent(
210 const std::string& name, 209 const std::string& name,
211 const syncer::JsEventDetails& details) OVERRIDE { 210 const JsEventDetails& details) OVERRIDE {
212 VLOG(1) << name << ": " << details.ToString(); 211 VLOG(1) << name << ": " << details.ToString();
213 } 212 }
214 }; 213 };
215 214
216 void LogUnrecoverableErrorContext() { 215 void LogUnrecoverableErrorContext() {
217 base::debug::StackTrace stack_trace; 216 base::debug::StackTrace stack_trace;
218 stack_trace.PrintBacktrace(); 217 stack_trace.PrintBacktrace();
219 } 218 }
220 219
221 notifier::NotifierOptions ParseNotifierOptions( 220 notifier::NotifierOptions ParseNotifierOptions(
(...skipping 24 matching lines...) Expand all
246 if (command_line.HasSwitch(kNotificationMethodSwitch)) { 245 if (command_line.HasSwitch(kNotificationMethodSwitch)) {
247 notifier_options.notification_method = 246 notifier_options.notification_method =
248 notifier::StringToNotificationMethod( 247 notifier::StringToNotificationMethod(
249 command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); 248 command_line.GetSwitchValueASCII(kNotificationMethodSwitch));
250 } 249 }
251 250
252 return notifier_options; 251 return notifier_options;
253 } 252 }
254 253
255 } // namespace 254 } // namespace
255 } // namespace syncer
256 256
257 int main(int argc, char* argv[]) { 257 int main(int argc, char* argv[]) {
258 using namespace syncer;
Nicolas Zea 2012/07/19 19:37:56 I think style guide forbids this usage?
akalin 2012/07/19 20:56:02 Done, did what I wanted some other way
258 #if defined(OS_MACOSX) 259 #if defined(OS_MACOSX)
259 base::mac::ScopedNSAutoreleasePool pool; 260 base::mac::ScopedNSAutoreleasePool pool;
260 #endif 261 #endif
261 base::AtExitManager exit_manager; 262 base::AtExitManager exit_manager;
262 CommandLine::Init(argc, argv); 263 CommandLine::Init(argc, argv);
263 logging::InitLogging( 264 logging::InitLogging(
264 NULL, 265 NULL,
265 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 266 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
266 logging::LOCK_LOG_FILE, 267 logging::LOCK_LOG_FILE,
267 logging::DELETE_OLD_LOG_FILE, 268 logging::DELETE_OLD_LOG_FILE,
268 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); 269 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
269 270
270 MessageLoop sync_loop; 271 MessageLoop sync_loop;
271 base::Thread io_thread("IO thread"); 272 base::Thread io_thread("IO thread");
272 base::Thread::Options options; 273 base::Thread::Options options;
273 options.message_loop_type = MessageLoop::TYPE_IO; 274 options.message_loop_type = MessageLoop::TYPE_IO;
274 io_thread.StartWithOptions(options); 275 io_thread.StartWithOptions(options);
275 276
276 // Parse command line. 277 // Parse command line.
277 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 278 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
278 syncer::SyncCredentials credentials; 279 SyncCredentials credentials;
279 credentials.email = command_line.GetSwitchValueASCII(kEmailSwitch); 280 credentials.email = command_line.GetSwitchValueASCII(kEmailSwitch);
280 credentials.sync_token = command_line.GetSwitchValueASCII(kTokenSwitch); 281 credentials.sync_token = command_line.GetSwitchValueASCII(kTokenSwitch);
281 // TODO(akalin): Write a wrapper script that gets a token for an 282 // TODO(akalin): Write a wrapper script that gets a token for an
282 // email and password and passes that in to this utility. 283 // email and password and passes that in to this utility.
283 if (credentials.email.empty() || credentials.sync_token.empty()) { 284 if (credentials.email.empty() || credentials.sync_token.empty()) {
284 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" 285 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n"
285 "[--%s=host:port] [--%s] [--%s]\n" 286 "[--%s=host:port] [--%s] [--%s]\n"
286 "[--%s=(server|p2p)]\n\n" 287 "[--%s=(server|p2p)]\n\n"
287 "Run chrome and set a breakpoint on\n" 288 "Run chrome and set a breakpoint on\n"
288 "syncer::SyncManager::SyncInternal::UpdateCredentials() " 289 "syncer::SyncManager::SyncInternal::UpdateCredentials() "
(...skipping 11 matching lines...) Expand all
300 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( 301 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
301 net::NetworkChangeNotifier::Create()); 302 net::NetworkChangeNotifier::Create());
302 303
303 // Set up sync notifier factory. 304 // Set up sync notifier factory.
304 const scoped_refptr<MyTestURLRequestContextGetter> context_getter = 305 const scoped_refptr<MyTestURLRequestContextGetter> context_getter =
305 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()); 306 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy());
306 const notifier::NotifierOptions& notifier_options = 307 const notifier::NotifierOptions& notifier_options =
307 ParseNotifierOptions(command_line, context_getter); 308 ParseNotifierOptions(command_line, context_getter);
308 const char kClientInfo[] = "sync_listen_notifications"; 309 const char kClientInfo[] = "sync_listen_notifications";
309 NullInvalidationStateTracker null_invalidation_state_tracker; 310 NullInvalidationStateTracker null_invalidation_state_tracker;
310 syncer::SyncNotifierFactory sync_notifier_factory( 311 SyncNotifierFactory sync_notifier_factory(
311 notifier_options, kClientInfo, 312 notifier_options, kClientInfo,
312 null_invalidation_state_tracker.AsWeakPtr()); 313 null_invalidation_state_tracker.AsWeakPtr());
313 314
314 // Set up database directory for the syncer. 315 // Set up database directory for the syncer.
315 ScopedTempDir database_dir; 316 ScopedTempDir database_dir;
316 CHECK(database_dir.CreateUniqueTempDir()); 317 CHECK(database_dir.CreateUniqueTempDir());
317 318
318 // Set up model type parameters. 319 // Set up model type parameters.
319 const syncer::ModelTypeSet model_types = syncer::ModelTypeSet::All(); 320 const ModelTypeSet model_types = ModelTypeSet::All();
320 syncer::ModelSafeRoutingInfo routing_info; 321 ModelSafeRoutingInfo routing_info;
321 for (syncer::ModelTypeSet::Iterator it = model_types.First(); 322 for (ModelTypeSet::Iterator it = model_types.First();
322 it.Good(); it.Inc()) { 323 it.Good(); it.Inc()) {
323 routing_info[it.Get()] = syncer::GROUP_PASSIVE; 324 routing_info[it.Get()] = GROUP_PASSIVE;
324 } 325 }
325 scoped_refptr<syncer::PassiveModelWorker> passive_model_safe_worker = 326 scoped_refptr<PassiveModelWorker> passive_model_safe_worker =
326 new syncer::PassiveModelWorker(&sync_loop); 327 new PassiveModelWorker(&sync_loop);
327 std::vector<syncer::ModelSafeWorker*> workers; 328 std::vector<ModelSafeWorker*> workers;
328 workers.push_back(passive_model_safe_worker.get()); 329 workers.push_back(passive_model_safe_worker.get());
329 330
330 // Set up sync manager. 331 // Set up sync manager.
331 syncer::SyncManagerFactory sync_manager_factory; 332 SyncManagerFactory sync_manager_factory;
332 scoped_ptr<syncer::SyncManager> sync_manager = 333 scoped_ptr<SyncManager> sync_manager =
333 sync_manager_factory.CreateSyncManager("sync_client manager"); 334 sync_manager_factory.CreateSyncManager("sync_client manager");
334 LoggingJsEventHandler js_event_handler; 335 LoggingJsEventHandler js_event_handler;
335 const char kSyncServerAndPath[] = "clients4.google.com/chrome-sync/dev"; 336 const char kSyncServerAndPath[] = "clients4.google.com/chrome-sync/dev";
336 int kSyncServerPort = 443; 337 int kSyncServerPort = 443;
337 bool kUseSsl = true; 338 bool kUseSsl = true;
338 // Used only by RefreshNigori(), so it's okay to leave this as NULL. 339 // Used only by RefreshNigori(), so it's okay to leave this as NULL.
339 const scoped_refptr<base::TaskRunner> blocking_task_runner = NULL; 340 const scoped_refptr<base::TaskRunner> blocking_task_runner = NULL;
340 const char kUserAgent[] = "sync_client"; 341 const char kUserAgent[] = "sync_client";
341 // TODO(akalin): Replace this with just the context getter once 342 // TODO(akalin): Replace this with just the context getter once
342 // HttpPostProviderFactory is removed. 343 // HttpPostProviderFactory is removed.
343 scoped_ptr<syncer::HttpPostProviderFactory> post_factory( 344 scoped_ptr<HttpPostProviderFactory> post_factory(
344 new syncer::HttpBridgeFactory(context_getter, kUserAgent)); 345 new HttpBridgeFactory(context_getter, kUserAgent));
345 // Used only when committing bookmarks, so it's okay to leave this 346 // Used only when committing bookmarks, so it's okay to leave this
346 // as NULL. 347 // as NULL.
347 syncer::ExtensionsActivityMonitor* extensions_activity_monitor = NULL; 348 ExtensionsActivityMonitor* extensions_activity_monitor = NULL;
348 LoggingChangeDelegate change_delegate; 349 LoggingChangeDelegate change_delegate;
349 const char kRestoredKeyForBootstrapping[] = ""; 350 const char kRestoredKeyForBootstrapping[] = "";
350 const syncer::SyncManager::TestingMode kTestingMode = 351 const SyncManager::TestingMode kTestingMode = SyncManager::NON_TEST;
351 syncer::SyncManager::NON_TEST;
352 NullEncryptor null_encryptor; 352 NullEncryptor null_encryptor;
353 LoggingUnrecoverableErrorHandler unrecoverable_error_handler; 353 LoggingUnrecoverableErrorHandler unrecoverable_error_handler;
354 sync_manager->Init(database_dir.path(), 354 sync_manager->Init(database_dir.path(),
355 syncer::WeakHandle<syncer::JsEventHandler>( 355 WeakHandle<JsEventHandler>(
356 js_event_handler.AsWeakPtr()), 356 js_event_handler.AsWeakPtr()),
357 kSyncServerAndPath, 357 kSyncServerAndPath,
358 kSyncServerPort, 358 kSyncServerPort,
359 kUseSsl, 359 kUseSsl,
360 blocking_task_runner, 360 blocking_task_runner,
361 post_factory.Pass(), 361 post_factory.Pass(),
362 routing_info, 362 routing_info,
363 workers, 363 workers,
364 extensions_activity_monitor, 364 extensions_activity_monitor,
365 &change_delegate, 365 &change_delegate,
366 credentials, 366 credentials,
367 scoped_ptr<syncer::SyncNotifier>( 367 scoped_ptr<SyncNotifier>(
368 sync_notifier_factory.CreateSyncNotifier()), 368 sync_notifier_factory.CreateSyncNotifier()),
369 kRestoredKeyForBootstrapping, 369 kRestoredKeyForBootstrapping,
370 kTestingMode, 370 kTestingMode,
371 &null_encryptor, 371 &null_encryptor,
372 &unrecoverable_error_handler, 372 &unrecoverable_error_handler,
373 &LogUnrecoverableErrorContext); 373 &LogUnrecoverableErrorContext);
374 // TODO(akalin): We have pass in model parameters multiple times. 374 // TODO(akalin): Avoid passing in model parameters multiple times by
375 // Organize handling of model types. 375 // organizing handling of model types.
376 sync_manager->UpdateEnabledTypes(model_types); 376 sync_manager->UpdateEnabledTypes(model_types);
377 sync_manager->StartSyncingNormally(routing_info); 377 sync_manager->StartSyncingNormally(routing_info);
378 378
379 sync_loop.Run(); 379 sync_loop.Run();
380 380
381 io_thread.Stop(); 381 io_thread.Stop();
382 return 0; 382 return 0;
383 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698