Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/backup_rollback_controller.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "chrome/browser/sync/managed_user_signin_manager_wrapper.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "components/sync_driver/sync_prefs.h" | |
| 12 | |
| 13 namespace browser_sync { | |
| 14 | |
| 15 // Number of rollback attempts to try before giving up. | |
| 16 static const int kRollbackLimits = 3; | |
| 17 | |
| 18 BackupRollbackController::BackupRollbackController( | |
| 19 sync_driver::SyncPrefs* sync_prefs, | |
| 20 const ManagedUserSigninManagerWrapper* signin, | |
| 21 base::Closure start_backup, | |
| 22 base::Closure start_rollback) | |
| 23 : sync_prefs_(sync_prefs), | |
| 24 signin_(signin), | |
| 25 start_backup_(start_backup), | |
| 26 start_rollback_(start_rollback), | |
| 27 weak_ptr_factory_(this) { | |
| 28 } | |
| 29 | |
| 30 BackupRollbackController::~BackupRollbackController() { | |
| 31 } | |
| 32 | |
| 33 void BackupRollbackController::Reset(base::TimeDelta delay) { | |
| 34 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
| 35 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 36 switches::kSyncEnableBackupRollback)) { | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 if (delay == base::TimeDelta()) { | |
| 41 TryStart(); | |
| 42 } else { | |
| 43 base::MessageLoop::current()->PostDelayedTask( | |
| 44 FROM_HERE, | |
| 45 base::Bind(&BackupRollbackController::TryStart, | |
| 46 weak_ptr_factory_.GetWeakPtr()), | |
| 47 delay); | |
| 48 } | |
| 49 #endif | |
| 50 } | |
| 51 | |
| 52 void BackupRollbackController::OnRollbackReceived() { | |
| 53 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
| 54 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits); | |
|
Nicolas Zea
2014/05/06 18:54:09
Why do we have a limitted number of tries? What co
haitaol1
2014/05/07 21:34:17
It's not good to be stuck in rollback mode. Backen
Nicolas Zea
2014/05/08 21:43:09
It seems odd that someone could prevent rollback b
haitaol1
2014/05/09 16:55:58
The user changes not in backup db will be constant
| |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 void BackupRollbackController::OnRollbackDone() { | |
| 59 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
| 60 sync_prefs_->SetRemainingRollbackTries(0); | |
| 61 #endif | |
| 62 } | |
| 63 | |
| 64 void BackupRollbackController::TryStart() { | |
| 65 if (!signin_->GetEffectiveUsername().empty()) { | |
| 66 DVLOG(1) << "Don't start backup/rollback when user is signed in."; | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 int rollback_tries = sync_prefs_->GetRemainingRollbackTries(); | |
| 71 if (rollback_tries > 0) { | |
| 72 DVLOG(1) << "Start rollback."; | |
| 73 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1); | |
| 74 start_rollback_.Run(); | |
| 75 } else { | |
| 76 DVLOG(1) << "Start backup."; | |
| 77 start_backup_.Run(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 } // namespace browser_sync | |
| OLD | NEW |