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 <stdint.h> | 5 #include <stdint.h> |
| 6 |
6 #include <cstddef> | 7 #include <cstddef> |
7 #include <cstdio> | 8 #include <cstdio> |
| 9 #include <memory> |
8 #include <string> | 10 #include <string> |
9 #include <utility> | 11 #include <utility> |
10 | 12 |
11 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
14 #include "base/debug/stack_trace.h" | 16 #include "base/debug/stack_trace.h" |
15 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
16 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
17 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/ptr_util.h" |
18 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | |
20 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
22 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
23 #include "base/task_runner.h" | 25 #include "base/task_runner.h" |
24 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
25 #include "build/build_config.h" | 27 #include "build/build_config.h" |
26 #include "components/invalidation/impl/non_blocking_invalidator.h" | 28 #include "components/invalidation/impl/non_blocking_invalidator.h" |
27 #include "components/invalidation/public/object_id_invalidation_map.h" | 29 #include "components/invalidation/public/object_id_invalidation_map.h" |
28 #include "components/sync_driver/invalidation_helper.h" | 30 #include "components/sync_driver/invalidation_helper.h" |
29 #include "jingle/notifier/base/notification_method.h" | 31 #include "jingle/notifier/base/notification_method.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 "xmpp-allow-insecure-connection"; | 73 "xmpp-allow-insecure-connection"; |
72 const char kSyncServiceURL[] = "https://clients4.google.com/chrome-sync/dev"; | 74 const char kSyncServiceURL[] = "https://clients4.google.com/chrome-sync/dev"; |
73 | 75 |
74 // Needed to use a real host resolver. | 76 // Needed to use a real host resolver. |
75 class MyTestURLRequestContext : public net::TestURLRequestContext { | 77 class MyTestURLRequestContext : public net::TestURLRequestContext { |
76 public: | 78 public: |
77 MyTestURLRequestContext() : TestURLRequestContext(true) { | 79 MyTestURLRequestContext() : TestURLRequestContext(true) { |
78 context_storage_.set_host_resolver( | 80 context_storage_.set_host_resolver( |
79 net::HostResolver::CreateDefaultResolver(NULL)); | 81 net::HostResolver::CreateDefaultResolver(NULL)); |
80 context_storage_.set_transport_security_state( | 82 context_storage_.set_transport_security_state( |
81 make_scoped_ptr(new net::TransportSecurityState())); | 83 base::WrapUnique(new net::TransportSecurityState())); |
82 Init(); | 84 Init(); |
83 } | 85 } |
84 | 86 |
85 ~MyTestURLRequestContext() override {} | 87 ~MyTestURLRequestContext() override {} |
86 }; | 88 }; |
87 | 89 |
88 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter { | 90 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter { |
89 public: | 91 public: |
90 explicit MyTestURLRequestContextGetter( | 92 explicit MyTestURLRequestContextGetter( |
91 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 93 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
92 : TestURLRequestContextGetter(io_task_runner) {} | 94 : TestURLRequestContextGetter(io_task_runner) {} |
93 | 95 |
94 net::TestURLRequestContext* GetURLRequestContext() override { | 96 net::TestURLRequestContext* GetURLRequestContext() override { |
95 // Construct |context_| lazily so it gets constructed on the right | 97 // Construct |context_| lazily so it gets constructed on the right |
96 // thread (the IO thread). | 98 // thread (the IO thread). |
97 if (!context_) | 99 if (!context_) |
98 context_.reset(new MyTestURLRequestContext()); | 100 context_.reset(new MyTestURLRequestContext()); |
99 return context_.get(); | 101 return context_.get(); |
100 } | 102 } |
101 | 103 |
102 private: | 104 private: |
103 ~MyTestURLRequestContextGetter() override {} | 105 ~MyTestURLRequestContextGetter() override {} |
104 | 106 |
105 scoped_ptr<MyTestURLRequestContext> context_; | 107 std::unique_ptr<MyTestURLRequestContext> context_; |
106 }; | 108 }; |
107 | 109 |
108 // TODO(akalin): Use system encryptor once it's moved to sync/. | 110 // TODO(akalin): Use system encryptor once it's moved to sync/. |
109 class NullEncryptor : public Encryptor { | 111 class NullEncryptor : public Encryptor { |
110 public: | 112 public: |
111 ~NullEncryptor() override {} | 113 ~NullEncryptor() override {} |
112 | 114 |
113 bool EncryptString(const std::string& plaintext, | 115 bool EncryptString(const std::string& plaintext, |
114 std::string* ciphertext) override { | 116 std::string* ciphertext) override { |
115 *ciphertext = plaintext; | 117 *ciphertext = plaintext; |
(...skipping 20 matching lines...) Expand all Loading... |
136 void OnChangesApplied(ModelType model_type, | 138 void OnChangesApplied(ModelType model_type, |
137 int64_t model_version, | 139 int64_t model_version, |
138 const BaseTransaction* trans, | 140 const BaseTransaction* trans, |
139 const ImmutableChangeRecordList& changes) override { | 141 const ImmutableChangeRecordList& changes) override { |
140 LOG(INFO) << "Changes applied for " | 142 LOG(INFO) << "Changes applied for " |
141 << ModelTypeToString(model_type); | 143 << ModelTypeToString(model_type); |
142 size_t i = 1; | 144 size_t i = 1; |
143 size_t change_count = changes.Get().size(); | 145 size_t change_count = changes.Get().size(); |
144 for (ChangeRecordList::const_iterator it = | 146 for (ChangeRecordList::const_iterator it = |
145 changes.Get().begin(); it != changes.Get().end(); ++it) { | 147 changes.Get().begin(); it != changes.Get().end(); ++it) { |
146 scoped_ptr<base::DictionaryValue> change_value(it->ToValue()); | 148 std::unique_ptr<base::DictionaryValue> change_value(it->ToValue()); |
147 LOG(INFO) << "Change (" << i << "/" << change_count << "): " | 149 LOG(INFO) << "Change (" << i << "/" << change_count << "): " |
148 << ValueToString(*change_value); | 150 << ValueToString(*change_value); |
149 if (it->action != ChangeRecord::ACTION_DELETE) { | 151 if (it->action != ChangeRecord::ACTION_DELETE) { |
150 ReadNode node(trans); | 152 ReadNode node(trans); |
151 CHECK_EQ(node.InitByIdLookup(it->id), BaseNode::INIT_OK); | 153 CHECK_EQ(node.InitByIdLookup(it->id), BaseNode::INIT_OK); |
152 scoped_ptr<base::DictionaryValue> details(node.ToValue()); | 154 std::unique_ptr<base::DictionaryValue> details(node.ToValue()); |
153 VLOG(1) << "Details: " << ValueToString(*details); | 155 VLOG(1) << "Details: " << ValueToString(*details); |
154 } | 156 } |
155 ++i; | 157 ++i; |
156 } | 158 } |
157 } | 159 } |
158 | 160 |
159 void OnChangesComplete(ModelType model_type) override { | 161 void OnChangesComplete(ModelType model_type) override { |
160 LOG(INFO) << "Changes complete for " | 162 LOG(INFO) << "Changes complete for " |
161 << ModelTypeToString(model_type); | 163 << ModelTypeToString(model_type); |
162 } | 164 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { | 234 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { |
233 DLOG(WARNING) << "Notification has invalid id: " | 235 DLOG(WARNING) << "Notification has invalid id: " |
234 << syncer::ObjectIdToString(*ids_it); | 236 << syncer::ObjectIdToString(*ids_it); |
235 } else { | 237 } else { |
236 syncer::SingleObjectInvalidationSet invalidation_set = | 238 syncer::SingleObjectInvalidationSet invalidation_set = |
237 invalidation_map.ForObject(*ids_it); | 239 invalidation_map.ForObject(*ids_it); |
238 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = | 240 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = |
239 invalidation_set.begin(); | 241 invalidation_set.begin(); |
240 inv_it != invalidation_set.end(); | 242 inv_it != invalidation_set.end(); |
241 ++inv_it) { | 243 ++inv_it) { |
242 scoped_ptr<syncer::InvalidationInterface> inv_adapter( | 244 std::unique_ptr<syncer::InvalidationInterface> inv_adapter( |
243 new InvalidationAdapter(*inv_it)); | 245 new InvalidationAdapter(*inv_it)); |
244 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); | 246 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); |
245 } | 247 } |
246 } | 248 } |
247 } | 249 } |
248 } | 250 } |
249 | 251 |
250 std::string GetOwnerName() const override { return "InvalidatorShim"; } | 252 std::string GetOwnerName() const override { return "InvalidatorShim"; } |
251 | 253 |
252 private: | 254 private: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 "after logging into\n" | 325 "after logging into\n" |
324 "sync to get the token to pass into this utility.\n", | 326 "sync to get the token to pass into this utility.\n", |
325 argv[0], | 327 argv[0], |
326 kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, | 328 kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, |
327 kXmppTrySslTcpFirstSwitch, | 329 kXmppTrySslTcpFirstSwitch, |
328 kXmppAllowInsecureConnectionSwitch); | 330 kXmppAllowInsecureConnectionSwitch); |
329 return -1; | 331 return -1; |
330 } | 332 } |
331 | 333 |
332 // Set up objects that monitor the network. | 334 // Set up objects that monitor the network. |
333 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | 335 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier( |
334 net::NetworkChangeNotifier::Create()); | 336 net::NetworkChangeNotifier::Create()); |
335 | 337 |
336 // Set up sync notifier factory. | 338 // Set up sync notifier factory. |
337 const scoped_refptr<MyTestURLRequestContextGetter> context_getter = | 339 const scoped_refptr<MyTestURLRequestContextGetter> context_getter = |
338 new MyTestURLRequestContextGetter(io_thread.task_runner()); | 340 new MyTestURLRequestContextGetter(io_thread.task_runner()); |
339 const notifier::NotifierOptions& notifier_options = | 341 const notifier::NotifierOptions& notifier_options = |
340 ParseNotifierOptions(command_line, context_getter); | 342 ParseNotifierOptions(command_line, context_getter); |
341 syncer::NetworkChannelCreator network_channel_creator = | 343 syncer::NetworkChannelCreator network_channel_creator = |
342 syncer::NonBlockingInvalidator::MakePushClientChannelCreator( | 344 syncer::NonBlockingInvalidator::MakePushClientChannelCreator( |
343 notifier_options); | 345 notifier_options); |
344 const char kClientInfo[] = "standalone_sync_client"; | 346 const char kClientInfo[] = "standalone_sync_client"; |
345 std::string invalidator_id = base::RandBytesAsString(8); | 347 std::string invalidator_id = base::RandBytesAsString(8); |
346 NullInvalidationStateTracker null_invalidation_state_tracker; | 348 NullInvalidationStateTracker null_invalidation_state_tracker; |
347 scoped_ptr<Invalidator> invalidator(new NonBlockingInvalidator( | 349 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator( |
348 network_channel_creator, | 350 network_channel_creator, invalidator_id, |
349 invalidator_id, | |
350 null_invalidation_state_tracker.GetSavedInvalidations(), | 351 null_invalidation_state_tracker.GetSavedInvalidations(), |
351 null_invalidation_state_tracker.GetBootstrapData(), | 352 null_invalidation_state_tracker.GetBootstrapData(), |
352 &null_invalidation_state_tracker, | 353 &null_invalidation_state_tracker, kClientInfo, |
353 kClientInfo, | |
354 notifier_options.request_context_getter)); | 354 notifier_options.request_context_getter)); |
355 | 355 |
356 // Set up database directory for the syncer. | 356 // Set up database directory for the syncer. |
357 base::ScopedTempDir database_dir; | 357 base::ScopedTempDir database_dir; |
358 CHECK(database_dir.CreateUniqueTempDir()); | 358 CHECK(database_dir.CreateUniqueTempDir()); |
359 | 359 |
360 // Developers often add types to ModelTypeSet::All() before the server | 360 // Developers often add types to ModelTypeSet::All() before the server |
361 // supports them. We need to be explicit about which types we want here. | 361 // supports them. We need to be explicit about which types we want here. |
362 ModelTypeSet model_types; | 362 ModelTypeSet model_types; |
363 model_types.Put(BOOKMARKS); | 363 model_types.Put(BOOKMARKS); |
(...skipping 26 matching lines...) Expand all Loading... |
390 it.Good(); it.Inc()) { | 390 it.Good(); it.Inc()) { |
391 routing_info[it.Get()] = GROUP_PASSIVE; | 391 routing_info[it.Get()] = GROUP_PASSIVE; |
392 } | 392 } |
393 scoped_refptr<PassiveModelWorker> passive_model_safe_worker = | 393 scoped_refptr<PassiveModelWorker> passive_model_safe_worker = |
394 new PassiveModelWorker(nullptr); | 394 new PassiveModelWorker(nullptr); |
395 std::vector<scoped_refptr<ModelSafeWorker> > workers; | 395 std::vector<scoped_refptr<ModelSafeWorker> > workers; |
396 workers.push_back(passive_model_safe_worker); | 396 workers.push_back(passive_model_safe_worker); |
397 | 397 |
398 // Set up sync manager. | 398 // Set up sync manager. |
399 SyncManagerFactory sync_manager_factory; | 399 SyncManagerFactory sync_manager_factory; |
400 scoped_ptr<SyncManager> sync_manager = | 400 std::unique_ptr<SyncManager> sync_manager = |
401 sync_manager_factory.CreateSyncManager("sync_client manager"); | 401 sync_manager_factory.CreateSyncManager("sync_client manager"); |
402 LoggingJsEventHandler js_event_handler; | 402 LoggingJsEventHandler js_event_handler; |
403 // Used only by InitialProcessMetadata(), so it's okay to leave this as NULL. | 403 // Used only by InitialProcessMetadata(), so it's okay to leave this as NULL. |
404 const scoped_refptr<base::TaskRunner> blocking_task_runner = NULL; | 404 const scoped_refptr<base::TaskRunner> blocking_task_runner = NULL; |
405 const char kUserAgent[] = "sync_client"; | 405 const char kUserAgent[] = "sync_client"; |
406 // TODO(akalin): Replace this with just the context getter once | 406 // TODO(akalin): Replace this with just the context getter once |
407 // HttpPostProviderFactory is removed. | 407 // HttpPostProviderFactory is removed. |
408 CancelationSignal factory_cancelation_signal; | 408 CancelationSignal factory_cancelation_signal; |
409 scoped_ptr<HttpPostProviderFactory> post_factory( | 409 std::unique_ptr<HttpPostProviderFactory> post_factory(new HttpBridgeFactory( |
410 new HttpBridgeFactory(context_getter.get(), | 410 context_getter.get(), base::Bind(&StubNetworkTimeUpdateCallback), |
411 base::Bind(&StubNetworkTimeUpdateCallback), | 411 &factory_cancelation_signal)); |
412 &factory_cancelation_signal)); | |
413 post_factory->Init(kUserAgent, BindToTrackerCallback()); | 412 post_factory->Init(kUserAgent, BindToTrackerCallback()); |
414 // Used only when committing bookmarks, so it's okay to leave this | 413 // Used only when committing bookmarks, so it's okay to leave this |
415 // as NULL. | 414 // as NULL. |
416 ExtensionsActivity* extensions_activity = NULL; | 415 ExtensionsActivity* extensions_activity = NULL; |
417 LoggingChangeDelegate change_delegate; | 416 LoggingChangeDelegate change_delegate; |
418 const char kRestoredKeyForBootstrapping[] = ""; | 417 const char kRestoredKeyForBootstrapping[] = ""; |
419 const char kRestoredKeystoreKeyForBootstrapping[] = ""; | 418 const char kRestoredKeystoreKeyForBootstrapping[] = ""; |
420 NullEncryptor null_encryptor; | 419 NullEncryptor null_encryptor; |
421 InternalComponentsFactoryImpl::Switches factory_switches = { | 420 InternalComponentsFactoryImpl::Switches factory_switches = { |
422 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 421 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
(...skipping 18 matching lines...) Expand all Loading... |
441 new InternalComponentsFactoryImpl(factory_switches)); | 440 new InternalComponentsFactoryImpl(factory_switches)); |
442 args.encryptor = &null_encryptor; | 441 args.encryptor = &null_encryptor; |
443 args.unrecoverable_error_handler = WeakHandle<UnrecoverableErrorHandler>(); | 442 args.unrecoverable_error_handler = WeakHandle<UnrecoverableErrorHandler>(); |
444 args.report_unrecoverable_error_function = | 443 args.report_unrecoverable_error_function = |
445 base::Bind(LogUnrecoverableErrorContext); | 444 base::Bind(LogUnrecoverableErrorContext); |
446 args.cancelation_signal = &scm_cancelation_signal; | 445 args.cancelation_signal = &scm_cancelation_signal; |
447 sync_manager->Init(&args); | 446 sync_manager->Init(&args); |
448 // TODO(akalin): Avoid passing in model parameters multiple times by | 447 // TODO(akalin): Avoid passing in model parameters multiple times by |
449 // organizing handling of model types. | 448 // organizing handling of model types. |
450 invalidator->UpdateCredentials(credentials.email, credentials.sync_token); | 449 invalidator->UpdateCredentials(credentials.email, credentials.sync_token); |
451 scoped_ptr<InvalidatorShim> shim(new InvalidatorShim(sync_manager.get())); | 450 std::unique_ptr<InvalidatorShim> shim( |
| 451 new InvalidatorShim(sync_manager.get())); |
452 invalidator->RegisterHandler(shim.get()); | 452 invalidator->RegisterHandler(shim.get()); |
453 CHECK(invalidator->UpdateRegisteredIds( | 453 CHECK(invalidator->UpdateRegisteredIds( |
454 shim.get(), ModelTypeSetToObjectIdSet(model_types))); | 454 shim.get(), ModelTypeSetToObjectIdSet(model_types))); |
455 sync_manager->StartSyncingNormally(routing_info, base::Time()); | 455 sync_manager->StartSyncingNormally(routing_info, base::Time()); |
456 | 456 |
457 sync_loop.Run(); | 457 sync_loop.Run(); |
458 | 458 |
459 io_thread.Stop(); | 459 io_thread.Stop(); |
460 return 0; | 460 return 0; |
461 } | 461 } |
462 | 462 |
463 } // namespace | 463 } // namespace |
464 } // namespace syncer | 464 } // namespace syncer |
465 | 465 |
466 int main(int argc, char* argv[]) { | 466 int main(int argc, char* argv[]) { |
467 return syncer::SyncClientMain(argc, argv); | 467 return syncer::SyncClientMain(argc, argv); |
468 } | 468 } |
OLD | NEW |