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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_BACKUP_ROLLBACK_CONTROLLER_H_
6 #define CHROME_BROWSER_SYNC_BACKUP_ROLLBACK_CONTROLLER_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
11 class ManagedUserSigninManagerWrapper;
13 namespace sync_driver {
17 namespace browser_sync {
19 // BackupRollbackController takes two closures for starting backup/rollback
20 // process. It calls the closures according to user's signin status or
21 // received rollback command. Backup is not run when user signed in, even when
22 // sync is not running.
23 class BackupRollbackController {
25 BackupRollbackController(sync_driver::SyncPrefs* sync_prefs,
26 const ManagedUserSigninManagerWrapper* signin,
27 base::Closure start_backup,
28 base::Closure start_rollback);
29 ~BackupRollbackController();
31 // Check to see whether to start backup/rollback. |delay| specifies the time
32 // to wait before checking.
33 void Start(base::TimeDelta delay);
35 // Update rollback preference to indicate rollback is needed.
36 void OnRollbackReceived();
38 // Update rollback preference to indicate rollback is finished.
39 void OnRollbackDone();
41 // Return true if platform supports backup and backup is enabled.
42 static bool IsBackupEnabled();
45 // Check signin status and rollback preference and start backup/rollback
49 sync_driver::SyncPrefs* sync_prefs_;
51 // Use ManagedUserSigninManagerWrapper instead of SigninManagerBase because
52 // SigninManagerBase could return non-empty user name for managed user, which
53 // would cause backup to trumpet normal sync for managed user.
54 const ManagedUserSigninManagerWrapper* signin_;
56 base::Closure start_backup_;
57 base::Closure start_rollback_;
58 base::WeakPtrFactory<BackupRollbackController> weak_ptr_factory_;
60 DISALLOW_COPY_AND_ASSIGN(BackupRollbackController);
63 } // namespace browser_sync
65 #endif // CHROME_BROWSER_SYNC_BACKUP_ROLLBACK_CONTROLLER_H_