Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: components/sync_driver/backup_rollback_controller.cc

Issue 1354883003: Componentize chrome/browser/sync/backup_rollback_controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/sync/backup_rollback_controller.h" 5 #include "components/sync_driver/backup_rollback_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "components/sync_driver/signin_manager_wrapper.h" 12 #include "components/sync_driver/signin_manager_wrapper.h"
14 #include "components/sync_driver/sync_driver_switches.h" 13 #include "components/sync_driver/sync_driver_switches.h"
15 #include "components/sync_driver/sync_prefs.h" 14 #include "components/sync_driver/sync_prefs.h"
16 15
17 namespace browser_sync { 16 namespace browser_sync {
droger 2015/09/18 13:04:14 namespace sync_driver {
Abhishek 2015/09/18 14:00:49 Done.
18 17
19 #if defined(ENABLE_PRE_SYNC_BACKUP) 18 #if defined(ENABLE_PRE_SYNC_BACKUP)
20 // Number of rollback attempts to try before giving up. 19 // Number of rollback attempts to try before giving up.
21 static const int kRollbackLimits = 3; 20 static const int kRollbackLimits = 3;
22 21
23 // Finch experiment name and group. 22 // Finch experiment name and group.
24 static char kSyncBackupFinchName[] = "SyncBackup"; 23 static char kSyncBackupFinchName[] = "SyncBackup";
25 static char kSyncBackupFinchDisabled[] = "disabled"; 24 static char kSyncBackupFinchDisabled[] = "disabled";
26 #endif 25 #endif
27 26
28 BackupRollbackController::BackupRollbackController( 27 BackupRollbackController::BackupRollbackController(
29 sync_driver::SyncPrefs* sync_prefs, 28 sync_driver::SyncPrefs* sync_prefs,
30 const SigninManagerWrapper* signin, 29 const SigninManagerWrapper* signin,
31 base::Closure start_backup, 30 base::Closure start_backup,
32 base::Closure start_rollback) 31 base::Closure start_rollback)
33 : sync_prefs_(sync_prefs), 32 : sync_prefs_(sync_prefs),
34 signin_(signin), 33 signin_(signin),
35 start_backup_(start_backup), 34 start_backup_(start_backup),
36 start_rollback_(start_rollback) { 35 start_rollback_(start_rollback) {}
37 }
38 36
39 BackupRollbackController::~BackupRollbackController() { 37 BackupRollbackController::~BackupRollbackController() {}
40 }
41 38
42 bool BackupRollbackController::StartBackup() { 39 bool BackupRollbackController::StartBackup() {
43 if (!IsBackupEnabled()) 40 if (!IsBackupEnabled())
44 return false; 41 return false;
45 42
46 // Disable rollback to previous backup DB because it will be overwritten by 43 // Disable rollback to previous backup DB because it will be overwritten by
47 // new backup. 44 // new backup.
48 sync_prefs_->SetRemainingRollbackTries(0); 45 sync_prefs_->SetRemainingRollbackTries(0);
49 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_backup_); 46 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_backup_);
50 return true; 47 return true;
51 } 48 }
52 49
53 bool BackupRollbackController::StartRollback() { 50 bool BackupRollbackController::StartRollback() {
54 if (!IsBackupEnabled()) 51 if (!IsBackupEnabled())
55 return false; 52 return false;
56 53
57 // Don't roll back if disabled or user is signed in. 54 // Don't roll back if disabled or user is signed in.
58 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 55 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
59 switches::kSyncDisableRollback) || 56 switches::kSyncDisableRollback) ||
60 !signin_->GetEffectiveUsername().empty()) { 57 !signin_->GetEffectiveUsername().empty()) {
61 sync_prefs_->SetRemainingRollbackTries(0); 58 sync_prefs_->SetRemainingRollbackTries(0);
62 return false; 59 return false;
63 } 60 }
64 61
65 int rollback_tries = sync_prefs_->GetRemainingRollbackTries(); 62 int rollback_tries = sync_prefs_->GetRemainingRollbackTries();
66 if (rollback_tries <= 0) 63 if (rollback_tries <= 0)
67 return false; // No pending rollback. 64 return false; // No pending rollback.
68 65
69 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1); 66 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1);
70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_); 67 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_);
71 return true; 68 return true;
72 } 69 }
73 70
74 void BackupRollbackController::OnRollbackReceived() { 71 void BackupRollbackController::OnRollbackReceived() {
75 #if defined(ENABLE_PRE_SYNC_BACKUP) 72 #if defined(ENABLE_PRE_SYNC_BACKUP)
76 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits); 73 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits);
77 #endif 74 #endif
(...skipping 15 matching lines...) Expand all
93 switches::kSyncDisableBackup) || 90 switches::kSyncDisableBackup) ||
94 group_name == kSyncBackupFinchDisabled) { 91 group_name == kSyncBackupFinchDisabled) {
95 return false; 92 return false;
96 } 93 }
97 return true; 94 return true;
98 #else 95 #else
99 return false; 96 return false;
100 #endif 97 #endif
101 } 98 }
102 99
103 } // namespace browser_sync 100 } // namespace browser_sync
droger 2015/09/18 13:04:14 } // namespace sync_driver
Abhishek 2015/09/18 14:00:49 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698