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