| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_driver/backup_rollback_controller.h" | 5 #include "components/sync_driver/backup_rollback_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "components/sync_driver/signin_manager_wrapper.h" | 14 #include "components/sync_driver/signin_manager_wrapper.h" |
| 15 #include "components/sync_driver/sync_driver_features.h" | |
| 16 #include "components/sync_driver/sync_driver_switches.h" | 15 #include "components/sync_driver/sync_driver_switches.h" |
| 17 #include "components/sync_driver/sync_prefs.h" | 16 #include "components/sync_driver/sync_prefs.h" |
| 18 | 17 |
| 19 namespace sync_driver { | 18 namespace sync_driver { |
| 20 | 19 |
| 21 #if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) | 20 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 22 // Number of rollback attempts to try before giving up. | 21 // Number of rollback attempts to try before giving up. |
| 23 static const int kRollbackLimits = 3; | 22 static const int kRollbackLimits = 3; |
| 24 | 23 |
| 25 // Finch experiment name and group. | 24 // Finch experiment name and group. |
| 26 static char kSyncBackupFinchName[] = "SyncBackup"; | 25 static char kSyncBackupFinchName[] = "SyncBackup"; |
| 27 static char kSyncBackupFinchDisabled[] = "disabled"; | 26 static char kSyncBackupFinchDisabled[] = "disabled"; |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 BackupRollbackController::BackupRollbackController( | 29 BackupRollbackController::BackupRollbackController( |
| 31 sync_driver::SyncPrefs* sync_prefs, | 30 sync_driver::SyncPrefs* sync_prefs, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 int rollback_tries = sync_prefs_->GetRemainingRollbackTries(); | 64 int rollback_tries = sync_prefs_->GetRemainingRollbackTries(); |
| 66 if (rollback_tries <= 0) | 65 if (rollback_tries <= 0) |
| 67 return false; // No pending rollback. | 66 return false; // No pending rollback. |
| 68 | 67 |
| 69 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1); | 68 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1); |
| 70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_); | 69 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_); |
| 71 return true; | 70 return true; |
| 72 } | 71 } |
| 73 | 72 |
| 74 void BackupRollbackController::OnRollbackReceived() { | 73 void BackupRollbackController::OnRollbackReceived() { |
| 75 #if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) | 74 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 76 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits); | 75 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits); |
| 77 #endif | 76 #endif |
| 78 } | 77 } |
| 79 | 78 |
| 80 void BackupRollbackController::OnRollbackDone() { | 79 void BackupRollbackController::OnRollbackDone() { |
| 81 #if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) | 80 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 82 sync_prefs_->SetRemainingRollbackTries(0); | 81 sync_prefs_->SetRemainingRollbackTries(0); |
| 83 #endif | 82 #endif |
| 84 } | 83 } |
| 85 | 84 |
| 86 // static | 85 // static |
| 87 bool BackupRollbackController::IsBackupEnabled() { | 86 bool BackupRollbackController::IsBackupEnabled() { |
| 88 #if BUILDFLAG(ENABLE_PRE_SYNC_BACKUP) | 87 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 89 const std::string group_name = | 88 const std::string group_name = |
| 90 base::FieldTrialList::FindFullName(kSyncBackupFinchName); | 89 base::FieldTrialList::FindFullName(kSyncBackupFinchName); |
| 91 | 90 |
| 92 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 91 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 93 switches::kSyncDisableBackup) || | 92 switches::kSyncDisableBackup) || |
| 94 group_name == kSyncBackupFinchDisabled) { | 93 group_name == kSyncBackupFinchDisabled) { |
| 95 return false; | 94 return false; |
| 96 } | 95 } |
| 97 return true; | 96 return true; |
| 98 #else | 97 #else |
| 99 return false; | 98 return false; |
| 100 #endif | 99 #endif |
| 101 } | 100 } |
| 102 | 101 |
| 103 } // namespace sync_driver | 102 } // namespace sync_driver |
| OLD | NEW |