| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 GetSessionModelAssociator()->AsWeakPtr())); | 600 GetSessionModelAssociator()->AsWeakPtr())); |
| 601 } | 601 } |
| 602 VLOG(2) << "Notifying observers sync cycle completed"; | 602 VLOG(2) << "Notifying observers sync cycle completed"; |
| 603 NotifyObservers(); | 603 NotifyObservers(); |
| 604 } | 604 } |
| 605 | 605 |
| 606 // TODO(sync): eventually support removing datatypes too. | 606 // TODO(sync): eventually support removing datatypes too. |
| 607 void ProfileSyncService::OnDataTypesChanged( | 607 void ProfileSyncService::OnDataTypesChanged( |
| 608 const syncable::ModelTypeSet& to_add) { | 608 const syncable::ModelTypeSet& to_add) { |
| 609 // We don't bother doing anything if the migrator is busy. | 609 // We don't bother doing anything if the migrator is busy. |
| 610 if (migrator_->state() != browser_sync::BackendMigrator::IDLE) { | 610 if (migrator_.get() && |
| 611 migrator_->state() != browser_sync::BackendMigrator::IDLE) { |
| 611 VLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; | 612 VLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; |
| 612 return; | 613 return; |
| 613 } | 614 } |
| 614 | 615 |
| 615 VLOG(2) << "OnDataTypesChanged called with types: " | 616 VLOG(2) << "OnDataTypesChanged called with types: " |
| 616 << syncable::ModelTypeSetToString(to_add); | 617 << syncable::ModelTypeSetToString(to_add); |
| 617 | 618 |
| 618 syncable::ModelTypeSet registered_types; | 619 syncable::ModelTypeSet registered_types; |
| 619 GetRegisteredDataTypes(®istered_types); | 620 GetRegisteredDataTypes(®istered_types); |
| 620 | 621 |
| 621 syncable::ModelTypeSet to_register; | 622 syncable::ModelTypeSet to_register; |
| 622 std::set_difference(to_add.begin(), to_add.end(), | 623 std::set_difference(to_add.begin(), to_add.end(), |
| 623 registered_types.begin(), registered_types.end(), | 624 registered_types.begin(), registered_types.end(), |
| 624 std::inserter(to_register, to_register.end())); | 625 std::inserter(to_register, to_register.end())); |
| 625 | 626 |
| 626 VLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); | 627 VLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); |
| 627 | 628 |
| 628 for (syncable::ModelTypeSet::const_iterator it = to_register.begin(); | 629 for (syncable::ModelTypeSet::const_iterator it = to_register.begin(); |
| 629 it != to_register.end(); ++it) { | 630 it != to_register.end(); ++it) { |
| 630 // Received notice to enable session sync. Check if sessions are | 631 // Received notice to enable experimental type. Check if the type is |
| 631 // registered, and if not register a new datatype controller. | 632 // registered, and if not register a new datatype controller. |
| 632 RegisterNewDataType(*it); | 633 RegisterNewDataType(*it); |
| 633 // Enable the about:flags switch for sessions so we don't have to always | 634 // Enable the about:flags switch for the experimental type so we don't have |
| 634 // perform this reconfiguration. Once we set this, sessions will remain | 635 // to always perform this reconfiguration. Once we set this, the type will |
| 635 // registered, so we will no longer go down this code path. | 636 // remain registered on restart, so we will no longer go down this code |
| 637 // path. |
| 636 std::string experiment_name = GetExperimentNameForDataType(*it); | 638 std::string experiment_name = GetExperimentNameForDataType(*it); |
| 637 if (experiment_name.empty()) | 639 if (experiment_name.empty()) |
| 638 continue; | 640 continue; |
| 639 about_flags::SetExperimentEnabled(g_browser_process->local_state(), | 641 about_flags::SetExperimentEnabled(g_browser_process->local_state(), |
| 640 experiment_name, | 642 experiment_name, |
| 641 true); | 643 true); |
| 642 } | 644 } |
| 643 | 645 |
| 644 // Check if the user has "Keep Everything Synced" enabled. If so, we want | 646 // Check if the user has "Keep Everything Synced" enabled. If so, we want |
| 645 // to turn on sessions if it's not already on. Otherwise we leave it off. | 647 // to turn on all experimental types if they're not already on. Otherwise we |
| 646 // Note: if sessions are already registered, we don't turn it on. This | 648 // leave them off. |
| 649 // Note: if any types are already registered, we don't turn them on. This |
| 647 // covers the case where we're already in the process of reconfiguring | 650 // covers the case where we're already in the process of reconfiguring |
| 648 // to turn sessions on. | 651 // to turn an experimental type on. |
| 649 if (sync_prefs_.HasKeepEverythingSynced()) { | 652 if (sync_prefs_.HasKeepEverythingSynced()) { |
| 650 // Mark all data types as preferred. | 653 // Mark all data types as preferred. |
| 651 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); | 654 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); |
| 652 | 655 |
| 653 if (!to_register.empty()) { | 656 // Only automatically turn on types if we have already finished set up. |
| 657 // Otherwise, just leave the experimental types on by default. |
| 658 if (!to_register.empty() && HasSyncSetupCompleted() && migrator_.get()) { |
| 654 VLOG(1) << "Dynamically enabling new datatypes: " | 659 VLOG(1) << "Dynamically enabling new datatypes: " |
| 655 << syncable::ModelTypeSetToString(to_register); | 660 << syncable::ModelTypeSetToString(to_register); |
| 656 OnMigrationNeededForTypes(to_register); | 661 OnMigrationNeededForTypes(to_register); |
| 657 } | 662 } |
| 658 } | 663 } |
| 659 } | 664 } |
| 660 | 665 |
| 661 void ProfileSyncService::UpdateAuthErrorState( | 666 void ProfileSyncService::UpdateAuthErrorState( |
| 662 const GoogleServiceAuthError& error) { | 667 const GoogleServiceAuthError& error) { |
| 663 last_auth_error_ = error; | 668 last_auth_error_ = error; |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 << "Unrecoverable error."; | 1527 << "Unrecoverable error."; |
| 1523 } else { | 1528 } else { |
| 1524 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1529 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
| 1525 << "initialized"; | 1530 << "initialized"; |
| 1526 } | 1531 } |
| 1527 } | 1532 } |
| 1528 | 1533 |
| 1529 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1534 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
| 1530 return failed_datatypes_handler_; | 1535 return failed_datatypes_handler_; |
| 1531 } | 1536 } |
| OLD | NEW |