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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 #include "content/public/browser/notification_service.h" | 72 #include "content/public/browser/notification_service.h" |
73 #include "content/public/browser/notification_source.h" | 73 #include "content/public/browser/notification_source.h" |
74 #include "google_apis/gaia/gaia_constants.h" | 74 #include "google_apis/gaia/gaia_constants.h" |
75 #include "grit/generated_resources.h" | 75 #include "grit/generated_resources.h" |
76 #include "net/cookies/cookie_monster.h" | 76 #include "net/cookies/cookie_monster.h" |
77 #include "net/url_request/url_request_context_getter.h" | 77 #include "net/url_request/url_request_context_getter.h" |
78 #include "sync/api/sync_error.h" | 78 #include "sync/api/sync_error.h" |
79 #include "sync/internal_api/public/configure_reason.h" | 79 #include "sync/internal_api/public/configure_reason.h" |
80 #include "sync/internal_api/public/http_bridge_network_resources.h" | 80 #include "sync/internal_api/public/http_bridge_network_resources.h" |
81 #include "sync/internal_api/public/network_resources.h" | 81 #include "sync/internal_api/public/network_resources.h" |
82 #include "sync/internal_api/public/sync_core_proxy.h" | |
82 #include "sync/internal_api/public/sync_encryption_handler.h" | 83 #include "sync/internal_api/public/sync_encryption_handler.h" |
83 #include "sync/internal_api/public/util/experiments.h" | 84 #include "sync/internal_api/public/util/experiments.h" |
84 #include "sync/internal_api/public/util/sync_string_conversions.h" | 85 #include "sync/internal_api/public/util/sync_string_conversions.h" |
85 #include "sync/js/js_arg_list.h" | 86 #include "sync/js/js_arg_list.h" |
86 #include "sync/js/js_event_details.h" | 87 #include "sync/js/js_event_details.h" |
87 #include "sync/util/cryptographer.h" | 88 #include "sync/util/cryptographer.h" |
88 #include "ui/base/l10n/l10n_util.h" | 89 #include "ui/base/l10n/l10n_util.h" |
89 #include "ui/base/l10n/time_format.h" | 90 #include "ui/base/l10n/time_format.h" |
90 | 91 |
91 #if defined(ENABLE_MANAGED_USERS) | 92 #if defined(ENABLE_MANAGED_USERS) |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 | 339 |
339 void ProfileSyncService::UnregisterAuthNotifications() { | 340 void ProfileSyncService::UnregisterAuthNotifications() { |
340 if (signin()) | 341 if (signin()) |
341 signin()->RemoveObserver(this); | 342 signin()->RemoveObserver(this); |
342 oauth2_token_service_->RemoveObserver(this); | 343 oauth2_token_service_->RemoveObserver(this); |
343 } | 344 } |
344 | 345 |
345 void ProfileSyncService::RegisterDataTypeController( | 346 void ProfileSyncService::RegisterDataTypeController( |
346 DataTypeController* data_type_controller) { | 347 DataTypeController* data_type_controller) { |
347 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 348 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
349 DCHECK(!GetRegisteredNonBlockingDataTypes().Has( | |
350 data_type_controller->type())); | |
348 data_type_controllers_[data_type_controller->type()] = | 351 data_type_controllers_[data_type_controller->type()] = |
349 data_type_controller; | 352 data_type_controller; |
350 } | 353 } |
351 | 354 |
355 void ProfileSyncService::RegisterNonBlockingType(syncer::ModelType type) { | |
356 DCHECK_EQ(data_type_controllers_.count(type), 0U); | |
357 DCHECK(!GetRegisteredNonBlockingDataTypes().Has(type)); | |
358 non_blocking_types_.Put(type); | |
359 } | |
360 | |
352 browser_sync::SessionModelAssociator* | 361 browser_sync::SessionModelAssociator* |
353 ProfileSyncService::GetSessionModelAssociatorDeprecated() { | 362 ProfileSyncService::GetSessionModelAssociatorDeprecated() { |
354 if (!IsSessionsDataTypeControllerRunning()) | 363 if (!IsSessionsDataTypeControllerRunning()) |
355 return NULL; | 364 return NULL; |
356 | 365 |
357 // If we're using sessions V2, there's no model associator. | 366 // If we're using sessions V2, there's no model associator. |
358 if (sessions_sync_manager_.get()) | 367 if (sessions_sync_manager_.get()) |
359 return NULL; | 368 return NULL; |
360 | 369 |
361 return static_cast<browser_sync::SessionDataTypeController*>( | 370 return static_cast<browser_sync::SessionDataTypeController*>( |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 | 941 |
933 backend_initialized_ = true; | 942 backend_initialized_ = true; |
934 | 943 |
935 sync_js_controller_.AttachJsBackend(js_backend); | 944 sync_js_controller_.AttachJsBackend(js_backend); |
936 debug_info_listener_ = debug_info_listener; | 945 debug_info_listener_ = debug_info_listener; |
937 | 946 |
938 if (protocol_event_observers_.might_have_observers()) { | 947 if (protocol_event_observers_.might_have_observers()) { |
939 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); | 948 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); |
940 } | 949 } |
941 | 950 |
951 syncer::SyncCoreProxy sync_core_proxy_ = backend_->GetSyncCoreProxy(); | |
952 | |
942 // If we have a cached passphrase use it to decrypt/encrypt data now that the | 953 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
943 // backend is initialized. We want to call this before notifying observers in | 954 // backend is initialized. We want to call this before notifying observers in |
944 // case this operation affects the "passphrase required" status. | 955 // case this operation affects the "passphrase required" status. |
945 ConsumeCachedPassphraseIfPossible(); | 956 ConsumeCachedPassphraseIfPossible(); |
946 | 957 |
947 // The very first time the backend initializes is effectively the first time | 958 // The very first time the backend initializes is effectively the first time |
948 // we can say we successfully "synced". last_synced_time_ will only be null | 959 // we can say we successfully "synced". last_synced_time_ will only be null |
949 // in this case, because the pref wasn't restored on StartUp. | 960 // in this case, because the pref wasn't restored on StartUp. |
950 if (last_synced_time_.is_null()) { | 961 if (last_synced_time_.is_null()) { |
951 UpdateLastSyncedTime(); | 962 UpdateLastSyncedTime(); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1206 if (HasUnrecoverableError()) { | 1217 if (HasUnrecoverableError()) { |
1207 // When unrecoverable error is detected we post a task to shutdown the | 1218 // When unrecoverable error is detected we post a task to shutdown the |
1208 // backend. The task might not have executed yet. | 1219 // backend. The task might not have executed yet. |
1209 return; | 1220 return; |
1210 } | 1221 } |
1211 | 1222 |
1212 DVLOG(1) << "Passphrase required with reason: " | 1223 DVLOG(1) << "Passphrase required with reason: " |
1213 << syncer::PassphraseRequiredReasonToString(reason); | 1224 << syncer::PassphraseRequiredReasonToString(reason); |
1214 passphrase_required_reason_ = reason; | 1225 passphrase_required_reason_ = reason; |
1215 | 1226 |
1216 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1227 const syncer::ModelTypeSet types = GetPreferredDirectoryDataTypes(); |
Nicolas Zea
2014/04/03 20:36:08
It's unclear to me how we should trigger reconfigu
| |
1217 if (data_type_manager_) { | 1228 if (data_type_manager_) { |
1218 // Reconfigure without the encrypted types (excluded implicitly via the | 1229 // Reconfigure without the encrypted types (excluded implicitly via the |
1219 // failed datatypes handler). | 1230 // failed datatypes handler). |
1220 data_type_manager_->Configure(types, | 1231 data_type_manager_->Configure(types, |
1221 syncer::CONFIGURE_REASON_CRYPTO); | 1232 syncer::CONFIGURE_REASON_CRYPTO); |
1222 } | 1233 } |
1223 | 1234 |
1224 // Notify observers that the passphrase status may have changed. | 1235 // Notify observers that the passphrase status may have changed. |
1225 NotifyObservers(); | 1236 NotifyObservers(); |
1226 } | 1237 } |
1227 | 1238 |
1228 void ProfileSyncService::OnPassphraseAccepted() { | 1239 void ProfileSyncService::OnPassphraseAccepted() { |
1229 DVLOG(1) << "Received OnPassphraseAccepted."; | 1240 DVLOG(1) << "Received OnPassphraseAccepted."; |
1230 | 1241 |
1231 // If the pending keys were resolved via keystore, it's possible we never | 1242 // If the pending keys were resolved via keystore, it's possible we never |
1232 // consumed our cached passphrase. Clear it now. | 1243 // consumed our cached passphrase. Clear it now. |
1233 if (!cached_passphrase_.empty()) | 1244 if (!cached_passphrase_.empty()) |
1234 cached_passphrase_.clear(); | 1245 cached_passphrase_.clear(); |
1235 | 1246 |
1236 // Reset passphrase_required_reason_ since we know we no longer require the | 1247 // Reset passphrase_required_reason_ since we know we no longer require the |
1237 // passphrase. We do this here rather than down in ResolvePassphraseRequired() | 1248 // passphrase. We do this here rather than down in ResolvePassphraseRequired() |
1238 // because that can be called by OnPassphraseRequired() if no encrypted data | 1249 // because that can be called by OnPassphraseRequired() if no encrypted data |
1239 // types are enabled, and we don't want to clobber the true passphrase error. | 1250 // types are enabled, and we don't want to clobber the true passphrase error. |
1240 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 1251 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
1241 | 1252 |
1242 // Make sure the data types that depend on the passphrase are started at | 1253 // Make sure the data types that depend on the passphrase are started at |
1243 // this time. | 1254 // this time. |
1244 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1255 const syncer::ModelTypeSet types = GetPreferredDirectoryDataTypes(); |
1245 if (data_type_manager_) { | 1256 if (data_type_manager_) { |
1246 // Re-enable any encrypted types if necessary. | 1257 // Re-enable any encrypted types if necessary. |
1247 data_type_manager_->Configure(types, | 1258 data_type_manager_->Configure(types, |
1248 syncer::CONFIGURE_REASON_CRYPTO); | 1259 syncer::CONFIGURE_REASON_CRYPTO); |
1249 } | 1260 } |
1250 | 1261 |
1251 NotifyObservers(); | 1262 NotifyObservers(); |
1252 } | 1263 } |
1253 | 1264 |
1254 void ProfileSyncService::OnEncryptedTypesChanged( | 1265 void ProfileSyncService::OnEncryptedTypesChanged( |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1667 return Difference(preferred_types, failed_types); | 1678 return Difference(preferred_types, failed_types); |
1668 } | 1679 } |
1669 | 1680 |
1670 syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { | 1681 syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { |
1671 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1682 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
1672 const syncer::ModelTypeSet preferred_types = | 1683 const syncer::ModelTypeSet preferred_types = |
1673 sync_prefs_.GetPreferredDataTypes(registered_types); | 1684 sync_prefs_.GetPreferredDataTypes(registered_types); |
1674 return preferred_types; | 1685 return preferred_types; |
1675 } | 1686 } |
1676 | 1687 |
1688 syncer::ModelTypeSet | |
1689 ProfileSyncService::GetPreferredDirectoryDataTypes() const { | |
1690 const syncer::ModelTypeSet registered_directory_types = | |
1691 GetRegisteredDirectoryDataTypes(); | |
1692 const syncer::ModelTypeSet preferred_types = | |
1693 sync_prefs_.GetPreferredDataTypes(registered_directory_types); | |
1694 return preferred_types; | |
1695 } | |
1696 | |
1697 syncer::ModelTypeSet | |
1698 ProfileSyncService::GetPreferredNonBlockingDataTypes() const { | |
1699 return sync_prefs_.GetPreferredDataTypes(GetRegisteredNonBlockingDataTypes()); | |
1700 } | |
1701 | |
1677 syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { | 1702 syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { |
1703 return Union(GetRegisteredDirectoryDataTypes(), | |
1704 GetRegisteredNonBlockingDataTypes()); | |
1705 } | |
1706 | |
1707 syncer::ModelTypeSet | |
1708 ProfileSyncService::GetRegisteredDirectoryDataTypes() const { | |
1678 syncer::ModelTypeSet registered_types; | 1709 syncer::ModelTypeSet registered_types; |
1679 // The data_type_controllers_ are determined by command-line flags; that's | 1710 // The data_type_controllers_ are determined by command-line flags; that's |
1680 // effectively what controls the values returned here. | 1711 // effectively what controls the values returned here. |
1681 for (DataTypeController::TypeMap::const_iterator it = | 1712 for (DataTypeController::TypeMap::const_iterator it = |
1682 data_type_controllers_.begin(); | 1713 data_type_controllers_.begin(); |
1683 it != data_type_controllers_.end(); ++it) { | 1714 it != data_type_controllers_.end(); ++it) { |
1684 registered_types.Put(it->first); | 1715 registered_types.Put(it->first); |
1685 } | 1716 } |
1686 return registered_types; | 1717 return registered_types; |
1687 } | 1718 } |
1688 | 1719 |
1720 syncer::ModelTypeSet | |
1721 ProfileSyncService::GetRegisteredNonBlockingDataTypes() const { | |
1722 return non_blocking_types_; | |
1723 } | |
1724 | |
1689 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { | 1725 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { |
1690 syncer::PassphraseType passphrase_type = GetPassphraseType(); | 1726 syncer::PassphraseType passphrase_type = GetPassphraseType(); |
1691 return passphrase_type == syncer::FROZEN_IMPLICIT_PASSPHRASE || | 1727 return passphrase_type == syncer::FROZEN_IMPLICIT_PASSPHRASE || |
1692 passphrase_type == syncer::CUSTOM_PASSPHRASE; | 1728 passphrase_type == syncer::CUSTOM_PASSPHRASE; |
1693 } | 1729 } |
1694 | 1730 |
1695 syncer::PassphraseType ProfileSyncService::GetPassphraseType() const { | 1731 syncer::PassphraseType ProfileSyncService::GetPassphraseType() const { |
1696 return backend_->GetPassphraseType(); | 1732 return backend_->GetPassphraseType(); |
1697 } | 1733 } |
1698 | 1734 |
1699 base::Time ProfileSyncService::GetExplicitPassphraseTime() const { | 1735 base::Time ProfileSyncService::GetExplicitPassphraseTime() const { |
1700 return backend_->GetExplicitPassphraseTime(); | 1736 return backend_->GetExplicitPassphraseTime(); |
1701 } | 1737 } |
1702 | 1738 |
1703 bool ProfileSyncService::IsCryptographerReady( | 1739 bool ProfileSyncService::IsCryptographerReady( |
1704 const syncer::BaseTransaction* trans) const { | 1740 const syncer::BaseTransaction* trans) const { |
1705 return backend_.get() && backend_->IsCryptographerReady(trans); | 1741 return backend_.get() && backend_->IsCryptographerReady(trans); |
1706 } | 1742 } |
1707 | 1743 |
1708 void ProfileSyncService::ConfigurePriorityDataTypes() { | 1744 void ProfileSyncService::ConfigurePriorityDataTypes() { |
1709 const syncer::ModelTypeSet priority_types = | 1745 const syncer::ModelTypeSet priority_types = |
1710 Intersection(GetPreferredDataTypes(), syncer::PriorityUserTypes()); | 1746 Intersection(GetPreferredDirectoryDataTypes(), |
1747 syncer::PriorityUserTypes()); | |
1711 if (!priority_types.Empty()) { | 1748 if (!priority_types.Empty()) { |
1712 const syncer::ConfigureReason reason = HasSyncSetupCompleted() ? | 1749 const syncer::ConfigureReason reason = HasSyncSetupCompleted() ? |
1713 syncer::CONFIGURE_REASON_RECONFIGURATION : | 1750 syncer::CONFIGURE_REASON_RECONFIGURATION : |
1714 syncer::CONFIGURE_REASON_NEW_CLIENT; | 1751 syncer::CONFIGURE_REASON_NEW_CLIENT; |
1715 data_type_manager_->Configure(priority_types, reason); | 1752 data_type_manager_->Configure(priority_types, reason); |
1716 } | 1753 } |
1717 } | 1754 } |
1718 | 1755 |
1719 void ProfileSyncService::ConfigureDataTypeManager() { | 1756 void ProfileSyncService::ConfigureDataTypeManager() { |
1720 // Don't configure datatypes if the setup UI is still on the screen - this | 1757 // Don't configure datatypes if the setup UI is still on the screen - this |
(...skipping 17 matching lines...) Expand all Loading... | |
1738 | 1775 |
1739 // We create the migrator at the same time. | 1776 // We create the migrator at the same time. |
1740 migrator_.reset( | 1777 migrator_.reset( |
1741 new browser_sync::BackendMigrator( | 1778 new browser_sync::BackendMigrator( |
1742 profile_->GetDebugName(), GetUserShare(), | 1779 profile_->GetDebugName(), GetUserShare(), |
1743 this, data_type_manager_.get(), | 1780 this, data_type_manager_.get(), |
1744 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1781 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
1745 base::Unretained(this)))); | 1782 base::Unretained(this)))); |
1746 } | 1783 } |
1747 | 1784 |
1748 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1785 const syncer::ModelTypeSet types = GetPreferredDirectoryDataTypes(); |
1749 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1786 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
1750 if (!HasSyncSetupCompleted()) { | 1787 if (!HasSyncSetupCompleted()) { |
1751 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; | 1788 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; |
1752 } else if (restart) { | 1789 } else if (restart) { |
1753 // Datatype downloads on restart are generally due to newly supported | 1790 // Datatype downloads on restart are generally due to newly supported |
1754 // datatypes (although it's also possible we're picking up where a failed | 1791 // datatypes (although it's also possible we're picking up where a failed |
1755 // previous configuration left off). | 1792 // previous configuration left off). |
1756 // TODO(sync): consider detecting configuration recovery and setting | 1793 // TODO(sync): consider detecting configuration recovery and setting |
1757 // the reason here appropriately. | 1794 // the reason here appropriately. |
1758 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 1795 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1855 type_status->SetString("value", error_text); | 1892 type_status->SetString("value", error_text); |
1856 } else if (throttled_types.Has(type) && passive_types.Has(type)) { | 1893 } else if (throttled_types.Has(type) && passive_types.Has(type)) { |
1857 type_status->SetString("status", "warning"); | 1894 type_status->SetString("status", "warning"); |
1858 type_status->SetString("value", "Passive, Throttled"); | 1895 type_status->SetString("value", "Passive, Throttled"); |
1859 } else if (passive_types.Has(type)) { | 1896 } else if (passive_types.Has(type)) { |
1860 type_status->SetString("status", "warning"); | 1897 type_status->SetString("status", "warning"); |
1861 type_status->SetString("value", "Passive"); | 1898 type_status->SetString("value", "Passive"); |
1862 } else if (throttled_types.Has(type)) { | 1899 } else if (throttled_types.Has(type)) { |
1863 type_status->SetString("status", "warning"); | 1900 type_status->SetString("status", "warning"); |
1864 type_status->SetString("value", "Throttled"); | 1901 type_status->SetString("value", "Throttled"); |
1902 } else if (GetRegisteredNonBlockingDataTypes().Has(type)) { | |
1903 type_status->SetString("status", "ok"); | |
1904 type_status->SetString("value", "Non-Blocking"); | |
1865 } else if (active_types.Has(type)) { | 1905 } else if (active_types.Has(type)) { |
1866 type_status->SetString("status", "ok"); | 1906 type_status->SetString("status", "ok"); |
1867 type_status->SetString("value", "Active: " + | 1907 type_status->SetString("value", "Active: " + |
1868 ModelSafeGroupToString(routing_info[type])); | 1908 ModelSafeGroupToString(routing_info[type])); |
1869 } else { | 1909 } else { |
1870 type_status->SetString("status", "warning"); | 1910 type_status->SetString("status", "warning"); |
1871 type_status->SetString("value", "Disabled by User"); | 1911 type_status->SetString("value", "Disabled by User"); |
1872 } | 1912 } |
1873 | 1913 |
1874 int live_count = detailed_status.num_entries_by_type[type] - | 1914 int live_count = detailed_status.num_entries_by_type[type] - |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2215 status.last_get_token_error = last_get_token_error_; | 2255 status.last_get_token_error = last_get_token_error_; |
2216 if (request_access_token_retry_timer_.IsRunning()) | 2256 if (request_access_token_retry_timer_.IsRunning()) |
2217 status.next_token_request_time = next_token_request_time_; | 2257 status.next_token_request_time = next_token_request_time_; |
2218 return status; | 2258 return status; |
2219 } | 2259 } |
2220 | 2260 |
2221 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2261 void ProfileSyncService::OverrideNetworkResourcesForTest( |
2222 scoped_ptr<syncer::NetworkResources> network_resources) { | 2262 scoped_ptr<syncer::NetworkResources> network_resources) { |
2223 network_resources_ = network_resources.Pass(); | 2263 network_resources_ = network_resources.Pass(); |
2224 } | 2264 } |
OLD | NEW |