Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / backup_rollback_controller.cc
index c7018e3..5a727bb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "base/command_line.h"
 #include "base/message_loop/message_loop.h"
+#include "base/metrics/field_trial.h"
 #include "chrome/browser/sync/managed_user_signin_manager_wrapper.h"
 #include "chrome/common/chrome_switches.h"
 #include "components/sync_driver/sync_prefs.h"
@@ -15,6 +16,10 @@ namespace browser_sync {
 #if defined(ENABLE_PRE_SYNC_BACKUP)
 // Number of rollback attempts to try before giving up.
 static const int kRollbackLimits = 3;
+
+// Finch experiment name and group.
+static char kSyncBackupFinchName[] = "SyncBackup";
+static char kSyncBackupFinchDisabled[] = "disabled";
 #endif
 
 BackupRollbackController::BackupRollbackController(
@@ -33,11 +38,8 @@ BackupRollbackController::~BackupRollbackController() {
 }
 
 void BackupRollbackController::Start(base::TimeDelta delay) {
-#if defined(ENABLE_PRE_SYNC_BACKUP)
-  if (CommandLine::ForCurrentProcess()->HasSwitch(
-          switches::kSyncDisableBackup)) {
+  if (!IsBackupEnabled())
     return;
-  }
 
   if (!CommandLine::ForCurrentProcess()->HasSwitch(
           switches::kSyncEnableRollback)) {
@@ -53,7 +55,6 @@ void BackupRollbackController::Start(base::TimeDelta delay) {
                    weak_ptr_factory_.GetWeakPtr()),
         delay);
   }
-#endif
 }
 
 void BackupRollbackController::OnRollbackReceived() {
@@ -85,4 +86,21 @@ void BackupRollbackController::TryStart() {
   }
 }
 
+// static
+bool BackupRollbackController::IsBackupEnabled() {
+#if defined(ENABLE_PRE_SYNC_BACKUP)
+  const std::string group_name =
+      base::FieldTrialList::FindFullName(kSyncBackupFinchName);
+
+  if (CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kSyncDisableBackup) ||
+      group_name == kSyncBackupFinchDisabled)  {
+    return false;
+  }
+  return true;
+#else
+  return false;
+#endif
+}
+
 }  // namespace browser_sync