| 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/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 using browser_sync::ServerConnectionEventListener; | 71 using browser_sync::ServerConnectionEventListener; |
| 72 using browser_sync::SyncEngineEvent; | 72 using browser_sync::SyncEngineEvent; |
| 73 using browser_sync::SyncEngineEventListener; | 73 using browser_sync::SyncEngineEventListener; |
| 74 using browser_sync::SyncScheduler; | 74 using browser_sync::SyncScheduler; |
| 75 using browser_sync::Syncer; | 75 using browser_sync::Syncer; |
| 76 using browser_sync::WeakHandle; | 76 using browser_sync::WeakHandle; |
| 77 using browser_sync::sessions::SyncSessionContext; | 77 using browser_sync::sessions::SyncSessionContext; |
| 78 using syncable::DirectoryManager; | 78 using syncable::DirectoryManager; |
| 79 using syncable::ImmutableWriteTransactionInfo; | 79 using syncable::ImmutableWriteTransactionInfo; |
| 80 using syncable::ModelType; | 80 using syncable::ModelType; |
| 81 using syncable::ModelTypeBitSet; | 81 using syncable::ModelEnumSet; |
| 82 using syncable::SPECIFICS; | 82 using syncable::SPECIFICS; |
| 83 using sync_pb::GetUpdatesCallerInfo; | 83 using sync_pb::GetUpdatesCallerInfo; |
| 84 | 84 |
| 85 typedef GoogleServiceAuthError AuthError; | 85 typedef GoogleServiceAuthError AuthError; |
| 86 | 86 |
| 87 namespace { | 87 namespace { |
| 88 | 88 |
| 89 static const int kSyncSchedulerDelayMsec = 250; | 89 static const int kSyncSchedulerDelayMsec = 250; |
| 90 | 90 |
| 91 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 bool SignIn(const SyncCredentials& credentials); | 200 bool SignIn(const SyncCredentials& credentials); |
| 201 | 201 |
| 202 // Update tokens that we're using in Sync. Email must stay the same. | 202 // Update tokens that we're using in Sync. Email must stay the same. |
| 203 void UpdateCredentials(const SyncCredentials& credentials); | 203 void UpdateCredentials(const SyncCredentials& credentials); |
| 204 | 204 |
| 205 // Called when the user disables or enables a sync type. | 205 // Called when the user disables or enables a sync type. |
| 206 void UpdateEnabledTypes(); | 206 void UpdateEnabledTypes(); |
| 207 | 207 |
| 208 // Conditionally sets the flag in the Nigori node which instructs other | 208 // Conditionally sets the flag in the Nigori node which instructs other |
| 209 // clients to start syncing tabs. | 209 // clients to start syncing tabs. |
| 210 void MaybeSetSyncTabsInNigoriNode(syncable::ModelEnumSet enabled_types); | 210 void MaybeSetSyncTabsInNigoriNode(ModelEnumSet enabled_types); |
| 211 | 211 |
| 212 // Tell the sync engine to start the syncing process. | 212 // Tell the sync engine to start the syncing process. |
| 213 void StartSyncingNormally(); | 213 void StartSyncingNormally(); |
| 214 | 214 |
| 215 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 215 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 216 bool IsUsingExplicitPassphrase(); | 216 bool IsUsingExplicitPassphrase(); |
| 217 | 217 |
| 218 // Update the Cryptographer from the current nigori node and write back any | 218 // Update the Cryptographer from the current nigori node and write back any |
| 219 // necessary changes to the nigori node. We also detect missing encryption | 219 // necessary changes to the nigori node. We also detect missing encryption |
| 220 // keys and write them into the nigori node. | 220 // keys and write them into the nigori node. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 236 | 236 |
| 237 // Call periodically from a database-safe thread to persist recent changes | 237 // Call periodically from a database-safe thread to persist recent changes |
| 238 // to the syncapi model. | 238 // to the syncapi model. |
| 239 void SaveChanges(); | 239 void SaveChanges(); |
| 240 | 240 |
| 241 // DirectoryChangeDelegate implementation. | 241 // DirectoryChangeDelegate implementation. |
| 242 // This listener is called upon completion of a syncable transaction, and | 242 // This listener is called upon completion of a syncable transaction, and |
| 243 // builds the list of sync-engine initiated changes that will be forwarded to | 243 // builds the list of sync-engine initiated changes that will be forwarded to |
| 244 // the SyncManager's Observers. | 244 // the SyncManager's Observers. |
| 245 virtual void HandleTransactionCompleteChangeEvent( | 245 virtual void HandleTransactionCompleteChangeEvent( |
| 246 syncable::ModelEnumSet models_with_changes) OVERRIDE; | 246 ModelEnumSet models_with_changes) OVERRIDE; |
| 247 virtual syncable::ModelEnumSet HandleTransactionEndingChangeEvent( | 247 virtual ModelEnumSet HandleTransactionEndingChangeEvent( |
| 248 const ImmutableWriteTransactionInfo& write_transaction_info, | 248 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 249 syncable::BaseTransaction* trans) OVERRIDE; | 249 syncable::BaseTransaction* trans) OVERRIDE; |
| 250 virtual void HandleCalculateChangesChangeEventFromSyncApi( | 250 virtual void HandleCalculateChangesChangeEventFromSyncApi( |
| 251 const ImmutableWriteTransactionInfo& write_transaction_info, | 251 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 252 syncable::BaseTransaction* trans) OVERRIDE; | 252 syncable::BaseTransaction* trans) OVERRIDE; |
| 253 virtual void HandleCalculateChangesChangeEventFromSyncer( | 253 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 254 const ImmutableWriteTransactionInfo& write_transaction_info, | 254 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 255 syncable::BaseTransaction* trans) OVERRIDE; | 255 syncable::BaseTransaction* trans) OVERRIDE; |
| 256 | 256 |
| 257 // Listens for notifications from the ServerConnectionManager | 257 // Listens for notifications from the ServerConnectionManager |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 DCHECK(thread_checker_.CalledOnValidThread()); | 635 DCHECK(thread_checker_.CalledOnValidThread()); |
| 636 data_->UpdateCredentials(credentials); | 636 data_->UpdateCredentials(credentials); |
| 637 } | 637 } |
| 638 | 638 |
| 639 void SyncManager::UpdateEnabledTypes() { | 639 void SyncManager::UpdateEnabledTypes() { |
| 640 DCHECK(thread_checker_.CalledOnValidThread()); | 640 DCHECK(thread_checker_.CalledOnValidThread()); |
| 641 data_->UpdateEnabledTypes(); | 641 data_->UpdateEnabledTypes(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void SyncManager::MaybeSetSyncTabsInNigoriNode( | 644 void SyncManager::MaybeSetSyncTabsInNigoriNode( |
| 645 syncable::ModelEnumSet enabled_types) { | 645 ModelEnumSet enabled_types) { |
| 646 DCHECK(thread_checker_.CalledOnValidThread()); | 646 DCHECK(thread_checker_.CalledOnValidThread()); |
| 647 data_->MaybeSetSyncTabsInNigoriNode(enabled_types); | 647 data_->MaybeSetSyncTabsInNigoriNode(enabled_types); |
| 648 } | 648 } |
| 649 | 649 |
| 650 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { | 650 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { |
| 651 return data_->InitialSyncEndedForAllEnabledTypes(); | 651 return data_->InitialSyncEndedForAllEnabledTypes(); |
| 652 } | 652 } |
| 653 | 653 |
| 654 void SyncManager::StartSyncingNormally() { | 654 void SyncManager::StartSyncingNormally() { |
| 655 DCHECK(thread_checker_.CalledOnValidThread()); | 655 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 if (data_->scheduler()) | 694 if (data_->scheduler()) |
| 695 data_->scheduler()->ScheduleCleanupDisabledTypes(); | 695 data_->scheduler()->ScheduleCleanupDisabledTypes(); |
| 696 } | 696 } |
| 697 | 697 |
| 698 void SyncManager::RequestClearServerData() { | 698 void SyncManager::RequestClearServerData() { |
| 699 DCHECK(thread_checker_.CalledOnValidThread()); | 699 DCHECK(thread_checker_.CalledOnValidThread()); |
| 700 if (data_->scheduler()) | 700 if (data_->scheduler()) |
| 701 data_->scheduler()->ScheduleClearUserData(); | 701 data_->scheduler()->ScheduleClearUserData(); |
| 702 } | 702 } |
| 703 | 703 |
| 704 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types, | 704 void SyncManager::RequestConfig( |
| 705 ConfigureReason reason) { | 705 ModelEnumSet types, ConfigureReason reason) { |
| 706 DCHECK(thread_checker_.CalledOnValidThread()); | 706 DCHECK(thread_checker_.CalledOnValidThread()); |
| 707 if (!data_->scheduler()) { | 707 if (!data_->scheduler()) { |
| 708 LOG(INFO) | 708 LOG(INFO) |
| 709 << "SyncManager::RequestConfig: bailing out because scheduler is " | 709 << "SyncManager::RequestConfig: bailing out because scheduler is " |
| 710 << "null"; | 710 << "null"; |
| 711 return; | 711 return; |
| 712 } | 712 } |
| 713 StartConfigurationMode(base::Closure()); | 713 StartConfigurationMode(base::Closure()); |
| 714 data_->scheduler()->ScheduleConfig( | 714 data_->scheduler()->ScheduleConfig(types, GetSourceFromReason(reason)); |
| 715 syncable::ModelTypeBitSetToEnumSet(types), | |
| 716 GetSourceFromReason(reason)); | |
| 717 } | 715 } |
| 718 | 716 |
| 719 void SyncManager::StartConfigurationMode(const base::Closure& callback) { | 717 void SyncManager::StartConfigurationMode(const base::Closure& callback) { |
| 720 DCHECK(thread_checker_.CalledOnValidThread()); | 718 DCHECK(thread_checker_.CalledOnValidThread()); |
| 721 if (!data_->scheduler()) { | 719 if (!data_->scheduler()) { |
| 722 LOG(INFO) | 720 LOG(INFO) |
| 723 << "SyncManager::StartConfigurationMode: could not start " | 721 << "SyncManager::StartConfigurationMode: could not start " |
| 724 << "configuration mode because because scheduler is null"; | 722 << "configuration mode because because scheduler is null"; |
| 725 return; | 723 return; |
| 726 } | 724 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, | 958 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, |
| 961 weak_ptr_factory_.GetWeakPtr())); | 959 weak_ptr_factory_.GetWeakPtr())); |
| 962 } | 960 } |
| 963 } | 961 } |
| 964 } | 962 } |
| 965 | 963 |
| 966 void SyncManager::SyncInternal::UpdateEnabledTypes() { | 964 void SyncManager::SyncInternal::UpdateEnabledTypes() { |
| 967 DCHECK(thread_checker_.CalledOnValidThread()); | 965 DCHECK(thread_checker_.CalledOnValidThread()); |
| 968 ModelSafeRoutingInfo routes; | 966 ModelSafeRoutingInfo routes; |
| 969 registrar_->GetModelSafeRoutingInfo(&routes); | 967 registrar_->GetModelSafeRoutingInfo(&routes); |
| 970 const syncable::ModelEnumSet enabled_types = GetRoutingInfoTypes(routes); | 968 const ModelEnumSet enabled_types = GetRoutingInfoTypes(routes); |
| 971 sync_notifier_->UpdateEnabledTypes(enabled_types); | 969 sync_notifier_->UpdateEnabledTypes(enabled_types); |
| 972 if (CommandLine::ForCurrentProcess()->HasSwitch( | 970 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 973 switches::kEnableSyncTabsForOtherClients)) { | 971 switches::kEnableSyncTabsForOtherClients)) { |
| 974 MaybeSetSyncTabsInNigoriNode(enabled_types); | 972 MaybeSetSyncTabsInNigoriNode(enabled_types); |
| 975 } | 973 } |
| 976 } | 974 } |
| 977 | 975 |
| 978 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode( | 976 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode( |
| 979 const syncable::ModelEnumSet enabled_types) { | 977 const ModelEnumSet enabled_types) { |
| 980 // The initialized_ check is to ensure that we don't CHECK in GetUserShare | 978 // The initialized_ check is to ensure that we don't CHECK in GetUserShare |
| 981 // when this is called on start-up. It's ok to ignore that case, since | 979 // when this is called on start-up. It's ok to ignore that case, since |
| 982 // presumably this would've run when the user originally enabled sessions. | 980 // presumably this would've run when the user originally enabled sessions. |
| 983 if (initialized_ && enabled_types.Has(syncable::SESSIONS)) { | 981 if (initialized_ && enabled_types.Has(syncable::SESSIONS)) { |
| 984 WriteTransaction trans(FROM_HERE, GetUserShare()); | 982 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 985 WriteNode node(&trans); | 983 WriteNode node(&trans); |
| 986 if (!node.InitByTagLookup(kNigoriTag)) { | 984 if (!node.InitByTagLookup(kNigoriTag)) { |
| 987 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not " | 985 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not " |
| 988 << "found."; | 986 << "found."; |
| 989 return; | 987 return; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 } | 1342 } |
| 1345 | 1343 |
| 1346 if (event.connection_code == | 1344 if (event.connection_code == |
| 1347 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { | 1345 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { |
| 1348 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1346 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1349 OnAuthError(AuthError(AuthError::CONNECTION_FAILED))); | 1347 OnAuthError(AuthError(AuthError::CONNECTION_FAILED))); |
| 1350 } | 1348 } |
| 1351 } | 1349 } |
| 1352 | 1350 |
| 1353 void SyncManager::SyncInternal::HandleTransactionCompleteChangeEvent( | 1351 void SyncManager::SyncInternal::HandleTransactionCompleteChangeEvent( |
| 1354 syncable::ModelEnumSet models_with_changes) { | 1352 ModelEnumSet models_with_changes) { |
| 1355 // This notification happens immediately after the transaction mutex is | 1353 // This notification happens immediately after the transaction mutex is |
| 1356 // released. This allows work to be performed without blocking other threads | 1354 // released. This allows work to be performed without blocking other threads |
| 1357 // from acquiring a transaction. | 1355 // from acquiring a transaction. |
| 1358 if (!change_delegate_) | 1356 if (!change_delegate_) |
| 1359 return; | 1357 return; |
| 1360 | 1358 |
| 1361 // Call commit. | 1359 // Call commit. |
| 1362 for (syncable::ModelEnumSet::Iterator it = models_with_changes.First(); | 1360 for (ModelEnumSet::Iterator it = models_with_changes.First(); |
| 1363 it.Good(); it.Inc()) { | 1361 it.Good(); it.Inc()) { |
| 1364 change_delegate_->OnChangesComplete(it.Get()); | 1362 change_delegate_->OnChangesComplete(it.Get()); |
| 1365 change_observer_.Call( | 1363 change_observer_.Call( |
| 1366 FROM_HERE, &SyncManager::ChangeObserver::OnChangesComplete, it.Get()); | 1364 FROM_HERE, &SyncManager::ChangeObserver::OnChangesComplete, it.Get()); |
| 1367 } | 1365 } |
| 1368 } | 1366 } |
| 1369 | 1367 |
| 1370 syncable::ModelEnumSet | 1368 ModelEnumSet |
| 1371 SyncManager::SyncInternal::HandleTransactionEndingChangeEvent( | 1369 SyncManager::SyncInternal::HandleTransactionEndingChangeEvent( |
| 1372 const ImmutableWriteTransactionInfo& write_transaction_info, | 1370 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 1373 syncable::BaseTransaction* trans) { | 1371 syncable::BaseTransaction* trans) { |
| 1374 // This notification happens immediately before a syncable WriteTransaction | 1372 // This notification happens immediately before a syncable WriteTransaction |
| 1375 // falls out of scope. It happens while the channel mutex is still held, | 1373 // falls out of scope. It happens while the channel mutex is still held, |
| 1376 // and while the transaction mutex is held, so it cannot be re-entrant. | 1374 // and while the transaction mutex is held, so it cannot be re-entrant. |
| 1377 if (!change_delegate_ || ChangeBuffersAreEmpty()) | 1375 if (!change_delegate_ || ChangeBuffersAreEmpty()) |
| 1378 return syncable::ModelEnumSet(); | 1376 return ModelEnumSet(); |
| 1379 | 1377 |
| 1380 // This will continue the WriteTransaction using a read only wrapper. | 1378 // This will continue the WriteTransaction using a read only wrapper. |
| 1381 // This is the last chance for read to occur in the WriteTransaction | 1379 // This is the last chance for read to occur in the WriteTransaction |
| 1382 // that's closing. This special ReadTransaction will not close the | 1380 // that's closing. This special ReadTransaction will not close the |
| 1383 // underlying transaction. | 1381 // underlying transaction. |
| 1384 ReadTransaction read_trans(GetUserShare(), trans); | 1382 ReadTransaction read_trans(GetUserShare(), trans); |
| 1385 | 1383 |
| 1386 syncable::ModelEnumSet models_with_changes; | 1384 ModelEnumSet models_with_changes; |
| 1387 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1385 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 1388 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1386 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 1389 const syncable::ModelType type = syncable::ModelTypeFromInt(i); | 1387 const syncable::ModelType type = syncable::ModelTypeFromInt(i); |
| 1390 if (change_buffers_[type].IsEmpty()) | 1388 if (change_buffers_[type].IsEmpty()) |
| 1391 continue; | 1389 continue; |
| 1392 | 1390 |
| 1393 ImmutableChangeRecordList ordered_changes; | 1391 ImmutableChangeRecordList ordered_changes; |
| 1394 // TODO(akalin): Propagate up the error further (see | 1392 // TODO(akalin): Propagate up the error further (see |
| 1395 // http://crbug.com/100907). | 1393 // http://crbug.com/100907). |
| 1396 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, | 1394 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 | 1529 |
| 1532 SyncManager::Status SyncManager::SyncInternal::GetStatus() { | 1530 SyncManager::Status SyncManager::SyncInternal::GetStatus() { |
| 1533 return allstatus_.status(); | 1531 return allstatus_.status(); |
| 1534 } | 1532 } |
| 1535 | 1533 |
| 1536 void SyncManager::SyncInternal::RequestNudge( | 1534 void SyncManager::SyncInternal::RequestNudge( |
| 1537 const tracked_objects::Location& location) { | 1535 const tracked_objects::Location& location) { |
| 1538 if (scheduler()) | 1536 if (scheduler()) |
| 1539 scheduler()->ScheduleNudge( | 1537 scheduler()->ScheduleNudge( |
| 1540 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, | 1538 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, |
| 1541 syncable::ModelEnumSet(), location); | 1539 ModelEnumSet(), location); |
| 1542 } | 1540 } |
| 1543 | 1541 |
| 1544 void SyncManager::SyncInternal::RequestNudgeForDataType( | 1542 void SyncManager::SyncInternal::RequestNudgeForDataType( |
| 1545 const tracked_objects::Location& nudge_location, | 1543 const tracked_objects::Location& nudge_location, |
| 1546 const ModelType& type) { | 1544 const ModelType& type) { |
| 1547 if (!scheduler()) { | 1545 if (!scheduler()) { |
| 1548 NOTREACHED(); | 1546 NOTREACHED(); |
| 1549 return; | 1547 return; |
| 1550 } | 1548 } |
| 1551 base::TimeDelta nudge_delay; | 1549 base::TimeDelta nudge_delay; |
| 1552 switch (type) { | 1550 switch (type) { |
| 1553 case syncable::PREFERENCES: | 1551 case syncable::PREFERENCES: |
| 1554 nudge_delay = | 1552 nudge_delay = |
| 1555 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); | 1553 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); |
| 1556 break; | 1554 break; |
| 1557 case syncable::SESSIONS: | 1555 case syncable::SESSIONS: |
| 1558 nudge_delay = scheduler()->sessions_commit_delay(); | 1556 nudge_delay = scheduler()->sessions_commit_delay(); |
| 1559 break; | 1557 break; |
| 1560 default: | 1558 default: |
| 1561 nudge_delay = | 1559 nudge_delay = |
| 1562 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds); | 1560 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds); |
| 1563 break; | 1561 break; |
| 1564 } | 1562 } |
| 1565 scheduler()->ScheduleNudge(nudge_delay, | 1563 scheduler()->ScheduleNudge(nudge_delay, |
| 1566 browser_sync::NUDGE_SOURCE_LOCAL, | 1564 browser_sync::NUDGE_SOURCE_LOCAL, |
| 1567 syncable::ModelEnumSet(type), | 1565 ModelEnumSet(type), |
| 1568 nudge_location); | 1566 nudge_location); |
| 1569 } | 1567 } |
| 1570 | 1568 |
| 1571 void SyncManager::SyncInternal::OnSyncEngineEvent( | 1569 void SyncManager::SyncInternal::OnSyncEngineEvent( |
| 1572 const SyncEngineEvent& event) { | 1570 const SyncEngineEvent& event) { |
| 1573 DCHECK(thread_checker_.CalledOnValidThread()); | 1571 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1574 // Only send an event if this is due to a cycle ending and this cycle | 1572 // Only send an event if this is due to a cycle ending and this cycle |
| 1575 // concludes a canonical "sync" process; that is, based on what is known | 1573 // concludes a canonical "sync" process; that is, based on what is known |
| 1576 // locally we are "all happy" and up-to-date. There may be new changes on | 1574 // locally we are "all happy" and up-to-date. There may be new changes on |
| 1577 // the server, but we'll get them on a subsequent sync. | 1575 // the server, but we'll get them on a subsequent sync. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 | 1617 |
| 1620 // This is here for tests, which are still using p2p notifications. | 1618 // This is here for tests, which are still using p2p notifications. |
| 1621 // | 1619 // |
| 1622 // TODO(chron): Consider changing this back to track has_more_to_sync | 1620 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 1623 // only notify peers if a successful commit has occurred. | 1621 // only notify peers if a successful commit has occurred. |
| 1624 bool is_notifiable_commit = | 1622 bool is_notifiable_commit = |
| 1625 (event.snapshot->syncer_status.num_successful_commits > 0); | 1623 (event.snapshot->syncer_status.num_successful_commits > 0); |
| 1626 if (is_notifiable_commit) { | 1624 if (is_notifiable_commit) { |
| 1627 allstatus_.IncrementNotifiableCommits(); | 1625 allstatus_.IncrementNotifiableCommits(); |
| 1628 if (sync_notifier_.get()) { | 1626 if (sync_notifier_.get()) { |
| 1629 const syncable::ModelEnumSet changed_types = | 1627 const ModelEnumSet changed_types = |
| 1630 syncable::ModelTypePayloadMapToEnumSet( | 1628 syncable::ModelTypePayloadMapToEnumSet( |
| 1631 event.snapshot->source.types); | 1629 event.snapshot->source.types); |
| 1632 sync_notifier_->SendNotification(changed_types); | 1630 sync_notifier_->SendNotification(changed_types); |
| 1633 } else { | 1631 } else { |
| 1634 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; | 1632 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; |
| 1635 } | 1633 } |
| 1636 } | 1634 } |
| 1637 } | 1635 } |
| 1638 | 1636 |
| 1639 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 1637 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2008 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2006 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 2009 } | 2007 } |
| 2010 | 2008 |
| 2011 void SyncManager::TriggerOnNotificationStateChangeForTest( | 2009 void SyncManager::TriggerOnNotificationStateChangeForTest( |
| 2012 bool notifications_enabled) { | 2010 bool notifications_enabled) { |
| 2013 DCHECK(thread_checker_.CalledOnValidThread()); | 2011 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2014 data_->OnNotificationStateChange(notifications_enabled); | 2012 data_->OnNotificationStateChange(notifications_enabled); |
| 2015 } | 2013 } |
| 2016 | 2014 |
| 2017 void SyncManager::TriggerOnIncomingNotificationForTest( | 2015 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 2018 syncable::ModelEnumSet model_types) { | 2016 ModelEnumSet model_types) { |
| 2019 DCHECK(thread_checker_.CalledOnValidThread()); | 2017 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2020 syncable::ModelTypePayloadMap model_types_with_payloads = | 2018 syncable::ModelTypePayloadMap model_types_with_payloads = |
| 2021 syncable::ModelTypePayloadMapFromEnumSet(model_types, | 2019 syncable::ModelTypePayloadMapFromEnumSet(model_types, |
| 2022 std::string()); | 2020 std::string()); |
| 2023 | 2021 |
| 2024 data_->OnIncomingNotification(model_types_with_payloads); | 2022 data_->OnIncomingNotification(model_types_with_payloads); |
| 2025 } | 2023 } |
| 2026 | 2024 |
| 2027 // Helper function that converts a PassphraseRequiredReason value to a string. | 2025 // Helper function that converts a PassphraseRequiredReason value to a string. |
| 2028 std::string PassphraseRequiredReasonToString( | 2026 std::string PassphraseRequiredReasonToString( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 lookup->GetDownloadProgress(*i, &marker); | 2076 lookup->GetDownloadProgress(*i, &marker); |
| 2079 | 2077 |
| 2080 if (marker.token().empty()) | 2078 if (marker.token().empty()) |
| 2081 result.insert(*i); | 2079 result.insert(*i); |
| 2082 | 2080 |
| 2083 } | 2081 } |
| 2084 return result; | 2082 return result; |
| 2085 } | 2083 } |
| 2086 | 2084 |
| 2087 } // namespace sync_api | 2085 } // namespace sync_api |
| OLD | NEW |