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/browser_sync/browser/profile_sync_service.h" | 5 #include "components/browser_sync/browser/profile_sync_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1523 } | 1523 } |
1524 | 1524 |
1525 bool ProfileSyncService::CanConfigureDataTypes() const { | 1525 bool ProfileSyncService::CanConfigureDataTypes() const { |
1526 return IsFirstSetupComplete() && !IsSetupInProgress(); | 1526 return IsFirstSetupComplete() && !IsSetupInProgress(); |
1527 } | 1527 } |
1528 | 1528 |
1529 bool ProfileSyncService::IsFirstSetupInProgress() const { | 1529 bool ProfileSyncService::IsFirstSetupInProgress() const { |
1530 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); | 1530 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); |
1531 } | 1531 } |
1532 | 1532 |
1533 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { | 1533 std::unique_ptr<sync_driver::SyncSetupInProgressHandle> |
1534 // This method is a no-op if |setup_in_progress_| remains unchanged. | 1534 ProfileSyncService::GetSetupInProgressHandle() { |
1535 if (startup_controller_->IsSetupInProgress() == setup_in_progress) | 1535 if (++outstanding_setup_in_progress_handles_ == 1) { |
1536 return; | 1536 DCHECK(!startup_controller_->IsSetupInProgress()); |
1537 startup_controller_->SetSetupInProgress(true); | |
1537 | 1538 |
1538 startup_controller_->SetSetupInProgress(setup_in_progress); | 1539 NotifyObservers(); |
1539 if (!setup_in_progress && IsBackendInitialized()) | 1540 } |
1540 ReconfigureDatatypeManager(); | 1541 |
1541 NotifyObservers(); | 1542 return std::unique_ptr<sync_driver::SyncSetupInProgressHandle>( |
1543 new sync_driver::SyncSetupInProgressHandle( | |
1544 base::Bind(&ProfileSyncService::OnSetupInProgressHandleDestroyed, | |
1545 weak_factory_.GetWeakPtr()))); | |
1542 } | 1546 } |
1543 | 1547 |
1544 bool ProfileSyncService::IsSyncAllowed() const { | 1548 bool ProfileSyncService::IsSyncAllowed() const { |
1545 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); | 1549 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); |
1546 } | 1550 } |
1547 | 1551 |
1548 bool ProfileSyncService::IsSyncActive() const { | 1552 bool ProfileSyncService::IsSyncActive() const { |
1549 return backend_initialized_ && data_type_manager_ && | 1553 return backend_initialized_ && data_type_manager_ && |
1550 data_type_manager_->state() != DataTypeManager::STOPPED; | 1554 data_type_manager_->state() != DataTypeManager::STOPPED; |
1551 } | 1555 } |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2537 } | 2541 } |
2538 | 2542 |
2539 std::string ProfileSyncService::unrecoverable_error_message() const { | 2543 std::string ProfileSyncService::unrecoverable_error_message() const { |
2540 return unrecoverable_error_message_; | 2544 return unrecoverable_error_message_; |
2541 } | 2545 } |
2542 | 2546 |
2543 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() | 2547 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() |
2544 const { | 2548 const { |
2545 return unrecoverable_error_location_; | 2549 return unrecoverable_error_location_; |
2546 } | 2550 } |
2551 | |
2552 void ProfileSyncService::OnSetupInProgressHandleDestroyed() { | |
Nicolas Zea
2016/06/13 20:01:00
nit: maybe DCHECK that the counter never goes nega
tommycli
2016/06/13 20:27:31
Done.
| |
2553 // Don't re-start Sync until all outstanding handles are destroyed. | |
2554 if (--outstanding_setup_in_progress_handles_ != 0) | |
2555 return; | |
2556 | |
2557 DCHECK(startup_controller_->IsSetupInProgress()); | |
2558 startup_controller_->SetSetupInProgress(false); | |
2559 | |
2560 if (IsBackendInitialized()) | |
2561 ReconfigureDatatypeManager(); | |
2562 NotifyObservers(); | |
2563 } | |
OLD | NEW |