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 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 } | 1521 } |
1522 | 1522 |
1523 bool ProfileSyncService::CanConfigureDataTypes() const { | 1523 bool ProfileSyncService::CanConfigureDataTypes() const { |
1524 return IsFirstSetupComplete() && !IsSetupInProgress(); | 1524 return IsFirstSetupComplete() && !IsSetupInProgress(); |
1525 } | 1525 } |
1526 | 1526 |
1527 bool ProfileSyncService::IsFirstSetupInProgress() const { | 1527 bool ProfileSyncService::IsFirstSetupInProgress() const { |
1528 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); | 1528 return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); |
1529 } | 1529 } |
1530 | 1530 |
1531 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { | 1531 std::unique_ptr<sync_driver::SyncSetupInProgressHandle> |
1532 // This method is a no-op if |setup_in_progress_| remains unchanged. | 1532 ProfileSyncService::GetSetupInProgressHandle() { |
1533 if (startup_controller_->IsSetupInProgress() == setup_in_progress) | 1533 if (++outstanding_setup_in_progress_handles_ == 1) { |
1534 return; | 1534 DCHECK(!startup_controller_->IsSetupInProgress()); |
| 1535 startup_controller_->SetSetupInProgress(true); |
1535 | 1536 |
1536 startup_controller_->SetSetupInProgress(setup_in_progress); | 1537 NotifyObservers(); |
1537 if (!setup_in_progress && IsBackendInitialized()) | 1538 } |
1538 ReconfigureDatatypeManager(); | 1539 |
1539 NotifyObservers(); | 1540 return std::unique_ptr<sync_driver::SyncSetupInProgressHandle>( |
| 1541 new sync_driver::SyncSetupInProgressHandle( |
| 1542 base::Bind(&ProfileSyncService::OnSetupInProgressHandleDestroyed, |
| 1543 weak_factory_.GetWeakPtr()))); |
1540 } | 1544 } |
1541 | 1545 |
1542 bool ProfileSyncService::IsSyncAllowed() const { | 1546 bool ProfileSyncService::IsSyncAllowed() const { |
1543 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); | 1547 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); |
1544 } | 1548 } |
1545 | 1549 |
1546 bool ProfileSyncService::IsSyncActive() const { | 1550 bool ProfileSyncService::IsSyncActive() const { |
1547 return backend_initialized_ && data_type_manager_ && | 1551 return backend_initialized_ && data_type_manager_ && |
1548 data_type_manager_->state() != DataTypeManager::STOPPED; | 1552 data_type_manager_->state() != DataTypeManager::STOPPED; |
1549 } | 1553 } |
(...skipping 987 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() { |
| 2553 DCHECK_GT(outstanding_setup_in_progress_handles_, 0); |
| 2554 |
| 2555 // Don't re-start Sync until all outstanding handles are destroyed. |
| 2556 if (--outstanding_setup_in_progress_handles_ != 0) |
| 2557 return; |
| 2558 |
| 2559 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2560 startup_controller_->SetSetupInProgress(false); |
| 2561 |
| 2562 if (IsBackendInitialized()) |
| 2563 ReconfigureDatatypeManager(); |
| 2564 NotifyObservers(); |
| 2565 } |
OLD | NEW |