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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 9235040: [Sync] Handle errors during first sync gracefully. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review. Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/net/chrome_cookie_notification_details.h" 26 #include "chrome/browser/net/chrome_cookie_notification_details.h"
27 27
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/signin/signin_manager.h" 29 #include "chrome/browser/signin/signin_manager.h"
30 #include "chrome/browser/signin/token_service.h" 30 #include "chrome/browser/signin/token_service.h"
31 #include "chrome/browser/sync/api/sync_error.h" 31 #include "chrome/browser/sync/api/sync_error.h"
32 #include "chrome/browser/sync/backend_migrator.h" 32 #include "chrome/browser/sync/backend_migrator.h"
33 #include "chrome/browser/sync/glue/change_processor.h" 33 #include "chrome/browser/sync/glue/change_processor.h"
34 #include "chrome/browser/sync/glue/data_type_controller.h" 34 #include "chrome/browser/sync/glue/data_type_controller.h"
35 #include "chrome/browser/sync/glue/data_type_manager.h"
36 #include "chrome/browser/sync/glue/session_data_type_controller.h" 35 #include "chrome/browser/sync/glue/session_data_type_controller.h"
37 #include "chrome/browser/sync/glue/session_model_associator.h" 36 #include "chrome/browser/sync/glue/session_model_associator.h"
38 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 37 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
39 #include "chrome/browser/sync/internal_api/configure_reason.h" 38 #include "chrome/browser/sync/internal_api/configure_reason.h"
40 #include "chrome/browser/sync/internal_api/sync_manager.h" 39 #include "chrome/browser/sync/internal_api/sync_manager.h"
41 #include "chrome/browser/sync/js/js_arg_list.h" 40 #include "chrome/browser/sync/js/js_arg_list.h"
42 #include "chrome/browser/sync/js/js_event_details.h" 41 #include "chrome/browser/sync/js/js_event_details.h"
43 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 42 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
44 #include "chrome/browser/sync/sync_global_error.h" 43 #include "chrome/browser/sync/sync_global_error.h"
45 #include "chrome/browser/sync/util/cryptographer.h" 44 #include "chrome/browser/sync/util/cryptographer.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 119 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
121 signin_(signin_manager), 120 signin_(signin_manager),
122 unrecoverable_error_detected_(false), 121 unrecoverable_error_detected_(false),
123 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 122 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
124 expect_sync_configuration_aborted_(false), 123 expect_sync_configuration_aborted_(false),
125 clear_server_data_state_(CLEAR_NOT_STARTED), 124 clear_server_data_state_(CLEAR_NOT_STARTED),
126 encrypted_types_(browser_sync::Cryptographer::SensitiveTypes()), 125 encrypted_types_(browser_sync::Cryptographer::SensitiveTypes()),
127 encrypt_everything_(false), 126 encrypt_everything_(false),
128 encryption_pending_(false), 127 encryption_pending_(false),
129 auto_start_enabled_(start_behavior == AUTO_START), 128 auto_start_enabled_(start_behavior == AUTO_START),
130 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 129 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
130 configure_status_(DataTypeManager::UNKNOWN) {
131 // By default, dev, canary, and unbranded Chromium users will go to the 131 // By default, dev, canary, and unbranded Chromium users will go to the
132 // development servers. Development servers have more features than standard 132 // development servers. Development servers have more features than standard
133 // sync servers. Users with officially-branded Chrome stable and beta builds 133 // sync servers. Users with officially-branded Chrome stable and beta builds
134 // will go to the standard sync servers. 134 // will go to the standard sync servers.
135 // 135 //
136 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 136 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
137 base::ThreadRestrictions::ScopedAllowIO allow_io; 137 base::ThreadRestrictions::ScopedAllowIO allow_io;
138 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 138 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
139 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 139 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
140 channel == chrome::VersionInfo::CHANNEL_BETA) { 140 channel == chrome::VersionInfo::CHANNEL_BETA) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return !Intersection(preferred_types, encrypted_types).Empty(); 347 return !Intersection(preferred_types, encrypted_types).Empty();
348 } 348 }
349 349
350 void ProfileSyncService::OnSyncConfigureDone( 350 void ProfileSyncService::OnSyncConfigureDone(
351 DataTypeManager::ConfigureResult result) { 351 DataTypeManager::ConfigureResult result) {
352 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) { 352 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) {
353 ReconfigureDatatypeManager(); 353 ReconfigureDatatypeManager();
354 } 354 }
355 } 355 }
356 356
357 void ProfileSyncService::OnSyncConfigureRetry() {
358 // In platforms with auto start we would just wait for the
359 // configure to finish. In other platforms we would throw
360 // an unrecoverable error.
Andrew T Wilson (Slow) 2012/01/27 18:41:11 Add a note that the reason we do this is to force
lipalani1 2012/01/27 19:35:26 Done.
361 // Also if backend has been initialized(the user is authenticated
362 // and nigori is downloaded) we would simply wait rather than going into
363 // unrecoverable error, even if the platform has auto start disabled.
364 // Note: In those scenarios the UI does not wait for the configuration
365 // to finish
Andrew T Wilson (Slow) 2012/01/27 18:41:11 nit: period at end of sentence.
lipalani1 2012/01/27 19:35:26 Done.
366 if (!auto_start_enabled_ && !backend_initialized_) {
367 OnUnrecoverableError(FROM_HERE,
368 "Configure failed to download.");
369 }
370
371 NotifyObservers();
372 }
373
374
357 void ProfileSyncService::StartUp() { 375 void ProfileSyncService::StartUp() {
358 // Don't start up multiple times. 376 // Don't start up multiple times.
359 if (backend_.get()) { 377 if (backend_.get()) {
360 DVLOG(1) << "Skipping bringing up backend host."; 378 DVLOG(1) << "Skipping bringing up backend host.";
361 return; 379 return;
362 } 380 }
363 381
364 DCHECK(AreCredentialsAvailable()); 382 DCHECK(AreCredentialsAvailable());
365 383
366 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); 384 last_synced_time_ = sync_prefs_.GetLastSyncedTime();
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 switch (type) { 1344 switch (type) {
1327 case chrome::NOTIFICATION_SYNC_CONFIGURE_START: { 1345 case chrome::NOTIFICATION_SYNC_CONFIGURE_START: {
1328 NotifyObservers(); 1346 NotifyObservers();
1329 // TODO(sync): Maybe toast? 1347 // TODO(sync): Maybe toast?
1330 break; 1348 break;
1331 } 1349 }
1332 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: { 1350 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: {
1333 DataTypeManager::ConfigureResult* result = 1351 DataTypeManager::ConfigureResult* result =
1334 content::Details<DataTypeManager::ConfigureResult>(details).ptr(); 1352 content::Details<DataTypeManager::ConfigureResult>(details).ptr();
1335 1353
1336 DataTypeManager::ConfigureStatus status = result->status; 1354 configure_status_ = result->status;
1337 DVLOG(1) << "PSS SYNC_CONFIGURE_DONE called with status: " << status; 1355 DVLOG(1) << "PSS SYNC_CONFIGURE_DONE called with status: "
1338 if (status == DataTypeManager::ABORTED && 1356 << configure_status_;
1357
1358 // The possible status values:
1359 // ABORT - Configuration was aborted. This is not an error, if
1360 // initiated by user..
Andrew T Wilson (Slow) 2012/01/27 18:41:11 nit: double '..'
lipalani1 2012/01/27 19:35:26 Done.
1361 // RETRY - Configure failed but we are retrying.
1362 // OK - Everything succeeded.
1363 // PARTIAL_SUCCESS - Some datatypes failed to start.
1364 // Everything else is an UnrecoverableError. So treat it as such.
1365
1366 // First handle the abort case.
1367 if (configure_status_ == DataTypeManager::ABORTED &&
1339 expect_sync_configuration_aborted_) { 1368 expect_sync_configuration_aborted_) {
1340 DVLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; 1369 DVLOG(0) << "ProfileSyncService::Observe Sync Configure aborted";
1341 expect_sync_configuration_aborted_ = false; 1370 expect_sync_configuration_aborted_ = false;
1342 return; 1371 return;
1343 } 1372 }
1344 if (status != DataTypeManager::OK && 1373
1345 status != DataTypeManager::PARTIAL_SUCCESS) { 1374 // Handle retry case.
1375 if (configure_status_ == DataTypeManager::RETRY) {
1376 OnSyncConfigureRetry();
1377 return;
1378 }
1379
1380 // Handle unrecoverable error.
1381 if (configure_status_ != DataTypeManager::OK &&
1382 configure_status_ != DataTypeManager::PARTIAL_SUCCESS) {
1346 // Something catastrophic had happened. We should only have one 1383 // Something catastrophic had happened. We should only have one
1347 // error representing it. 1384 // error representing it.
1348 DCHECK(result->errors.size() == 1); 1385 DCHECK(result->errors.size() == 1);
1349 SyncError error = result->errors.front(); 1386 SyncError error = result->errors.front();
1350 DCHECK(error.IsSet()); 1387 DCHECK(error.IsSet());
1351 std::string message = 1388 std::string message =
1352 "Sync configuration failed with status " + 1389 "Sync configuration failed with status " +
1353 DataTypeManager::ConfigureStatusToString(status) + 1390 DataTypeManager::ConfigureStatusToString(configure_status_) +
1354 " during " + syncable::ModelTypeToString(error.type()) + 1391 " during " + syncable::ModelTypeToString(error.type()) +
1355 ": " + error.message(); 1392 ": " + error.message();
1356 LOG(ERROR) << "ProfileSyncService error: " 1393 LOG(ERROR) << "ProfileSyncService error: "
1357 << message; 1394 << message;
1358 // TODO: Don't 1395 // TODO: Don't
1359 OnUnrecoverableError(error.location(), message); 1396 OnUnrecoverableError(error.location(), message);
1360 return; 1397 return;
1361 } 1398 }
1362 1399
1400 // Now handle partial success and full success.
1363 MessageLoop::current()->PostTask(FROM_HERE, 1401 MessageLoop::current()->PostTask(FROM_HERE,
1364 base::Bind(&ProfileSyncService::OnSyncConfigureDone, 1402 base::Bind(&ProfileSyncService::OnSyncConfigureDone,
1365 weak_factory_.GetWeakPtr(), *result)); 1403 weak_factory_.GetWeakPtr(), *result));
1366 1404
1367 // We should never get in a state where we have no encrypted datatypes 1405 // We should never get in a state where we have no encrypted datatypes
1368 // enabled, and yet we still think we require a passphrase for decryption. 1406 // enabled, and yet we still think we require a passphrase for decryption.
1369 DCHECK(!(IsPassphraseRequiredForDecryption() && 1407 DCHECK(!(IsPassphraseRequiredForDecryption() &&
1370 !IsEncryptedDatatypeEnabled())); 1408 !IsEncryptedDatatypeEnabled()));
1371 1409
1372 // This must be done before we start syncing with the server to avoid 1410 // This must be done before we start syncing with the server to avoid
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 << "Unrecoverable error."; 1598 << "Unrecoverable error.";
1561 } else { 1599 } else {
1562 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " 1600 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not "
1563 << "initialized"; 1601 << "initialized";
1564 } 1602 }
1565 } 1603 }
1566 1604
1567 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { 1605 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() {
1568 return failed_datatypes_handler_; 1606 return failed_datatypes_handler_;
1569 } 1607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698