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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #include "components/version_info/version_info_values.h" | 93 #include "components/version_info/version_info_values.h" |
94 #include "net/cookies/cookie_monster.h" | 94 #include "net/cookies/cookie_monster.h" |
95 #include "net/url_request/url_request_context_getter.h" | 95 #include "net/url_request/url_request_context_getter.h" |
96 #include "ui/base/l10n/l10n_util.h" | 96 #include "ui/base/l10n/l10n_util.h" |
97 #include "ui/base/l10n/time_format.h" | 97 #include "ui/base/l10n/time_format.h" |
98 | 98 |
99 #if defined(OS_ANDROID) | 99 #if defined(OS_ANDROID) |
100 #include "components/sync/core/read_transaction.h" | 100 #include "components/sync/core/read_transaction.h" |
101 #endif | 101 #endif |
102 | 102 |
103 using browser_sync::SyncBackendHost; | |
104 using sync_driver::ChangeProcessor; | 103 using sync_driver::ChangeProcessor; |
105 using sync_driver::DataTypeController; | 104 using sync_driver::DataTypeController; |
106 using sync_driver::DataTypeManager; | 105 using sync_driver::DataTypeManager; |
107 using sync_driver::DataTypeStatusTable; | 106 using sync_driver::DataTypeStatusTable; |
108 using sync_driver::DeviceInfoSyncService; | 107 using sync_driver::DeviceInfoSyncService; |
109 using sync_driver_v2::DeviceInfoService; | 108 using sync_driver_v2::DeviceInfoService; |
110 using sync_sessions::SessionsSyncManager; | 109 using sync_sessions::SessionsSyncManager; |
111 using syncer::ModelType; | 110 using syncer::ModelType; |
112 using syncer::ModelTypeSet; | 111 using syncer::ModelTypeSet; |
113 using syncer::JsBackend; | 112 using syncer::JsBackend; |
114 using syncer::JsController; | 113 using syncer::JsController; |
115 using syncer::JsEventDetails; | 114 using syncer::JsEventDetails; |
116 using syncer::JsEventHandler; | 115 using syncer::JsEventHandler; |
117 using syncer::ModelSafeRoutingInfo; | 116 using syncer::ModelSafeRoutingInfo; |
118 using syncer::SyncCredentials; | 117 using syncer::SyncCredentials; |
119 using syncer::SyncProtocolError; | 118 using syncer::SyncProtocolError; |
120 using syncer::WeakHandle; | 119 using syncer::WeakHandle; |
121 using syncer_v2::ModelTypeStore; | 120 using syncer_v2::ModelTypeStore; |
122 using syncer_v2::SharedModelTypeProcessor; | 121 using syncer_v2::SharedModelTypeProcessor; |
123 | 122 |
| 123 namespace browser_sync { |
| 124 |
124 typedef GoogleServiceAuthError AuthError; | 125 typedef GoogleServiceAuthError AuthError; |
125 | 126 |
126 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; | 127 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; |
127 | 128 |
128 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { | 129 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { |
129 // Number of initial errors (in sequence) to ignore before applying | 130 // Number of initial errors (in sequence) to ignore before applying |
130 // exponential back-off rules. | 131 // exponential back-off rules. |
131 0, | 132 0, |
132 | 133 |
133 // Initial delay for exponential back-off in ms. | 134 // Initial delay for exponential back-off in ms. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 264 |
264 bool ProfileSyncService::CanSyncStart() const { | 265 bool ProfileSyncService::CanSyncStart() const { |
265 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); | 266 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); |
266 } | 267 } |
267 | 268 |
268 void ProfileSyncService::Initialize() { | 269 void ProfileSyncService::Initialize() { |
269 sync_client_->Initialize(); | 270 sync_client_->Initialize(); |
270 | 271 |
271 // We don't pass StartupController an Unretained reference to future-proof | 272 // We don't pass StartupController an Unretained reference to future-proof |
272 // against the controller impl changing to post tasks. | 273 // against the controller impl changing to post tasks. |
273 startup_controller_.reset(new browser_sync::StartupController( | 274 startup_controller_.reset(new StartupController( |
274 &sync_prefs_, | 275 &sync_prefs_, |
275 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)), | 276 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)), |
276 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | 277 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
277 weak_factory_.GetWeakPtr()))); | 278 weak_factory_.GetWeakPtr()))); |
278 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router( | 279 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router( |
279 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); | 280 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); |
280 local_device_ = sync_client_->GetSyncApiComponentFactory() | 281 local_device_ = sync_client_->GetSyncApiComponentFactory() |
281 ->CreateLocalDeviceInfoProvider(); | 282 ->CreateLocalDeviceInfoProvider(); |
282 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( | 283 sync_stopped_reporter_.reset(new SyncStoppedReporter( |
283 sync_service_url_, local_device_->GetSyncUserAgent(), | 284 sync_service_url_, local_device_->GetSyncUserAgent(), |
284 url_request_context_, | 285 url_request_context_, SyncStoppedReporter::ResultCallback())); |
285 browser_sync::SyncStoppedReporter::ResultCallback())); | |
286 sessions_sync_manager_.reset(new SessionsSyncManager( | 286 sessions_sync_manager_.reset(new SessionsSyncManager( |
287 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), | 287 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), |
288 std::move(router), | 288 std::move(router), |
289 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, | 289 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, |
290 sync_enabled_weak_factory_.GetWeakPtr()), | 290 sync_enabled_weak_factory_.GetWeakPtr()), |
291 base::Bind(&ProfileSyncService::TriggerRefresh, | 291 base::Bind(&ProfileSyncService::TriggerRefresh, |
292 sync_enabled_weak_factory_.GetWeakPtr(), | 292 sync_enabled_weak_factory_.GetWeakPtr(), |
293 syncer::ModelTypeSet(syncer::SESSIONS)))); | 293 syncer::ModelTypeSet(syncer::SESSIONS)))); |
294 | 294 |
295 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { | 295 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 base::Unretained(network_resources_.get()), | 517 base::Unretained(network_resources_.get()), |
518 url_request_context_, network_time_update_callback_); | 518 url_request_context_, network_time_update_callback_); |
519 | 519 |
520 backend_->Initialize( | 520 backend_->Initialize( |
521 this, std::move(sync_thread_), db_thread_, file_thread_, | 521 this, std::move(sync_thread_), db_thread_, file_thread_, |
522 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), | 522 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), |
523 credentials, delete_stale_data, | 523 credentials, delete_stale_data, |
524 std::unique_ptr<syncer::SyncManagerFactory>( | 524 std::unique_ptr<syncer::SyncManagerFactory>( |
525 new syncer::SyncManagerFactory()), | 525 new syncer::SyncManagerFactory()), |
526 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 526 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
527 base::Bind(browser_sync::ChromeReportUnrecoverableError, channel_), | 527 base::Bind(ChromeReportUnrecoverableError, channel_), |
528 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 528 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
529 } | 529 } |
530 | 530 |
531 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 531 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
532 if (encryption_pending()) | 532 if (encryption_pending()) |
533 return true; | 533 return true; |
534 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); | 534 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
535 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); | 535 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); |
536 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); | 536 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); |
537 return !Intersection(preferred_types, encrypted_types).Empty(); | 537 return !Intersection(preferred_types, encrypted_types).Empty(); |
538 } | 538 } |
539 | 539 |
540 void ProfileSyncService::OnProtocolEvent(const syncer::ProtocolEvent& event) { | 540 void ProfileSyncService::OnProtocolEvent(const syncer::ProtocolEvent& event) { |
541 FOR_EACH_OBSERVER(browser_sync::ProtocolEventObserver, | 541 FOR_EACH_OBSERVER(ProtocolEventObserver, protocol_event_observers_, |
542 protocol_event_observers_, OnProtocolEvent(event)); | 542 OnProtocolEvent(event)); |
543 } | 543 } |
544 | 544 |
545 void ProfileSyncService::OnDirectoryTypeCommitCounterUpdated( | 545 void ProfileSyncService::OnDirectoryTypeCommitCounterUpdated( |
546 syncer::ModelType type, | 546 syncer::ModelType type, |
547 const syncer::CommitCounters& counters) { | 547 const syncer::CommitCounters& counters) { |
548 FOR_EACH_OBSERVER(syncer::TypeDebugInfoObserver, type_debug_info_observers_, | 548 FOR_EACH_OBSERVER(syncer::TypeDebugInfoObserver, type_debug_info_observers_, |
549 OnCommitCountersUpdated(type, counters)); | 549 OnCommitCountersUpdated(type, counters)); |
550 } | 550 } |
551 | 551 |
552 void ProfileSyncService::OnDirectoryTypeUpdateCounterUpdated( | 552 void ProfileSyncService::OnDirectoryTypeUpdateCounterUpdated( |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 // enabled, and yet we still think we require a passphrase for decryption. | 1380 // enabled, and yet we still think we require a passphrase for decryption. |
1381 DCHECK( | 1381 DCHECK( |
1382 !(IsPassphraseRequiredForDecryption() && !IsEncryptedDatatypeEnabled())); | 1382 !(IsPassphraseRequiredForDecryption() && !IsEncryptedDatatypeEnabled())); |
1383 | 1383 |
1384 // This must be done before we start syncing with the server to avoid | 1384 // This must be done before we start syncing with the server to avoid |
1385 // sending unencrypted data up on a first time sync. | 1385 // sending unencrypted data up on a first time sync. |
1386 if (encryption_pending_) | 1386 if (encryption_pending_) |
1387 backend_->EnableEncryptEverything(); | 1387 backend_->EnableEncryptEverything(); |
1388 NotifyObservers(); | 1388 NotifyObservers(); |
1389 | 1389 |
1390 if (migrator_.get() && | 1390 if (migrator_.get() && migrator_->state() != BackendMigrator::IDLE) { |
1391 migrator_->state() != browser_sync::BackendMigrator::IDLE) { | |
1392 // Migration in progress. Let the migrator know we just finished | 1391 // Migration in progress. Let the migrator know we just finished |
1393 // configuring something. It will be up to the migrator to call | 1392 // configuring something. It will be up to the migrator to call |
1394 // StartSyncingWithServer() if migration is now finished. | 1393 // StartSyncingWithServer() if migration is now finished. |
1395 migrator_->OnConfigureDone(result); | 1394 migrator_->OnConfigureDone(result); |
1396 return; | 1395 return; |
1397 } | 1396 } |
1398 | 1397 |
1399 if (catch_up_configure_in_progress_) { | 1398 if (catch_up_configure_in_progress_) { |
1400 catch_up_configure_in_progress_ = false; | 1399 catch_up_configure_in_progress_ = false; |
1401 ClearAndRestartSyncForPassphraseEncryption(); | 1400 ClearAndRestartSyncForPassphraseEncryption(); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1754 |
1756 bool restart = false; | 1755 bool restart = false; |
1757 if (!data_type_manager_) { | 1756 if (!data_type_manager_) { |
1758 restart = true; | 1757 restart = true; |
1759 data_type_manager_.reset( | 1758 data_type_manager_.reset( |
1760 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( | 1759 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( |
1761 debug_info_listener_, &data_type_controllers_, this, backend_.get(), | 1760 debug_info_listener_, &data_type_controllers_, this, backend_.get(), |
1762 this)); | 1761 this)); |
1763 | 1762 |
1764 // We create the migrator at the same time. | 1763 // We create the migrator at the same time. |
1765 migrator_.reset(new browser_sync::BackendMigrator( | 1764 migrator_.reset(new BackendMigrator( |
1766 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), | 1765 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), |
1767 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1766 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
1768 base::Unretained(this)))); | 1767 base::Unretained(this)))); |
1769 } | 1768 } |
1770 | 1769 |
1771 syncer::ModelTypeSet types; | 1770 syncer::ModelTypeSet types; |
1772 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1771 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
1773 types = GetPreferredDataTypes(); | 1772 types = GetPreferredDataTypes(); |
1774 if (restart) { | 1773 if (restart) { |
1775 // Datatype downloads on restart are generally due to newly supported | 1774 // Datatype downloads on restart are generally due to newly supported |
(...skipping 25 matching lines...) Expand all Loading... |
1801 } | 1800 } |
1802 | 1801 |
1803 bool ProfileSyncService::HasUnsyncedItems() const { | 1802 bool ProfileSyncService::HasUnsyncedItems() const { |
1804 if (HasSyncingBackend() && backend_initialized_) { | 1803 if (HasSyncingBackend() && backend_initialized_) { |
1805 return backend_->HasUnsyncedItems(); | 1804 return backend_->HasUnsyncedItems(); |
1806 } | 1805 } |
1807 NOTREACHED(); | 1806 NOTREACHED(); |
1808 return false; | 1807 return false; |
1809 } | 1808 } |
1810 | 1809 |
1811 browser_sync::BackendMigrator* ProfileSyncService::GetBackendMigratorForTest() { | 1810 BackendMigrator* ProfileSyncService::GetBackendMigratorForTest() { |
1812 return migrator_.get(); | 1811 return migrator_.get(); |
1813 } | 1812 } |
1814 | 1813 |
1815 void ProfileSyncService::GetModelSafeRoutingInfo( | 1814 void ProfileSyncService::GetModelSafeRoutingInfo( |
1816 syncer::ModelSafeRoutingInfo* out) const { | 1815 syncer::ModelSafeRoutingInfo* out) const { |
1817 if (backend_.get() && backend_initialized_) { | 1816 if (backend_.get() && backend_initialized_) { |
1818 backend_->GetModelSafeRoutingInfo(out); | 1817 backend_->GetModelSafeRoutingInfo(out); |
1819 } else { | 1818 } else { |
1820 NOTREACHED(); | 1819 NOTREACHED(); |
1821 } | 1820 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 sync_driver::SyncServiceObserver* observer) { | 2108 sync_driver::SyncServiceObserver* observer) { |
2110 observers_.AddObserver(observer); | 2109 observers_.AddObserver(observer); |
2111 } | 2110 } |
2112 | 2111 |
2113 void ProfileSyncService::RemoveObserver( | 2112 void ProfileSyncService::RemoveObserver( |
2114 sync_driver::SyncServiceObserver* observer) { | 2113 sync_driver::SyncServiceObserver* observer) { |
2115 observers_.RemoveObserver(observer); | 2114 observers_.RemoveObserver(observer); |
2116 } | 2115 } |
2117 | 2116 |
2118 void ProfileSyncService::AddProtocolEventObserver( | 2117 void ProfileSyncService::AddProtocolEventObserver( |
2119 browser_sync::ProtocolEventObserver* observer) { | 2118 ProtocolEventObserver* observer) { |
2120 protocol_event_observers_.AddObserver(observer); | 2119 protocol_event_observers_.AddObserver(observer); |
2121 if (HasSyncingBackend()) { | 2120 if (HasSyncingBackend()) { |
2122 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); | 2121 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); |
2123 } | 2122 } |
2124 } | 2123 } |
2125 | 2124 |
2126 void ProfileSyncService::RemoveProtocolEventObserver( | 2125 void ProfileSyncService::RemoveProtocolEventObserver( |
2127 browser_sync::ProtocolEventObserver* observer) { | 2126 ProtocolEventObserver* observer) { |
2128 protocol_event_observers_.RemoveObserver(observer); | 2127 protocol_event_observers_.RemoveObserver(observer); |
2129 if (HasSyncingBackend() && | 2128 if (HasSyncingBackend() && |
2130 !protocol_event_observers_.might_have_observers()) { | 2129 !protocol_event_observers_.might_have_observers()) { |
2131 backend_->DisableProtocolEventForwarding(); | 2130 backend_->DisableProtocolEventForwarding(); |
2132 } | 2131 } |
2133 } | 2132 } |
2134 | 2133 |
2135 void ProfileSyncService::AddTypeDebugInfoObserver( | 2134 void ProfileSyncService::AddTypeDebugInfoObserver( |
2136 syncer::TypeDebugInfoObserver* type_debug_info_observer) { | 2135 syncer::TypeDebugInfoObserver* type_debug_info_observer) { |
2137 type_debug_info_observers_.AddObserver(type_debug_info_observer); | 2136 type_debug_info_observers_.AddObserver(type_debug_info_observer); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 if (--outstanding_setup_in_progress_handles_ != 0) | 2502 if (--outstanding_setup_in_progress_handles_ != 0) |
2504 return; | 2503 return; |
2505 | 2504 |
2506 DCHECK(startup_controller_->IsSetupInProgress()); | 2505 DCHECK(startup_controller_->IsSetupInProgress()); |
2507 startup_controller_->SetSetupInProgress(false); | 2506 startup_controller_->SetSetupInProgress(false); |
2508 | 2507 |
2509 if (IsBackendInitialized()) | 2508 if (IsBackendInitialized()) |
2510 ReconfigureDatatypeManager(); | 2509 ReconfigureDatatypeManager(); |
2511 NotifyObservers(); | 2510 NotifyObservers(); |
2512 } | 2511 } |
| 2512 |
| 2513 } // namespace browser_sync |
OLD | NEW |