| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 using syncer::ModelTypeSet; | 108 using syncer::ModelTypeSet; |
| 109 using syncer::ModelTypeStore; | 109 using syncer::ModelTypeStore; |
| 110 using syncer::ProtocolEventObserver; | 110 using syncer::ProtocolEventObserver; |
| 111 using syncer::SyncEngine; | 111 using syncer::SyncEngine; |
| 112 using syncer::SyncCredentials; | 112 using syncer::SyncCredentials; |
| 113 using syncer::SyncProtocolError; | 113 using syncer::SyncProtocolError; |
| 114 using syncer::WeakHandle; | 114 using syncer::WeakHandle; |
| 115 | 115 |
| 116 namespace browser_sync { | 116 namespace browser_sync { |
| 117 | 117 |
| 118 namespace { |
| 119 |
| 118 typedef GoogleServiceAuthError AuthError; | 120 typedef GoogleServiceAuthError AuthError; |
| 119 | 121 |
| 122 // Events in ClearServerData flow to be recorded in histogram. Existing |
| 123 // constants should not be deleted or reordered. New ones shold be added at the |
| 124 // end, before CLEAR_SERVER_DATA_MAX. |
| 125 enum ClearServerDataEvents { |
| 126 // ClearServerData started after user switched to custom passphrase. |
| 127 CLEAR_SERVER_DATA_STARTED, |
| 128 // DataTypeManager reported that catchup configuration failed. |
| 129 CLEAR_SERVER_DATA_CATCHUP_FAILED, |
| 130 // ClearServerData flow restarted after browser restart. |
| 131 CLEAR_SERVER_DATA_RETRIED, |
| 132 // Success. |
| 133 CLEAR_SERVER_DATA_SUCCEEDED, |
| 134 // Client received RECET_LOCAL_SYNC_DATA after custom passphrase was enabled |
| 135 // on different client. |
| 136 CLEAR_SERVER_DATA_RESET_LOCAL_DATA_RECEIVED, |
| 137 CLEAR_SERVER_DATA_MAX |
| 138 }; |
| 139 |
| 140 const char kClearServerDataEventsHistogramName[] = "Sync.ClearServerDataEvents"; |
| 141 |
| 120 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; | 142 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; |
| 121 | 143 |
| 122 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { | 144 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { |
| 123 // Number of initial errors (in sequence) to ignore before applying | 145 // Number of initial errors (in sequence) to ignore before applying |
| 124 // exponential back-off rules. | 146 // exponential back-off rules. |
| 125 0, | 147 0, |
| 126 | 148 |
| 127 // Initial delay for exponential back-off in ms. | 149 // Initial delay for exponential back-off in ms. |
| 128 2000, | 150 2000, |
| 129 | 151 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 1000 * 3600 * 4, // 4 hours. | 162 1000 * 3600 * 4, // 4 hours. |
| 141 | 163 |
| 142 // Time to keep an entry from being discarded even when it | 164 // Time to keep an entry from being discarded even when it |
| 143 // has no significant state, -1 to never discard. | 165 // has no significant state, -1 to never discard. |
| 144 -1, | 166 -1, |
| 145 | 167 |
| 146 // Don't use initial delay unless the last request was an error. | 168 // Don't use initial delay unless the last request was an error. |
| 147 false, | 169 false, |
| 148 }; | 170 }; |
| 149 | 171 |
| 150 static const base::FilePath::CharType kSyncDataFolderName[] = | 172 const base::FilePath::CharType kSyncDataFolderName[] = |
| 151 FILE_PATH_LITERAL("Sync Data"); | 173 FILE_PATH_LITERAL("Sync Data"); |
| 152 static const base::FilePath::CharType kLevelDBFolderName[] = | 174 const base::FilePath::CharType kLevelDBFolderName[] = |
| 153 FILE_PATH_LITERAL("LevelDB"); | 175 FILE_PATH_LITERAL("LevelDB"); |
| 154 | 176 |
| 155 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
| 156 static const base::FilePath::CharType kLoopbackServerBackendFilename[] = | 178 const base::FilePath::CharType kLoopbackServerBackendFilename[] = |
| 157 FILE_PATH_LITERAL("profile.pb"); | 179 FILE_PATH_LITERAL("profile.pb"); |
| 158 #endif | 180 #endif |
| 159 | 181 |
| 160 namespace { | |
| 161 | |
| 162 // Perform the actual sync data folder deletion. | 182 // Perform the actual sync data folder deletion. |
| 163 // This should only be called on the sync thread. | 183 // This should only be called on the sync thread. |
| 164 void DeleteSyncDataFolder(const base::FilePath& directory_path) { | 184 void DeleteSyncDataFolder(const base::FilePath& directory_path) { |
| 165 if (base::DirectoryExists(directory_path)) { | 185 if (base::DirectoryExists(directory_path)) { |
| 166 if (!base::DeleteFile(directory_path, true)) | 186 if (!base::DeleteFile(directory_path, true)) |
| 167 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 187 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
| 168 } | 188 } |
| 169 } | 189 } |
| 170 | 190 |
| 171 } // namespace | 191 } // namespace |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 startup_controller_->TryStartImmediately(); | 400 startup_controller_->TryStartImmediately(); |
| 381 } else { | 401 } else { |
| 382 startup_controller_->TryStart(); | 402 startup_controller_->TryStart(); |
| 383 } | 403 } |
| 384 } | 404 } |
| 385 | 405 |
| 386 void ProfileSyncService::StartSyncingWithServer() { | 406 void ProfileSyncService::StartSyncingWithServer() { |
| 387 if (base::FeatureList::IsEnabled( | 407 if (base::FeatureList::IsEnabled( |
| 388 switches::kSyncClearDataOnPassphraseEncryption) && | 408 switches::kSyncClearDataOnPassphraseEncryption) && |
| 389 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { | 409 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { |
| 410 // We are restarting catchup configuration after browser restart. |
| 411 UMA_HISTOGRAM_ENUMERATION(kClearServerDataEventsHistogramName, |
| 412 CLEAR_SERVER_DATA_RETRIED, CLEAR_SERVER_DATA_MAX); |
| 413 |
| 390 BeginConfigureCatchUpBeforeClear(); | 414 BeginConfigureCatchUpBeforeClear(); |
| 391 return; | 415 return; |
| 392 } | 416 } |
| 393 | 417 |
| 394 if (engine_) | 418 if (engine_) |
| 395 engine_->StartSyncingWithServer(); | 419 engine_->StartSyncingWithServer(); |
| 396 } | 420 } |
| 397 | 421 |
| 398 void ProfileSyncService::RegisterAuthNotifications() { | 422 void ProfileSyncService::RegisterAuthNotifications() { |
| 399 DCHECK(thread_checker_.CalledOnValidThread()); | 423 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 break; | 1319 break; |
| 1296 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: | 1320 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: |
| 1297 // Sync disabled by domain admin. we should stop syncing until next | 1321 // Sync disabled by domain admin. we should stop syncing until next |
| 1298 // restart. | 1322 // restart. |
| 1299 sync_disabled_by_admin_ = true; | 1323 sync_disabled_by_admin_ = true; |
| 1300 ShutdownImpl(syncer::DISABLE_SYNC); | 1324 ShutdownImpl(syncer::DISABLE_SYNC); |
| 1301 break; | 1325 break; |
| 1302 case syncer::RESET_LOCAL_SYNC_DATA: | 1326 case syncer::RESET_LOCAL_SYNC_DATA: |
| 1303 ShutdownImpl(syncer::DISABLE_SYNC); | 1327 ShutdownImpl(syncer::DISABLE_SYNC); |
| 1304 startup_controller_->TryStart(); | 1328 startup_controller_->TryStart(); |
| 1329 UMA_HISTOGRAM_ENUMERATION(kClearServerDataEventsHistogramName, |
| 1330 CLEAR_SERVER_DATA_RESET_LOCAL_DATA_RECEIVED, |
| 1331 CLEAR_SERVER_DATA_MAX); |
| 1305 break; | 1332 break; |
| 1306 default: | 1333 default: |
| 1307 NOTREACHED(); | 1334 NOTREACHED(); |
| 1308 } | 1335 } |
| 1309 NotifyObservers(); | 1336 NotifyObservers(); |
| 1310 } | 1337 } |
| 1311 | 1338 |
| 1312 void ProfileSyncService::OnLocalSetPassphraseEncryption( | 1339 void ProfileSyncService::OnLocalSetPassphraseEncryption( |
| 1313 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { | 1340 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { |
| 1314 DCHECK(thread_checker_.CalledOnValidThread()); | 1341 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1315 if (!base::FeatureList::IsEnabled( | 1342 if (!base::FeatureList::IsEnabled( |
| 1316 switches::kSyncClearDataOnPassphraseEncryption)) | 1343 switches::kSyncClearDataOnPassphraseEncryption)) |
| 1317 return; | 1344 return; |
| 1318 | 1345 |
| 1319 // At this point the user has set a custom passphrase and we have received the | 1346 // At this point the user has set a custom passphrase and we have received the |
| 1320 // updated nigori state. Time to cache the nigori state, and catch up the | 1347 // updated nigori state. Time to cache the nigori state, and catch up the |
| 1321 // active data types. | 1348 // active data types. |
| 1349 UMA_HISTOGRAM_ENUMERATION(kClearServerDataEventsHistogramName, |
| 1350 CLEAR_SERVER_DATA_STARTED, CLEAR_SERVER_DATA_MAX); |
| 1322 sync_prefs_.SetNigoriSpecificsForPassphraseTransition( | 1351 sync_prefs_.SetNigoriSpecificsForPassphraseTransition( |
| 1323 nigori_state.nigori_specifics); | 1352 nigori_state.nigori_specifics); |
| 1324 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(true); | 1353 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(true); |
| 1325 BeginConfigureCatchUpBeforeClear(); | 1354 BeginConfigureCatchUpBeforeClear(); |
| 1326 } | 1355 } |
| 1327 | 1356 |
| 1328 void ProfileSyncService::BeginConfigureCatchUpBeforeClear() { | 1357 void ProfileSyncService::BeginConfigureCatchUpBeforeClear() { |
| 1329 DCHECK(data_type_manager_); | 1358 DCHECK(data_type_manager_); |
| 1330 DCHECK(!saved_nigori_state_); | 1359 DCHECK(!saved_nigori_state_); |
| 1331 saved_nigori_state_ = | 1360 saved_nigori_state_ = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1349 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false); | 1378 sync_prefs_.SetPassphraseEncryptionTransitionInProgress(false); |
| 1350 | 1379 |
| 1351 // Call to ClearServerData generates new keystore key on the server. This | 1380 // Call to ClearServerData generates new keystore key on the server. This |
| 1352 // makes keystore bootstrap token invalid. Let's clear it from preferences. | 1381 // makes keystore bootstrap token invalid. Let's clear it from preferences. |
| 1353 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string()); | 1382 sync_prefs_.SetKeystoreEncryptionBootstrapToken(std::string()); |
| 1354 | 1383 |
| 1355 // Shutdown sync, delete the Directory, then restart, restoring the cached | 1384 // Shutdown sync, delete the Directory, then restart, restoring the cached |
| 1356 // nigori state. | 1385 // nigori state. |
| 1357 ShutdownImpl(syncer::DISABLE_SYNC); | 1386 ShutdownImpl(syncer::DISABLE_SYNC); |
| 1358 startup_controller_->TryStart(); | 1387 startup_controller_->TryStart(); |
| 1388 UMA_HISTOGRAM_ENUMERATION(kClearServerDataEventsHistogramName, |
| 1389 CLEAR_SERVER_DATA_SUCCEEDED, CLEAR_SERVER_DATA_MAX); |
| 1359 } | 1390 } |
| 1360 | 1391 |
| 1361 void ProfileSyncService::OnConfigureDone( | 1392 void ProfileSyncService::OnConfigureDone( |
| 1362 const DataTypeManager::ConfigureResult& result) { | 1393 const DataTypeManager::ConfigureResult& result) { |
| 1363 DCHECK(thread_checker_.CalledOnValidThread()); | 1394 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1364 configure_status_ = result.status; | 1395 configure_status_ = result.status; |
| 1365 data_type_status_table_ = result.data_type_status_table; | 1396 data_type_status_table_ = result.data_type_status_table; |
| 1366 | 1397 |
| 1367 // We should have cleared our cached passphrase before we get here (in | 1398 // We should have cleared our cached passphrase before we get here (in |
| 1368 // OnEngineInitialized()). | 1399 // OnEngineInitialized()). |
| 1369 DCHECK(cached_passphrase_.empty()); | 1400 DCHECK(cached_passphrase_.empty()); |
| 1370 | 1401 |
| 1371 if (!sync_configure_start_time_.is_null()) { | 1402 if (!sync_configure_start_time_.is_null()) { |
| 1372 if (result.status == DataTypeManager::OK) { | 1403 if (configure_status_ == DataTypeManager::OK) { |
| 1373 base::Time sync_configure_stop_time = base::Time::Now(); | 1404 base::Time sync_configure_stop_time = base::Time::Now(); |
| 1374 base::TimeDelta delta = | 1405 base::TimeDelta delta = |
| 1375 sync_configure_stop_time - sync_configure_start_time_; | 1406 sync_configure_stop_time - sync_configure_start_time_; |
| 1376 if (is_first_time_sync_configure_) { | 1407 if (is_first_time_sync_configure_) { |
| 1377 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceInitialConfigureTime", delta); | 1408 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceInitialConfigureTime", delta); |
| 1378 } else { | 1409 } else { |
| 1379 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceSubsequentConfigureTime", delta); | 1410 UMA_HISTOGRAM_LONG_TIMES("Sync.ServiceSubsequentConfigureTime", delta); |
| 1380 } | 1411 } |
| 1381 } | 1412 } |
| 1382 sync_configure_start_time_ = base::Time(); | 1413 sync_configure_start_time_ = base::Time(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1396 // First handle the abort case. | 1427 // First handle the abort case. |
| 1397 if (configure_status_ == DataTypeManager::ABORTED && | 1428 if (configure_status_ == DataTypeManager::ABORTED && |
| 1398 expect_sync_configuration_aborted_) { | 1429 expect_sync_configuration_aborted_) { |
| 1399 DVLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; | 1430 DVLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; |
| 1400 expect_sync_configuration_aborted_ = false; | 1431 expect_sync_configuration_aborted_ = false; |
| 1401 return; | 1432 return; |
| 1402 } | 1433 } |
| 1403 | 1434 |
| 1404 // Handle unrecoverable error. | 1435 // Handle unrecoverable error. |
| 1405 if (configure_status_ != DataTypeManager::OK) { | 1436 if (configure_status_ != DataTypeManager::OK) { |
| 1437 if (catch_up_configure_in_progress_) { |
| 1438 // Record catchup configuration failure. |
| 1439 UMA_HISTOGRAM_ENUMERATION(kClearServerDataEventsHistogramName, |
| 1440 CLEAR_SERVER_DATA_CATCHUP_FAILED, |
| 1441 CLEAR_SERVER_DATA_MAX); |
| 1442 } |
| 1406 // Something catastrophic had happened. We should only have one | 1443 // Something catastrophic had happened. We should only have one |
| 1407 // error representing it. | 1444 // error representing it. |
| 1408 syncer::SyncError error = data_type_status_table_.GetUnrecoverableError(); | 1445 syncer::SyncError error = data_type_status_table_.GetUnrecoverableError(); |
| 1409 DCHECK(error.IsSet()); | 1446 DCHECK(error.IsSet()); |
| 1410 std::string message = | 1447 std::string message = |
| 1411 "Sync configuration failed with status " + | 1448 "Sync configuration failed with status " + |
| 1412 DataTypeManager::ConfigureStatusToString(configure_status_) + | 1449 DataTypeManager::ConfigureStatusToString(configure_status_) + |
| 1413 " caused by " + | 1450 " caused by " + |
| 1414 syncer::ModelTypeSetToString( | 1451 syncer::ModelTypeSetToString( |
| 1415 data_type_status_table_.GetUnrecoverableErrorTypes()) + | 1452 data_type_status_table_.GetUnrecoverableErrorTypes()) + |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 | 2677 |
| 2641 DCHECK(startup_controller_->IsSetupInProgress()); | 2678 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2642 startup_controller_->SetSetupInProgress(false); | 2679 startup_controller_->SetSetupInProgress(false); |
| 2643 | 2680 |
| 2644 if (IsEngineInitialized()) | 2681 if (IsEngineInitialized()) |
| 2645 ReconfigureDatatypeManager(); | 2682 ReconfigureDatatypeManager(); |
| 2646 NotifyObservers(); | 2683 NotifyObservers(); |
| 2647 } | 2684 } |
| 2648 | 2685 |
| 2649 } // namespace browser_sync | 2686 } // namespace browser_sync |
| OLD | NEW |