| 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 "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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 #include "sync/internal_api/public/util/sync_string_conversions.h" | 96 #include "sync/internal_api/public/util/sync_string_conversions.h" |
| 97 #include "sync/js/js_event_details.h" | 97 #include "sync/js/js_event_details.h" |
| 98 #include "sync/util/cryptographer.h" | 98 #include "sync/util/cryptographer.h" |
| 99 #include "ui/base/l10n/l10n_util.h" | 99 #include "ui/base/l10n/l10n_util.h" |
| 100 #include "ui/base/l10n/time_format.h" | 100 #include "ui/base/l10n/time_format.h" |
| 101 | 101 |
| 102 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
| 103 #include "sync/internal_api/public/read_transaction.h" | 103 #include "sync/internal_api/public/read_transaction.h" |
| 104 #endif | 104 #endif |
| 105 | 105 |
| 106 using browser_sync::ChangeProcessor; | |
| 107 using browser_sync::DataTypeController; | |
| 108 using browser_sync::DataTypeManager; | |
| 109 using browser_sync::FailedDataTypesHandler; | |
| 110 using browser_sync::NotificationServiceSessionsRouter; | 106 using browser_sync::NotificationServiceSessionsRouter; |
| 111 using browser_sync::ProfileSyncServiceStartBehavior; | 107 using browser_sync::ProfileSyncServiceStartBehavior; |
| 112 using browser_sync::SyncBackendHost; | 108 using browser_sync::SyncBackendHost; |
| 109 using sync_driver::ChangeProcessor; |
| 110 using sync_driver::DataTypeController; |
| 111 using sync_driver::DataTypeManager; |
| 112 using sync_driver::FailedDataTypesHandler; |
| 113 using syncer::ModelType; | 113 using syncer::ModelType; |
| 114 using syncer::ModelTypeSet; | 114 using syncer::ModelTypeSet; |
| 115 using syncer::JsBackend; | 115 using syncer::JsBackend; |
| 116 using syncer::JsController; | 116 using syncer::JsController; |
| 117 using syncer::JsEventDetails; | 117 using syncer::JsEventDetails; |
| 118 using syncer::JsEventHandler; | 118 using syncer::JsEventHandler; |
| 119 using syncer::ModelSafeRoutingInfo; | 119 using syncer::ModelSafeRoutingInfo; |
| 120 using syncer::SyncCredentials; | 120 using syncer::SyncCredentials; |
| 121 using syncer::SyncProtocolError; | 121 using syncer::SyncProtocolError; |
| 122 using syncer::WeakHandle; | 122 using syncer::WeakHandle; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 if (HasSyncingBackend()) { | 481 if (HasSyncingBackend()) { |
| 482 browser_sync::SyncedDeviceTracker* device_tracker = | 482 browser_sync::SyncedDeviceTracker* device_tracker = |
| 483 backend_->GetSyncedDeviceTracker(); | 483 backend_->GetSyncedDeviceTracker(); |
| 484 if (device_tracker) { | 484 if (device_tracker) { |
| 485 device_tracker->RemoveObserver(observer); | 485 device_tracker->RemoveObserver(observer); |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 void ProfileSyncService::GetDataTypeControllerStates( | 490 void ProfileSyncService::GetDataTypeControllerStates( |
| 491 browser_sync::DataTypeController::StateMap* state_map) const { | 491 DataTypeController::StateMap* state_map) const { |
| 492 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = | 492 for (DataTypeController::TypeMap::const_iterator iter = |
| 493 directory_data_type_controllers_.begin(); | 493 directory_data_type_controllers_.begin(); |
| 494 iter != directory_data_type_controllers_.end(); | 494 iter != directory_data_type_controllers_.end(); |
| 495 ++iter) | 495 ++iter) |
| 496 (*state_map)[iter->first] = iter->second.get()->state(); | 496 (*state_map)[iter->first] = iter->second.get()->state(); |
| 497 } | 497 } |
| 498 | 498 |
| 499 SyncCredentials ProfileSyncService::GetCredentials() { | 499 SyncCredentials ProfileSyncService::GetCredentials() { |
| 500 SyncCredentials credentials; | 500 SyncCredentials credentials; |
| 501 if (backend_mode_ == SYNC) { | 501 if (backend_mode_ == SYNC) { |
| 502 credentials.email = signin_->GetEffectiveUsername(); | 502 credentials.email = signin_->GetEffectiveUsername(); |
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 break; | 1452 break; |
| 1453 default: | 1453 default: |
| 1454 NOTREACHED(); | 1454 NOTREACHED(); |
| 1455 } | 1455 } |
| 1456 NotifyObservers(); | 1456 NotifyObservers(); |
| 1457 | 1457 |
| 1458 backup_rollback_controller_.Start(base::TimeDelta()); | 1458 backup_rollback_controller_.Start(base::TimeDelta()); |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 void ProfileSyncService::OnConfigureDone( | 1461 void ProfileSyncService::OnConfigureDone( |
| 1462 const browser_sync::DataTypeManager::ConfigureResult& result) { | 1462 const DataTypeManager::ConfigureResult& result) { |
| 1463 // We should have cleared our cached passphrase before we get here (in | 1463 // We should have cleared our cached passphrase before we get here (in |
| 1464 // OnBackendInitialized()). | 1464 // OnBackendInitialized()). |
| 1465 DCHECK(cached_passphrase_.empty()); | 1465 DCHECK(cached_passphrase_.empty()); |
| 1466 | 1466 |
| 1467 configure_status_ = result.status; | 1467 configure_status_ = result.status; |
| 1468 | 1468 |
| 1469 if (backend_mode_ != SYNC) { | 1469 if (backend_mode_ != SYNC) { |
| 1470 if (configure_status_ == DataTypeManager::OK || | 1470 if (configure_status_ == DataTypeManager::OK || |
| 1471 configure_status_ == DataTypeManager::PARTIAL_SUCCESS) { | 1471 configure_status_ == DataTypeManager::PARTIAL_SUCCESS) { |
| 1472 StartSyncingWithServer(); | 1472 StartSyncingWithServer(); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 void ProfileSyncService::UpdateSelectedTypesHistogram( | 1711 void ProfileSyncService::UpdateSelectedTypesHistogram( |
| 1712 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { | 1712 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { |
| 1713 if (!HasSyncSetupCompleted() || | 1713 if (!HasSyncSetupCompleted() || |
| 1714 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { | 1714 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { |
| 1715 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); | 1715 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); |
| 1716 } | 1716 } |
| 1717 | 1717 |
| 1718 // Only log the data types that are shown in the sync settings ui. | 1718 // Only log the data types that are shown in the sync settings ui. |
| 1719 // Note: the order of these types must match the ordering of | 1719 // Note: the order of these types must match the ordering of |
| 1720 // the respective types in ModelType | 1720 // the respective types in ModelType |
| 1721 const browser_sync::user_selectable_type::UserSelectableSyncType | 1721 const sync_driver::user_selectable_type::UserSelectableSyncType |
| 1722 user_selectable_types[] = { | 1722 user_selectable_types[] = { |
| 1723 browser_sync::user_selectable_type::BOOKMARKS, | 1723 sync_driver::user_selectable_type::BOOKMARKS, |
| 1724 browser_sync::user_selectable_type::PREFERENCES, | 1724 sync_driver::user_selectable_type::PREFERENCES, |
| 1725 browser_sync::user_selectable_type::PASSWORDS, | 1725 sync_driver::user_selectable_type::PASSWORDS, |
| 1726 browser_sync::user_selectable_type::AUTOFILL, | 1726 sync_driver::user_selectable_type::AUTOFILL, |
| 1727 browser_sync::user_selectable_type::THEMES, | 1727 sync_driver::user_selectable_type::THEMES, |
| 1728 browser_sync::user_selectable_type::TYPED_URLS, | 1728 sync_driver::user_selectable_type::TYPED_URLS, |
| 1729 browser_sync::user_selectable_type::EXTENSIONS, | 1729 sync_driver::user_selectable_type::EXTENSIONS, |
| 1730 browser_sync::user_selectable_type::APPS, | 1730 sync_driver::user_selectable_type::APPS, |
| 1731 browser_sync::user_selectable_type::PROXY_TABS | 1731 sync_driver::user_selectable_type::PROXY_TABS |
| 1732 }; | 1732 }; |
| 1733 | 1733 |
| 1734 COMPILE_ASSERT(32 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram); | 1734 COMPILE_ASSERT(32 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram); |
| 1735 | 1735 |
| 1736 if (!sync_everything) { | 1736 if (!sync_everything) { |
| 1737 const syncer::ModelTypeSet current_types = GetPreferredDataTypes(); | 1737 const syncer::ModelTypeSet current_types = GetPreferredDataTypes(); |
| 1738 | 1738 |
| 1739 syncer::ModelTypeSet type_set = syncer::UserSelectableTypes(); | 1739 syncer::ModelTypeSet type_set = syncer::UserSelectableTypes(); |
| 1740 syncer::ModelTypeSet::Iterator it = type_set.First(); | 1740 syncer::ModelTypeSet::Iterator it = type_set.First(); |
| 1741 | 1741 |
| 1742 DCHECK_EQ(arraysize(user_selectable_types), type_set.Size()); | 1742 DCHECK_EQ(arraysize(user_selectable_types), type_set.Size()); |
| 1743 | 1743 |
| 1744 for (size_t i = 0; i < arraysize(user_selectable_types) && it.Good(); | 1744 for (size_t i = 0; i < arraysize(user_selectable_types) && it.Good(); |
| 1745 ++i, it.Inc()) { | 1745 ++i, it.Inc()) { |
| 1746 const syncer::ModelType type = it.Get(); | 1746 const syncer::ModelType type = it.Get(); |
| 1747 if (chosen_types.Has(type) && | 1747 if (chosen_types.Has(type) && |
| 1748 (!HasSyncSetupCompleted() || !current_types.Has(type))) { | 1748 (!HasSyncSetupCompleted() || !current_types.Has(type))) { |
| 1749 // Selected type has changed - log it. | 1749 // Selected type has changed - log it. |
| 1750 UMA_HISTOGRAM_ENUMERATION( | 1750 UMA_HISTOGRAM_ENUMERATION( |
| 1751 "Sync.CustomSync", | 1751 "Sync.CustomSync", |
| 1752 user_selectable_types[i], | 1752 user_selectable_types[i], |
| 1753 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); | 1753 sync_driver::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); |
| 1754 } | 1754 } |
| 1755 } | 1755 } |
| 1756 } | 1756 } |
| 1757 } | 1757 } |
| 1758 | 1758 |
| 1759 #if defined(OS_CHROMEOS) | 1759 #if defined(OS_CHROMEOS) |
| 1760 void ProfileSyncService::RefreshSpareBootstrapToken( | 1760 void ProfileSyncService::RefreshSpareBootstrapToken( |
| 1761 const std::string& passphrase) { | 1761 const std::string& passphrase) { |
| 1762 browser_sync::SystemEncryptor encryptor; | 1762 sync_driver::SystemEncryptor encryptor; |
| 1763 syncer::Cryptographer temp_cryptographer(&encryptor); | 1763 syncer::Cryptographer temp_cryptographer(&encryptor); |
| 1764 // The first 2 params (hostname and username) doesn't have any effect here. | 1764 // The first 2 params (hostname and username) doesn't have any effect here. |
| 1765 syncer::KeyParams key_params = {"localhost", "dummy", passphrase}; | 1765 syncer::KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 1766 | 1766 |
| 1767 std::string bootstrap_token; | 1767 std::string bootstrap_token; |
| 1768 if (!temp_cryptographer.AddKey(key_params)) { | 1768 if (!temp_cryptographer.AddKey(key_params)) { |
| 1769 NOTREACHED() << "Failed to add key to cryptographer."; | 1769 NOTREACHED() << "Failed to add key to cryptographer."; |
| 1770 } | 1770 } |
| 1771 temp_cryptographer.GetBootstrapToken(&bootstrap_token); | 1771 temp_cryptographer.GetBootstrapToken(&bootstrap_token); |
| 1772 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); | 1772 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 browser_sync::SyncedDeviceTracker* device_tracker = | 2660 browser_sync::SyncedDeviceTracker* device_tracker = |
| 2661 backend_->GetSyncedDeviceTracker(); | 2661 backend_->GetSyncedDeviceTracker(); |
| 2662 if (device_tracker) | 2662 if (device_tracker) |
| 2663 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); | 2663 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); |
| 2664 } | 2664 } |
| 2665 } | 2665 } |
| 2666 | 2666 |
| 2667 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { | 2667 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { |
| 2668 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); | 2668 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); |
| 2669 } | 2669 } |
| OLD | NEW |