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

Side by Side Diff: chrome/browser/sync/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: updated 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
(Empty)
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.
4
5 #include "chrome/browser/sync/backup_rollback_controller.h"
6
7 #include "base/command_line.h"
8 #include "base/location.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/single_thread_task_runner.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"
14 #include "components/sync_driver/sync_driver_switches.h"
15 #include "components/sync_driver/sync_prefs.h"
16
17 namespace browser_sync {
18
19 #if defined(ENABLE_PRE_SYNC_BACKUP)
20 // Number of rollback attempts to try before giving up.
21 static const int kRollbackLimits = 3;
22
23 // Finch experiment name and group.
24 static char kSyncBackupFinchName[] = "SyncBackup";
25 static char kSyncBackupFinchDisabled[] = "disabled";
26 #endif
27
28 BackupRollbackController::BackupRollbackController(
29 sync_driver::SyncPrefs* sync_prefs,
30 const SigninManagerWrapper* signin,
31 base::Closure start_backup,
32 base::Closure start_rollback)
33 : sync_prefs_(sync_prefs),
34 signin_(signin),
35 start_backup_(start_backup),
36 start_rollback_(start_rollback) {
37 }
38
39 BackupRollbackController::~BackupRollbackController() {
40 }
41
42 bool BackupRollbackController::StartBackup() {
43 if (!IsBackupEnabled())
44 return false;
45
46 // Disable rollback to previous backup DB because it will be overwritten by
47 // new backup.
48 sync_prefs_->SetRemainingRollbackTries(0);
49 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_backup_);
50 return true;
51 }
52
53 bool BackupRollbackController::StartRollback() {
54 if (!IsBackupEnabled())
55 return false;
56
57 // Don't roll back if disabled or user is signed in.
58 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
59 switches::kSyncDisableRollback) ||
60 !signin_->GetEffectiveUsername().empty()) {
61 sync_prefs_->SetRemainingRollbackTries(0);
62 return false;
63 }
64
65 int rollback_tries = sync_prefs_->GetRemainingRollbackTries();
66 if (rollback_tries <= 0)
67 return false; // No pending rollback.
68
69 sync_prefs_->SetRemainingRollbackTries(rollback_tries - 1);
70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, start_rollback_);
71 return true;
72 }
73
74 void BackupRollbackController::OnRollbackReceived() {
75 #if defined(ENABLE_PRE_SYNC_BACKUP)
76 sync_prefs_->SetRemainingRollbackTries(kRollbackLimits);
77 #endif
78 }
79
80 void BackupRollbackController::OnRollbackDone() {
81 #if defined(ENABLE_PRE_SYNC_BACKUP)
82 sync_prefs_->SetRemainingRollbackTries(0);
83 #endif
84 }
85
86 // static
87 bool BackupRollbackController::IsBackupEnabled() {
88 #if defined(ENABLE_PRE_SYNC_BACKUP)
89 const std::string group_name =
90 base::FieldTrialList::FindFullName(kSyncBackupFinchName);
91
92 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
93 switches::kSyncDisableBackup) ||
94 group_name == kSyncBackupFinchDisabled) {
95 return false;
96 }
97 return true;
98 #else
99 return false;
100 #endif
101 }
102
103 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/backup_rollback_controller.h ('k') | chrome/browser/sync/backup_rollback_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698