| 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 std::unique_ptr<sync_driver::SyncSetupInProgressHandle> | 1531 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { |
| 1532 ProfileSyncService::GetSetupInProgressHandle() { | 1532 // This method is a no-op if |setup_in_progress_| remains unchanged. |
| 1533 if (++outstanding_setup_in_progress_handles_ == 1) { | 1533 if (startup_controller_->IsSetupInProgress() == setup_in_progress) |
| 1534 DCHECK(!startup_controller_->IsSetupInProgress()); | 1534 return; |
| 1535 startup_controller_->SetSetupInProgress(true); | |
| 1536 | 1535 |
| 1537 NotifyObservers(); | 1536 startup_controller_->SetSetupInProgress(setup_in_progress); |
| 1538 } | 1537 if (!setup_in_progress && IsBackendInitialized()) |
| 1539 | 1538 ReconfigureDatatypeManager(); |
| 1540 return std::unique_ptr<sync_driver::SyncSetupInProgressHandle>( | 1539 NotifyObservers(); |
| 1541 new sync_driver::SyncSetupInProgressHandle( | |
| 1542 base::Bind(&ProfileSyncService::OnSetupInProgressHandleDestroyed, | |
| 1543 weak_factory_.GetWeakPtr()))); | |
| 1544 } | 1540 } |
| 1545 | 1541 |
| 1546 bool ProfileSyncService::IsSyncAllowed() const { | 1542 bool ProfileSyncService::IsSyncAllowed() const { |
| 1547 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); | 1543 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); |
| 1548 } | 1544 } |
| 1549 | 1545 |
| 1550 bool ProfileSyncService::IsSyncActive() const { | 1546 bool ProfileSyncService::IsSyncActive() const { |
| 1551 return backend_initialized_ && data_type_manager_ && | 1547 return backend_initialized_ && data_type_manager_ && |
| 1552 data_type_manager_->state() != DataTypeManager::STOPPED; | 1548 data_type_manager_->state() != DataTypeManager::STOPPED; |
| 1553 } | 1549 } |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2541 } | 2537 } |
| 2542 | 2538 |
| 2543 std::string ProfileSyncService::unrecoverable_error_message() const { | 2539 std::string ProfileSyncService::unrecoverable_error_message() const { |
| 2544 return unrecoverable_error_message_; | 2540 return unrecoverable_error_message_; |
| 2545 } | 2541 } |
| 2546 | 2542 |
| 2547 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() | 2543 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() |
| 2548 const { | 2544 const { |
| 2549 return unrecoverable_error_location_; | 2545 return unrecoverable_error_location_; |
| 2550 } | 2546 } |
| 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 |