Chromium Code Reviews| 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool SyncManagerImpl::Init( | 364 bool SyncManagerImpl::Init( |
| 365 const FilePath& database_location, | 365 const FilePath& database_location, |
| 366 const WeakHandle<JsEventHandler>& event_handler, | 366 const WeakHandle<JsEventHandler>& event_handler, |
| 367 const std::string& sync_server_and_path, | 367 const std::string& sync_server_and_path, |
| 368 int port, | 368 int port, |
| 369 bool use_ssl, | 369 bool use_ssl, |
| 370 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 370 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 371 scoped_ptr<HttpPostProviderFactory> post_factory, | 371 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 372 const ModelSafeRoutingInfo& model_safe_routing_info, | |
| 373 const std::vector<ModelSafeWorker*>& workers, | 372 const std::vector<ModelSafeWorker*>& workers, |
| 374 ExtensionsActivityMonitor* extensions_activity_monitor, | 373 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 375 SyncManager::ChangeDelegate* change_delegate, | 374 SyncManager::ChangeDelegate* change_delegate, |
| 376 const SyncCredentials& credentials, | 375 const SyncCredentials& credentials, |
| 377 scoped_ptr<SyncNotifier> sync_notifier, | 376 scoped_ptr<SyncNotifier> sync_notifier, |
| 378 const std::string& restored_key_for_bootstrapping, | 377 const std::string& restored_key_for_bootstrapping, |
| 379 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 378 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 380 Encryptor* encryptor, | 379 Encryptor* encryptor, |
| 381 UnrecoverableErrorHandler* unrecoverable_error_handler, | 380 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 382 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 381 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 383 CHECK(!initialized_); | 382 CHECK(!initialized_); |
| 384 DCHECK(thread_checker_.CalledOnValidThread()); | 383 DCHECK(thread_checker_.CalledOnValidThread()); |
| 385 DCHECK(post_factory.get()); | 384 DCHECK(post_factory.get()); |
| 385 DCHECK(!credentials.email.empty()); | |
| 386 DCHECK(!credentials.sync_token.empty()); | |
| 386 DVLOG(1) << "SyncManager starting Init..."; | 387 DVLOG(1) << "SyncManager starting Init..."; |
| 387 | 388 |
| 388 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 389 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
| 389 | 390 |
| 390 blocking_task_runner_ = blocking_task_runner; | 391 blocking_task_runner_ = blocking_task_runner; |
| 391 | 392 |
| 392 change_delegate_ = change_delegate; | 393 change_delegate_ = change_delegate; |
| 393 | 394 |
| 394 sync_notifier_ = sync_notifier.Pass(); | 395 sync_notifier_ = sync_notifier.Pass(); |
| 395 | 396 |
| 396 AddObserver(&js_sync_manager_observer_); | 397 AddObserver(&js_sync_manager_observer_); |
| 397 SetJsEventHandler(event_handler); | 398 SetJsEventHandler(event_handler); |
| 398 | 399 |
| 399 AddObserver(&debug_info_event_listener_); | 400 AddObserver(&debug_info_event_listener_); |
| 400 | 401 |
| 401 database_path_ = database_location.Append( | 402 database_path_ = database_location.Append( |
| 402 syncable::Directory::kSyncDatabaseFilename); | 403 syncable::Directory::kSyncDatabaseFilename); |
| 403 encryptor_ = encryptor; | 404 encryptor_ = encryptor; |
| 404 unrecoverable_error_handler_ = unrecoverable_error_handler; | 405 unrecoverable_error_handler_ = unrecoverable_error_handler; |
| 405 report_unrecoverable_error_function_ = report_unrecoverable_error_function; | 406 report_unrecoverable_error_function_ = report_unrecoverable_error_function; |
| 406 | 407 |
| 407 FilePath absolute_db_path(database_path_); | 408 FilePath absolute_db_path(database_path_); |
| 408 file_util::AbsolutePath(&absolute_db_path); | 409 file_util::AbsolutePath(&absolute_db_path); |
| 409 scoped_ptr<syncable::DirectoryBackingStore> backing_store = | 410 scoped_ptr<syncable::DirectoryBackingStore> backing_store = |
| 410 internal_components_factory->BuildDirectoryBackingStore( | 411 internal_components_factory->BuildDirectoryBackingStore( |
| 411 credentials.email, absolute_db_path).Pass(); | 412 credentials.email, absolute_db_path).Pass(); |
| 412 | 413 |
| 413 DCHECK(backing_store.get()); | 414 DCHECK(backing_store.get()); |
| 415 share_.name = credentials.email; | |
|
rlarocque
2012/07/25 18:45:08
Formerly part of SignIn()
| |
| 414 share_.directory.reset( | 416 share_.directory.reset( |
| 415 new syncable::Directory(encryptor_, | 417 new syncable::Directory(encryptor_, |
| 416 unrecoverable_error_handler_, | 418 unrecoverable_error_handler_, |
| 417 report_unrecoverable_error_function_, | 419 report_unrecoverable_error_function_, |
| 418 backing_store.release())); | 420 backing_store.release())); |
| 419 | 421 |
| 420 connection_manager_.reset(new SyncAPIServerConnectionManager( | 422 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 421 sync_server_and_path, port, use_ssl, post_factory.release())); | 423 sync_server_and_path, port, use_ssl, post_factory.release())); |
| 422 | 424 |
| 423 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 425 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 424 observing_ip_address_changes_ = true; | 426 observing_ip_address_changes_ = true; |
| 425 | 427 |
| 426 connection_manager_->AddListener(this); | 428 connection_manager_->AddListener(this); |
| 427 | 429 |
| 428 // Build a SyncSessionContext and store the worker in it. | 430 DVLOG(1) << "Username: " << username_for_share(); |
|
rlarocque
2012/07/25 18:45:08
Inlined SignIn code begins here.
| |
| 429 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 431 bool success = OpenDirectory(); |
| 430 std::vector<SyncEngineEventListener*> listeners; | 432 if (success) { |
|
tim (not reviewing)
2012/07/26 18:48:05
I know this code did if (success) { before, but no
rlarocque
2012/07/26 21:59:54
Good idea.
| |
| 431 listeners.push_back(&allstatus_); | 433 // Retrieve and set the sync notifier state. |
| 432 listeners.push_back(this); | 434 std::string unique_id = directory()->cache_guid(); |
| 433 session_context_ = internal_components_factory->BuildContext( | 435 DVLOG(1) << "Read notification unique ID: " << unique_id; |
| 434 connection_manager_.get(), | 436 allstatus_.SetUniqueId(unique_id); |
| 435 directory(), | 437 sync_notifier_->SetUniqueId(unique_id); |
| 436 model_safe_routing_info, | |
| 437 workers, | |
| 438 extensions_activity_monitor, | |
| 439 &throttled_data_type_tracker_, | |
| 440 listeners, | |
| 441 &debug_info_event_listener_, | |
| 442 &traffic_recorder_).Pass(); | |
| 443 session_context_->set_account_name(credentials.email); | |
| 444 scheduler_ = internal_components_factory->BuildScheduler( | |
| 445 name_, session_context_.get()).Pass(); | |
| 446 | 438 |
| 447 bool success = SignIn(credentials); | 439 std::string state = directory()->GetNotificationState(); |
| 440 if (VLOG_IS_ON(1)) { | |
| 441 std::string encoded_state; | |
| 442 base::Base64Encode(state, &encoded_state); | |
| 443 DVLOG(1) << "Read notification state: " << encoded_state; | |
| 444 } | |
| 448 | 445 |
| 449 if (success) { | 446 // TODO(tim): Remove once invalidation state has been migrated to new |
| 447 // InvalidationStateTracker store. Bug 124140. | |
| 448 sync_notifier_->SetStateDeprecated(state); | |
| 449 | |
| 450 connection_manager_->set_auth_token(credentials.sync_token); | |
|
rlarocque
2012/07/25 18:45:08
These two lines are effectively what UpdateCredent
tim (not reviewing)
2012/07/26 18:48:05
What is the benefit of not calling UpdateCredentia
rlarocque
2012/07/26 21:59:54
It's debatable. The arguments for are:
- UpdateCr
| |
| 451 sync_notifier_->UpdateCredentials(credentials.email, | |
|
rlarocque
2012/07/25 18:45:08
I think it's safe to initialize the sync_notifier
tim (not reviewing)
2012/07/26 18:48:05
I think this is okay too - the call to AddObserver
| |
| 452 credentials.sync_token); | |
| 453 | |
| 454 // Build a SyncSessionContext and store the worker in it. | |
| 455 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | |
| 456 std::vector<SyncEngineEventListener*> listeners; | |
| 457 listeners.push_back(&allstatus_); | |
| 458 listeners.push_back(this); | |
| 459 session_context_ = internal_components_factory->BuildContext( | |
|
rlarocque
2012/07/25 18:45:08
Warning: Real code change here.
We used to create
tim (not reviewing)
2012/07/26 18:48:05
Agreed, it would be strange if we were relying on
| |
| 460 connection_manager_.get(), | |
| 461 directory(), | |
| 462 workers, | |
| 463 extensions_activity_monitor, | |
| 464 &throttled_data_type_tracker_, | |
| 465 listeners, | |
| 466 &debug_info_event_listener_, | |
| 467 &traffic_recorder_).Pass(); | |
| 468 session_context_->set_account_name(credentials.email); | |
| 469 scheduler_ = internal_components_factory->BuildScheduler( | |
| 470 name_, session_context_.get()).Pass(); | |
| 471 | |
| 450 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); | 472 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
| 451 | 473 |
| 452 initialized_ = true; | 474 initialized_ = true; |
| 453 | 475 |
| 454 // Unapplied datatypes (those that do not have initial sync ended set) get | 476 // Unapplied datatypes (those that do not have initial sync ended set) get |
| 455 // re-downloaded during any configuration. But, it's possible for a datatype | 477 // re-downloaded during any configuration. But, it's possible for a datatype |
| 456 // to have a progress marker but not have initial sync ended yet, making | 478 // to have a progress marker but not have initial sync ended yet, making |
| 457 // it a candidate for migration. This is a problem, as the DataTypeManager | 479 // it a candidate for migration. This is a problem, as the DataTypeManager |
| 458 // does not support a migration while it's already in the middle of a | 480 // does not support a migration while it's already in the middle of a |
| 459 // configuration. As a result, any partially synced datatype can stall the | 481 // configuration. As a result, any partially synced datatype can stall the |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 475 } | 497 } |
| 476 | 498 |
| 477 // Notify that initialization is complete. Note: This should be the last to | 499 // Notify that initialization is complete. Note: This should be the last to |
| 478 // execute if |signed_in| is false. Reason being in that case we would | 500 // execute if |signed_in| is false. Reason being in that case we would |
| 479 // post a task to shutdown sync. But if this function posts any other tasks | 501 // post a task to shutdown sync. But if this function posts any other tasks |
| 480 // on the UI thread and if shutdown wins then that tasks would execute on | 502 // on the UI thread and if shutdown wins then that tasks would execute on |
| 481 // a freed pointer. This is because UI thread is not shut down. | 503 // a freed pointer. This is because UI thread is not shut down. |
| 482 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 504 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 483 OnInitializationComplete( | 505 OnInitializationComplete( |
| 484 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 506 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 485 success)); | 507 success, success ? InitialSyncEndedTypes() |
| 508 : syncer::ModelTypeSet())); | |
| 486 if (!success) | 509 if (!success) |
| 487 return false; | 510 return false; |
| 488 | 511 |
| 489 sync_notifier_->AddObserver(this); | 512 sync_notifier_->AddObserver(this); |
| 490 | 513 |
| 491 return success; | 514 return success; |
| 492 } | 515 } |
| 493 | 516 |
| 494 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 517 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| 495 const base::Closure& done_callback) { | 518 const base::Closure& done_callback) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 transaction_observer); | 684 transaction_observer); |
| 662 if (open_result != syncable::OPENED) { | 685 if (open_result != syncable::OPENED) { |
| 663 LOG(ERROR) << "Could not open share for:" << username_for_share(); | 686 LOG(ERROR) << "Could not open share for:" << username_for_share(); |
| 664 return false; | 687 return false; |
| 665 } | 688 } |
| 666 | 689 |
| 667 connection_manager_->set_client_id(directory()->cache_guid()); | 690 connection_manager_->set_client_id(directory()->cache_guid()); |
| 668 return true; | 691 return true; |
| 669 } | 692 } |
| 670 | 693 |
| 671 bool SyncManagerImpl::SignIn(const SyncCredentials& credentials) { | |
| 672 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 673 DCHECK(share_.name.empty()); | |
| 674 share_.name = credentials.email; | |
| 675 | |
| 676 DVLOG(1) << "Signing in user: " << username_for_share(); | |
| 677 if (!OpenDirectory()) | |
| 678 return false; | |
| 679 | |
| 680 // Retrieve and set the sync notifier state. This should be done | |
| 681 // only after OpenDirectory is called. | |
| 682 std::string unique_id = directory()->cache_guid(); | |
| 683 std::string state = directory()->GetNotificationState(); | |
| 684 DVLOG(1) << "Read notification unique ID: " << unique_id; | |
| 685 if (VLOG_IS_ON(1)) { | |
| 686 std::string encoded_state; | |
| 687 base::Base64Encode(state, &encoded_state); | |
| 688 DVLOG(1) << "Read notification state: " << encoded_state; | |
| 689 } | |
| 690 allstatus_.SetUniqueId(unique_id); | |
| 691 sync_notifier_->SetUniqueId(unique_id); | |
| 692 // TODO(tim): Remove once invalidation state has been migrated to new | |
| 693 // InvalidationStateTracker store. Bug 124140. | |
| 694 sync_notifier_->SetStateDeprecated(state); | |
| 695 | |
| 696 UpdateCredentials(credentials); | |
| 697 return true; | |
| 698 } | |
| 699 | |
| 700 bool SyncManagerImpl::PurgePartiallySyncedTypes() { | 694 bool SyncManagerImpl::PurgePartiallySyncedTypes() { |
| 701 ModelTypeSet partially_synced_types = ModelTypeSet::All(); | 695 ModelTypeSet partially_synced_types = ModelTypeSet::All(); |
| 702 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); | 696 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); |
| 703 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( | 697 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( |
| 704 ModelTypeSet::All())); | 698 ModelTypeSet::All())); |
| 705 | 699 |
| 706 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 700 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
| 707 partially_synced_types.Size()); | 701 partially_synced_types.Size()); |
| 708 if (partially_synced_types.Empty()) | 702 if (partially_synced_types.Empty()) |
| 709 return true; | 703 return true; |
| (...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1885 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1892 return kDefaultNudgeDelayMilliseconds; | 1886 return kDefaultNudgeDelayMilliseconds; |
| 1893 } | 1887 } |
| 1894 | 1888 |
| 1895 // static. | 1889 // static. |
| 1896 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1890 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1897 return kPreferencesNudgeDelayMilliseconds; | 1891 return kPreferencesNudgeDelayMilliseconds; |
| 1898 } | 1892 } |
| 1899 | 1893 |
| 1900 } // namespace syncer | 1894 } // namespace syncer |
| OLD | NEW |