| 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/core_impl/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "components/sync/core/http_post_provider_factory.h" | 31 #include "components/sync/core/http_post_provider_factory.h" |
| 32 #include "components/sync/core/internal_components_factory.h" | 32 #include "components/sync/core/internal_components_factory.h" |
| 33 #include "components/sync/core/read_node.h" | 33 #include "components/sync/core/read_node.h" |
| 34 #include "components/sync/core/read_transaction.h" | 34 #include "components/sync/core/read_transaction.h" |
| 35 #include "components/sync/core/user_share.h" | 35 #include "components/sync/core/user_share.h" |
| 36 #include "components/sync/core/write_node.h" | 36 #include "components/sync/core/write_node.h" |
| 37 #include "components/sync/core/write_transaction.h" | 37 #include "components/sync/core/write_transaction.h" |
| 38 #include "components/sync/core_impl/change_reorder_buffer.h" | 38 #include "components/sync/core_impl/change_reorder_buffer.h" |
| 39 #include "components/sync/core_impl/model_type_connector_proxy.h" | 39 #include "components/sync/core_impl/model_type_connector_proxy.h" |
| 40 #include "components/sync/core_impl/syncapi_internal.h" | 40 #include "components/sync/core_impl/syncapi_internal.h" |
| 41 #include "components/sync/core_impl/syncapi_server_connection_manager.h" | |
| 42 #include "components/sync/engine/polling_constants.h" | 41 #include "components/sync/engine/polling_constants.h" |
| 43 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h" | 42 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h" |
| 43 #include "components/sync/engine_impl/net/loopback_connection_manager.h" |
| 44 #include "components/sync/engine_impl/sync_scheduler.h" | 44 #include "components/sync/engine_impl/sync_scheduler.h" |
| 45 #include "components/sync/engine_impl/syncer_types.h" | 45 #include "components/sync/engine_impl/syncer_types.h" |
| 46 #include "components/sync/protocol/proto_value_conversions.h" | 46 #include "components/sync/protocol/proto_value_conversions.h" |
| 47 #include "components/sync/protocol/sync.pb.h" | 47 #include "components/sync/protocol/sync.pb.h" |
| 48 #include "components/sync/syncable/directory.h" | 48 #include "components/sync/syncable/directory.h" |
| 49 #include "components/sync/syncable/entry.h" | 49 #include "components/sync/syncable/entry.h" |
| 50 #include "components/sync/syncable/in_memory_directory_backing_store.h" | 50 #include "components/sync/syncable/in_memory_directory_backing_store.h" |
| 51 #include "components/sync/syncable/on_disk_directory_backing_store.h" | 51 #include "components/sync/syncable/on_disk_directory_backing_store.h" |
| 52 | 52 |
| 53 using base::TimeDelta; | 53 using base::TimeDelta; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 new_routing_info, ready_task, retry_task); | 215 new_routing_info, ready_task, retry_task); |
| 216 | 216 |
| 217 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 217 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); |
| 218 scheduler_->ScheduleConfiguration(params); | 218 scheduler_->ScheduleConfiguration(params); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void SyncManagerImpl::Init(InitArgs* args) { | 221 void SyncManagerImpl::Init(InitArgs* args) { |
| 222 CHECK(!initialized_); | 222 CHECK(!initialized_); |
| 223 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 DCHECK(args->post_factory.get()); | 224 DCHECK(args->post_factory.get()); |
| 225 DCHECK(!args->credentials.account_id.empty()); | 225 // ### Only run this when needed. |
| 226 DCHECK(!args->credentials.sync_token.empty()); | 226 //DCHECK(!args->credentials.account_id.empty()); |
| 227 DCHECK(!args->credentials.scope_set.empty()); | 227 //DCHECK(!args->credentials.sync_token.empty()); |
| 228 //DCHECK(!args->credentials.scope_set.empty()); |
| 228 DCHECK(args->cancelation_signal); | 229 DCHECK(args->cancelation_signal); |
| 229 DVLOG(1) << "SyncManager starting Init..."; | 230 DVLOG(1) << "SyncManager starting Init..."; |
| 230 | 231 |
| 231 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 232 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
| 232 | 233 |
| 233 change_delegate_ = args->change_delegate; | 234 change_delegate_ = args->change_delegate; |
| 234 | 235 |
| 235 AddObserver(&js_sync_manager_observer_); | 236 AddObserver(&js_sync_manager_observer_); |
| 236 SetJsEventHandler(args->event_handler); | 237 SetJsEventHandler(args->event_handler); |
| 237 | 238 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 return; | 279 return; |
| 279 } | 280 } |
| 280 | 281 |
| 281 // Now that we have opened the Directory we can restore any previously saved | 282 // Now that we have opened the Directory we can restore any previously saved |
| 282 // nigori specifics. | 283 // nigori specifics. |
| 283 if (args->saved_nigori_state) { | 284 if (args->saved_nigori_state) { |
| 284 sync_encryption_handler_->RestoreNigori(*args->saved_nigori_state); | 285 sync_encryption_handler_->RestoreNigori(*args->saved_nigori_state); |
| 285 args->saved_nigori_state.reset(); | 286 args->saved_nigori_state.reset(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 connection_manager_.reset(new SyncAPIServerConnectionManager( | 289 connection_manager_.reset(new LoopbackConnectionManager( |
| 289 args->service_url.host() + args->service_url.path(), | 290 directory(), args->cancelation_signal)); |
| 290 args->service_url.EffectiveIntPort(), | |
| 291 args->service_url.SchemeIsCryptographic(), args->post_factory.release(), | |
| 292 args->cancelation_signal)); | |
| 293 connection_manager_->set_client_id(directory()->cache_guid()); | 291 connection_manager_->set_client_id(directory()->cache_guid()); |
| 294 connection_manager_->AddListener(this); | 292 connection_manager_->AddListener(this); |
| 295 | 293 |
| 296 std::string sync_id = directory()->cache_guid(); | 294 std::string sync_id = directory()->cache_guid(); |
| 297 | 295 |
| 298 DVLOG(1) << "Setting sync client ID: " << sync_id; | 296 DVLOG(1) << "Setting sync client ID: " << sync_id; |
| 299 allstatus_.SetSyncId(sync_id); | 297 allstatus_.SetSyncId(sync_id); |
| 300 DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id; | 298 DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id; |
| 301 allstatus_.SetInvalidatorClientId(args->invalidator_client_id); | 299 allstatus_.SetInvalidatorClientId(args->invalidator_client_id); |
| 302 | 300 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 313 connection_manager_.get(), directory(), args->extensions_activity, | 311 connection_manager_.get(), directory(), args->extensions_activity, |
| 314 listeners, &debug_info_event_listener_, model_type_registry_.get(), | 312 listeners, &debug_info_event_listener_, model_type_registry_.get(), |
| 315 args->invalidator_client_id); | 313 args->invalidator_client_id); |
| 316 scheduler_ = args->internal_components_factory->BuildScheduler( | 314 scheduler_ = args->internal_components_factory->BuildScheduler( |
| 317 name_, cycle_context_.get(), args->cancelation_signal); | 315 name_, cycle_context_.get(), args->cancelation_signal); |
| 318 | 316 |
| 319 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 317 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); |
| 320 | 318 |
| 321 initialized_ = true; | 319 initialized_ = true; |
| 322 | 320 |
| 323 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 321 // ### Only when needed. |
| 324 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 322 // net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 325 observing_network_connectivity_changes_ = true; | 323 // net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 324 // observing_network_connectivity_changes_ = true; |
| 326 | 325 |
| 327 UpdateCredentials(args->credentials); | 326 UpdateCredentials(args->credentials); |
| 328 | 327 |
| 329 NotifyInitializationSuccess(); | 328 NotifyInitializationSuccess(); |
| 329 LOG(ERROR) << "SyncManagerImpl::Init finished"; |
| 330 } | 330 } |
| 331 | 331 |
| 332 void SyncManagerImpl::NotifyInitializationSuccess() { | 332 void SyncManagerImpl::NotifyInitializationSuccess() { |
| 333 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 333 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 334 OnInitializationComplete( | 334 OnInitializationComplete( |
| 335 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 335 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 336 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), | 336 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), |
| 337 true, InitialSyncEndedTypes())); | 337 true, InitialSyncEndedTypes())); |
| 338 } | 338 } |
| 339 | 339 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return true; | 470 return true; |
| 471 DVLOG(1) << "Purging disabled types " << ModelTypeSetToString(to_purge); | 471 DVLOG(1) << "Purging disabled types " << ModelTypeSetToString(to_purge); |
| 472 DCHECK(to_purge.HasAll(to_journal)); | 472 DCHECK(to_purge.HasAll(to_journal)); |
| 473 DCHECK(to_purge.HasAll(to_unapply)); | 473 DCHECK(to_purge.HasAll(to_unapply)); |
| 474 return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); | 474 return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); |
| 475 } | 475 } |
| 476 | 476 |
| 477 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { | 477 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { |
| 478 DCHECK(thread_checker_.CalledOnValidThread()); | 478 DCHECK(thread_checker_.CalledOnValidThread()); |
| 479 DCHECK(initialized_); | 479 DCHECK(initialized_); |
| 480 DCHECK(!credentials.account_id.empty()); | 480 // ### Only when needed. |
| 481 DCHECK(!credentials.sync_token.empty()); | 481 // DCHECK(!credentials.account_id.empty()); |
| 482 DCHECK(!credentials.scope_set.empty()); | 482 // DCHECK(!credentials.sync_token.empty()); |
| 483 // DCHECK(!credentials.scope_set.empty()); |
| 483 cycle_context_->set_account_name(credentials.email); | 484 cycle_context_->set_account_name(credentials.email); |
| 484 | 485 |
| 485 observing_network_connectivity_changes_ = true; | 486 // ### Why here again? |
| 487 // observing_network_connectivity_changes_ = true; |
| 486 if (!connection_manager_->SetAuthToken(credentials.sync_token)) | 488 if (!connection_manager_->SetAuthToken(credentials.sync_token)) |
| 487 return; // Auth token is known to be invalid, so exit early. | 489 return; // Auth token is known to be invalid, so exit early. |
| 488 | 490 |
| 489 scheduler_->OnCredentialsUpdated(); | 491 scheduler_->OnCredentialsUpdated(); |
| 490 | 492 |
| 491 // TODO(zea): pass the credential age to the debug info event listener. | 493 // TODO(zea): pass the credential age to the debug info event listener. |
| 492 } | 494 } |
| 493 | 495 |
| 494 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { | 496 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { |
| 495 DCHECK(thread_checker_.CalledOnValidThread()); | 497 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 } | 993 } |
| 992 | 994 |
| 993 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, | 995 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, |
| 994 bool empty_jar) { | 996 bool empty_jar) { |
| 995 DCHECK(thread_checker_.CalledOnValidThread()); | 997 DCHECK(thread_checker_.CalledOnValidThread()); |
| 996 cycle_context_->set_cookie_jar_mismatch(account_mismatch); | 998 cycle_context_->set_cookie_jar_mismatch(account_mismatch); |
| 997 cycle_context_->set_cookie_jar_empty(empty_jar); | 999 cycle_context_->set_cookie_jar_empty(empty_jar); |
| 998 } | 1000 } |
| 999 | 1001 |
| 1000 } // namespace syncer | 1002 } // namespace syncer |
| OLD | NEW |