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 "components/sync/core_impl/sync_manager_impl.h" | 5 #include "components/sync/engine_impl/sync_manager_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "components/sync/base/cancelation_signal.h" | 23 #include "components/sync/base/cancelation_signal.h" |
24 #include "components/sync/base/experiments.h" | 24 #include "components/sync/base/experiments.h" |
25 #include "components/sync/base/invalidation_interface.h" | 25 #include "components/sync/base/invalidation_interface.h" |
26 #include "components/sync/base/model_type.h" | 26 #include "components/sync/base/model_type.h" |
27 #include "components/sync/core/configure_reason.h" | 27 #include "components/sync/engine/configure_reason.h" |
28 #include "components/sync/core/internal_components_factory.h" | 28 #include "components/sync/engine/engine_components_factory.h" |
29 #include "components/sync/core_impl/model_type_connector_proxy.h" | 29 #include "components/sync/engine/engine_util.h" |
30 #include "components/sync/core_impl/syncapi_internal.h" | |
31 #include "components/sync/engine/net/http_post_provider_factory.h" | 30 #include "components/sync/engine/net/http_post_provider_factory.h" |
32 #include "components/sync/engine/polling_constants.h" | 31 #include "components/sync/engine/polling_constants.h" |
33 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h" | 32 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h" |
| 33 #include "components/sync/engine_impl/model_type_connector_proxy.h" |
34 #include "components/sync/engine_impl/net/sync_server_connection_manager.h" | 34 #include "components/sync/engine_impl/net/sync_server_connection_manager.h" |
35 #include "components/sync/engine_impl/sync_scheduler.h" | 35 #include "components/sync/engine_impl/sync_scheduler.h" |
36 #include "components/sync/engine_impl/syncer_types.h" | 36 #include "components/sync/engine_impl/syncer_types.h" |
37 #include "components/sync/protocol/proto_value_conversions.h" | 37 #include "components/sync/protocol/proto_value_conversions.h" |
38 #include "components/sync/protocol/sync.pb.h" | 38 #include "components/sync/protocol/sync.pb.h" |
39 #include "components/sync/syncable/base_node.h" | 39 #include "components/sync/syncable/base_node.h" |
40 #include "components/sync/syncable/directory.h" | 40 #include "components/sync/syncable/directory.h" |
41 #include "components/sync/syncable/entry.h" | 41 #include "components/sync/syncable/entry.h" |
42 #include "components/sync/syncable/in_memory_directory_backing_store.h" | 42 #include "components/sync/syncable/in_memory_directory_backing_store.h" |
43 #include "components/sync/syncable/on_disk_directory_backing_store.h" | 43 #include "components/sync/syncable/on_disk_directory_backing_store.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 &share_, args->encryptor, args->restored_key_for_bootstrapping, | 244 &share_, args->encryptor, args->restored_key_for_bootstrapping, |
245 args->restored_keystore_key_for_bootstrapping)); | 245 args->restored_keystore_key_for_bootstrapping)); |
246 sync_encryption_handler_->AddObserver(this); | 246 sync_encryption_handler_->AddObserver(this); |
247 sync_encryption_handler_->AddObserver(&debug_info_event_listener_); | 247 sync_encryption_handler_->AddObserver(&debug_info_event_listener_); |
248 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); | 248 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); |
249 | 249 |
250 base::FilePath absolute_db_path = database_path_; | 250 base::FilePath absolute_db_path = database_path_; |
251 DCHECK(absolute_db_path.IsAbsolute()); | 251 DCHECK(absolute_db_path.IsAbsolute()); |
252 | 252 |
253 std::unique_ptr<syncable::DirectoryBackingStore> backing_store = | 253 std::unique_ptr<syncable::DirectoryBackingStore> backing_store = |
254 args->internal_components_factory->BuildDirectoryBackingStore( | 254 args->engine_components_factory->BuildDirectoryBackingStore( |
255 InternalComponentsFactory::STORAGE_ON_DISK, | 255 EngineComponentsFactory::STORAGE_ON_DISK, |
256 args->credentials.account_id, absolute_db_path); | 256 args->credentials.account_id, absolute_db_path); |
257 | 257 |
258 DCHECK(backing_store.get()); | 258 DCHECK(backing_store.get()); |
259 share_.directory.reset(new syncable::Directory( | 259 share_.directory.reset(new syncable::Directory( |
260 backing_store.release(), args->unrecoverable_error_handler, | 260 backing_store.release(), args->unrecoverable_error_handler, |
261 report_unrecoverable_error_function_, sync_encryption_handler_.get(), | 261 report_unrecoverable_error_function_, sync_encryption_handler_.get(), |
262 sync_encryption_handler_->GetCryptographerUnsafe())); | 262 sync_encryption_handler_->GetCryptographerUnsafe())); |
263 share_.sync_credentials = args->credentials; | 263 share_.sync_credentials = args->credentials; |
264 | 264 |
265 // UserShare is accessible to a lot of code that doesn't need access to the | 265 // UserShare is accessible to a lot of code that doesn't need access to the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 model_type_registry_.reset( | 299 model_type_registry_.reset( |
300 new ModelTypeRegistry(args->workers, directory(), this)); | 300 new ModelTypeRegistry(args->workers, directory(), this)); |
301 sync_encryption_handler_->AddObserver(model_type_registry_.get()); | 301 sync_encryption_handler_->AddObserver(model_type_registry_.get()); |
302 | 302 |
303 // Build a SyncCycleContext and store the worker in it. | 303 // Build a SyncCycleContext and store the worker in it. |
304 DVLOG(1) << "Sync is bringing up SyncCycleContext."; | 304 DVLOG(1) << "Sync is bringing up SyncCycleContext."; |
305 std::vector<SyncEngineEventListener*> listeners; | 305 std::vector<SyncEngineEventListener*> listeners; |
306 listeners.push_back(&allstatus_); | 306 listeners.push_back(&allstatus_); |
307 listeners.push_back(this); | 307 listeners.push_back(this); |
308 cycle_context_ = args->internal_components_factory->BuildContext( | 308 cycle_context_ = args->engine_components_factory->BuildContext( |
309 connection_manager_.get(), directory(), args->extensions_activity, | 309 connection_manager_.get(), directory(), args->extensions_activity, |
310 listeners, &debug_info_event_listener_, model_type_registry_.get(), | 310 listeners, &debug_info_event_listener_, model_type_registry_.get(), |
311 args->invalidator_client_id); | 311 args->invalidator_client_id); |
312 scheduler_ = args->internal_components_factory->BuildScheduler( | 312 scheduler_ = args->engine_components_factory->BuildScheduler( |
313 name_, cycle_context_.get(), args->cancelation_signal); | 313 name_, cycle_context_.get(), args->cancelation_signal); |
314 | 314 |
315 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 315 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); |
316 | 316 |
317 initialized_ = true; | 317 initialized_ = true; |
318 | 318 |
319 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 319 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
320 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 320 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
321 observing_network_connectivity_changes_ = true; | 321 observing_network_connectivity_changes_ = true; |
322 | 322 |
323 UpdateCredentials(args->credentials); | 323 UpdateCredentials(args->credentials); |
324 | 324 |
325 NotifyInitializationSuccess(); | 325 NotifyInitializationSuccess(); |
326 } | 326 } |
327 | 327 |
328 void SyncManagerImpl::NotifyInitializationSuccess() { | 328 void SyncManagerImpl::NotifyInitializationSuccess() { |
329 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 329 for (auto& observer : observers_) { |
330 OnInitializationComplete( | 330 observer.OnInitializationComplete( |
331 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 331 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
332 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), | 332 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), true, |
333 true, InitialSyncEndedTypes())); | 333 InitialSyncEndedTypes()); |
| 334 } |
334 } | 335 } |
335 | 336 |
336 void SyncManagerImpl::NotifyInitializationFailure() { | 337 void SyncManagerImpl::NotifyInitializationFailure() { |
337 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 338 for (auto& observer : observers_) { |
338 OnInitializationComplete( | 339 observer.OnInitializationComplete( |
339 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 340 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
340 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), | 341 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), false, |
341 false, ModelTypeSet())); | 342 ModelTypeSet()); |
| 343 } |
342 } | 344 } |
343 | 345 |
344 void SyncManagerImpl::OnPassphraseRequired( | 346 void SyncManagerImpl::OnPassphraseRequired( |
345 PassphraseRequiredReason reason, | 347 PassphraseRequiredReason reason, |
346 const sync_pb::EncryptedData& pending_keys) { | 348 const sync_pb::EncryptedData& pending_keys) { |
347 // Does nothing. | 349 // Does nothing. |
348 } | 350 } |
349 | 351 |
350 void SyncManagerImpl::OnPassphraseAccepted() { | 352 void SyncManagerImpl::OnPassphraseAccepted() { |
351 // Does nothing. | 353 // Does nothing. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 574 |
573 void SyncManagerImpl::OnNetworkConnectivityChangedImpl() { | 575 void SyncManagerImpl::OnNetworkConnectivityChangedImpl() { |
574 DCHECK(thread_checker_.CalledOnValidThread()); | 576 DCHECK(thread_checker_.CalledOnValidThread()); |
575 scheduler_->OnConnectionStatusChange(); | 577 scheduler_->OnConnectionStatusChange(); |
576 } | 578 } |
577 | 579 |
578 void SyncManagerImpl::OnServerConnectionEvent( | 580 void SyncManagerImpl::OnServerConnectionEvent( |
579 const ServerConnectionEvent& event) { | 581 const ServerConnectionEvent& event) { |
580 DCHECK(thread_checker_.CalledOnValidThread()); | 582 DCHECK(thread_checker_.CalledOnValidThread()); |
581 if (event.connection_code == HttpResponse::SERVER_CONNECTION_OK) { | 583 if (event.connection_code == HttpResponse::SERVER_CONNECTION_OK) { |
582 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 584 for (auto& observer : observers_) { |
583 OnConnectionStatusChange(CONNECTION_OK)); | 585 observer.OnConnectionStatusChange(CONNECTION_OK); |
| 586 } |
584 } | 587 } |
585 | 588 |
586 if (event.connection_code == HttpResponse::SYNC_AUTH_ERROR) { | 589 if (event.connection_code == HttpResponse::SYNC_AUTH_ERROR) { |
587 observing_network_connectivity_changes_ = false; | 590 observing_network_connectivity_changes_ = false; |
588 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 591 for (auto& observer : observers_) { |
589 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); | 592 observer.OnConnectionStatusChange(CONNECTION_AUTH_ERROR); |
| 593 } |
590 } | 594 } |
591 | 595 |
592 if (event.connection_code == HttpResponse::SYNC_SERVER_ERROR) { | 596 if (event.connection_code == HttpResponse::SYNC_SERVER_ERROR) { |
593 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 597 for (auto& observer : observers_) { |
594 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); | 598 observer.OnConnectionStatusChange(CONNECTION_SERVER_ERROR); |
| 599 } |
595 } | 600 } |
596 } | 601 } |
597 | 602 |
598 void SyncManagerImpl::HandleTransactionCompleteChangeEvent( | 603 void SyncManagerImpl::HandleTransactionCompleteChangeEvent( |
599 ModelTypeSet models_with_changes) { | 604 ModelTypeSet models_with_changes) { |
600 // This notification happens immediately after the transaction mutex is | 605 // This notification happens immediately after the transaction mutex is |
601 // released. This allows work to be performed without blocking other threads | 606 // released. This allows work to be performed without blocking other threads |
602 // from acquiring a transaction. | 607 // from acquiring a transaction. |
603 if (!change_delegate_) | 608 if (!change_delegate_) |
604 return; | 609 return; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 // Notifications are sent at the end of every sync cycle, regardless of | 815 // Notifications are sent at the end of every sync cycle, regardless of |
811 // whether we should sync again. | 816 // whether we should sync again. |
812 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { | 817 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { |
813 if (!initialized_) { | 818 if (!initialized_) { |
814 DVLOG(1) << "OnSyncCycleCompleted not sent because sync api is not " | 819 DVLOG(1) << "OnSyncCycleCompleted not sent because sync api is not " |
815 << "initialized"; | 820 << "initialized"; |
816 return; | 821 return; |
817 } | 822 } |
818 | 823 |
819 DVLOG(1) << "Sending OnSyncCycleCompleted"; | 824 DVLOG(1) << "Sending OnSyncCycleCompleted"; |
820 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 825 for (auto& observer : observers_) { |
821 OnSyncCycleCompleted(event.snapshot)); | 826 observer.OnSyncCycleCompleted(event.snapshot); |
| 827 } |
822 } | 828 } |
823 } | 829 } |
824 | 830 |
825 void SyncManagerImpl::OnActionableError(const SyncProtocolError& error) { | 831 void SyncManagerImpl::OnActionableError(const SyncProtocolError& error) { |
826 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 832 for (auto& observer : observers_) { |
827 OnActionableError(error)); | 833 observer.OnActionableError(error); |
| 834 } |
828 } | 835 } |
829 | 836 |
830 void SyncManagerImpl::OnRetryTimeChanged(base::Time) {} | 837 void SyncManagerImpl::OnRetryTimeChanged(base::Time) {} |
831 | 838 |
832 void SyncManagerImpl::OnThrottledTypesChanged(ModelTypeSet) {} | 839 void SyncManagerImpl::OnThrottledTypesChanged(ModelTypeSet) {} |
833 | 840 |
834 void SyncManagerImpl::OnMigrationRequested(ModelTypeSet types) { | 841 void SyncManagerImpl::OnMigrationRequested(ModelTypeSet types) { |
835 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 842 for (auto& observer : observers_) { |
836 OnMigrationRequested(types)); | 843 observer.OnMigrationRequested(types); |
| 844 } |
837 } | 845 } |
838 | 846 |
839 void SyncManagerImpl::OnProtocolEvent(const ProtocolEvent& event) { | 847 void SyncManagerImpl::OnProtocolEvent(const ProtocolEvent& event) { |
840 protocol_event_buffer_.RecordProtocolEvent(event); | 848 protocol_event_buffer_.RecordProtocolEvent(event); |
841 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnProtocolEvent(event)); | 849 for (auto& observer : observers_) { |
| 850 observer.OnProtocolEvent(event); |
| 851 } |
842 } | 852 } |
843 | 853 |
844 void SyncManagerImpl::SetJsEventHandler( | 854 void SyncManagerImpl::SetJsEventHandler( |
845 const WeakHandle<JsEventHandler>& event_handler) { | 855 const WeakHandle<JsEventHandler>& event_handler) { |
846 js_sync_manager_observer_.SetJsEventHandler(event_handler); | 856 js_sync_manager_observer_.SetJsEventHandler(event_handler); |
847 js_mutation_event_observer_.SetJsEventHandler(event_handler); | 857 js_mutation_event_observer_.SetJsEventHandler(event_handler); |
848 js_sync_encryption_handler_observer_.SetJsEventHandler(event_handler); | 858 js_sync_encryption_handler_observer_.SetJsEventHandler(event_handler); |
849 } | 859 } |
850 | 860 |
851 void SyncManagerImpl::SetInvalidatorEnabled(bool invalidator_enabled) { | 861 void SyncManagerImpl::SetInvalidatorEnabled(bool invalidator_enabled) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 } | 995 } |
986 | 996 |
987 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, | 997 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, |
988 bool empty_jar) { | 998 bool empty_jar) { |
989 DCHECK(thread_checker_.CalledOnValidThread()); | 999 DCHECK(thread_checker_.CalledOnValidThread()); |
990 cycle_context_->set_cookie_jar_mismatch(account_mismatch); | 1000 cycle_context_->set_cookie_jar_mismatch(account_mismatch); |
991 cycle_context_->set_cookie_jar_empty(empty_jar); | 1001 cycle_context_->set_cookie_jar_empty(empty_jar); |
992 } | 1002 } |
993 | 1003 |
994 } // namespace syncer | 1004 } // namespace syncer |
OLD | NEW |