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 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 if (!child.InitByIdLookup(child_id)) { | 1209 if (!child.InitByIdLookup(child_id)) { |
1210 NOTREACHED(); | 1210 NOTREACHED(); |
1211 return; | 1211 return; |
1212 } | 1212 } |
1213 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | 1213 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
1214 child_id = child.GetSuccessorId(); | 1214 child_id = child.GetSuccessorId(); |
1215 } | 1215 } |
1216 } | 1216 } |
1217 } | 1217 } |
1218 | 1218 |
1219 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1219 FOR_EACH_OBSERVER( |
1220 OnEncryptionComplete(encrypted_types)); | 1220 SyncManager::Observer, observers_, |
1221 OnEncryptionComplete( | |
1222 encrypted_types, cryptographer->encrypt_everything())); | |
1221 } | 1223 } |
1222 | 1224 |
1223 SyncManager::~SyncManager() { | 1225 SyncManager::~SyncManager() { |
1224 DCHECK(thread_checker_.CalledOnValidThread()); | 1226 DCHECK(thread_checker_.CalledOnValidThread()); |
1225 delete data_; | 1227 delete data_; |
1226 } | 1228 } |
1227 | 1229 |
1228 void SyncManager::AddChangeObserver(ChangeObserver* observer) { | 1230 void SyncManager::AddChangeObserver(ChangeObserver* observer) { |
1229 DCHECK(thread_checker_.CalledOnValidThread()); | 1231 DCHECK(thread_checker_.CalledOnValidThread()); |
1230 data_->AddChangeObserver(observer); | 1232 data_->AddChangeObserver(observer); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1593 // Only send an event if this is due to a cycle ending and this cycle | 1595 // Only send an event if this is due to a cycle ending and this cycle |
1594 // concludes a canonical "sync" process; that is, based on what is known | 1596 // concludes a canonical "sync" process; that is, based on what is known |
1595 // locally we are "all happy" and up-to-date. There may be new changes on | 1597 // locally we are "all happy" and up-to-date. There may be new changes on |
1596 // the server, but we'll get them on a subsequent sync. | 1598 // the server, but we'll get them on a subsequent sync. |
1597 // | 1599 // |
1598 // Notifications are sent at the end of every sync cycle, regardless of | 1600 // Notifications are sent at the end of every sync cycle, regardless of |
1599 // whether we should sync again. | 1601 // whether we should sync again. |
1600 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 1602 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
1601 ModelSafeRoutingInfo enabled_types; | 1603 ModelSafeRoutingInfo enabled_types; |
1602 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 1604 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
1605 bool send_encryption_complete_notification = false; | |
1606 syncable::ModelTypeSet encrypted_types( | |
1607 browser_sync::Cryptographer::SensitiveTypes()); | |
1608 bool encrypt_everything = false; | |
1603 { | 1609 { |
1604 // Check to see if we need to notify the frontend that we have newly | 1610 // Check to see if we need to notify the frontend that we have newly |
1605 // encrypted types or that we require a passphrase. | 1611 // encrypted types or that we require a passphrase. |
1606 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); | 1612 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); |
1607 Cryptographer* cryptographer = trans.GetCryptographer(); | 1613 Cryptographer* cryptographer = trans.GetCryptographer(); |
1608 // If we've completed a sync cycle and the cryptographer isn't ready | 1614 // If we've completed a sync cycle and the cryptographer isn't ready |
1609 // yet, prompt the user for a passphrase. | 1615 // yet, prompt the user for a passphrase. |
1610 if (cryptographer->has_pending_keys()) { | 1616 if (cryptographer->has_pending_keys()) { |
1611 VLOG(1) << "OnPassPhraseRequired Sent"; | 1617 VLOG(1) << "OnPassPhraseRequired Sent"; |
1612 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1618 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1613 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 1619 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
1614 } else if (!cryptographer->is_ready() && | 1620 } else if (!cryptographer->is_ready() && |
1615 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { | 1621 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { |
1616 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 1622 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
1617 << "ready"; | 1623 << "ready"; |
1618 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1624 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1619 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); | 1625 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); |
1626 } else { | |
1627 send_encryption_complete_notification = true; | |
1620 } | 1628 } |
1621 | 1629 |
1630 encrypted_types = cryptographer->GetEncryptedTypes(); | |
1631 encrypt_everything = cryptographer->encrypt_everything(); | |
1622 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1632 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
1623 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1633 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
1624 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1634 allstatus_.SetEncryptedTypes(encrypted_types); |
1625 | 1635 |
1626 // If everything is in order(we have the passphrase) then there is no | 1636 // If everything is in order (we have the passphrase) then we |
1627 // need to inform the listeners. They will just wait for sync | 1637 // inform the listeners below right after we close the |
1628 // completion event and if no errors have been raised it means | 1638 // transaction. |
1629 // encryption was succesful. | 1639 } |
1640 | |
1641 if (send_encryption_complete_notification) { | |
1642 VLOG(1) << "Sending OnEncryptionComplete"; | |
Nicolas Zea
2011/10/20 18:40:41
Should probably be VLOG(2), since this is going to
akalin
2011/10/21 02:24:17
Removed. Probably not necessary.
| |
1643 // TODO(akalin): Ideally, the Cryptographer would be the one | |
1644 // sending out this notification, as it knows exactly when it | |
1645 // does encryption (whereas we always send this at the end of a | |
1646 // sync cycle, regardless of whether encryption was actually | |
1647 // done). | |
1648 FOR_EACH_OBSERVER( | |
1649 SyncManager::Observer, observers_, | |
1650 OnEncryptionComplete(encrypted_types, encrypt_everything)); | |
1630 } | 1651 } |
1631 | 1652 |
1632 if (!initialized_) { | 1653 if (!initialized_) { |
1633 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 1654 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
1634 << "initialized"; | 1655 << "initialized"; |
1635 return; | 1656 return; |
1636 } | 1657 } |
1637 | 1658 |
1638 if (!event.snapshot->has_more_to_sync) { | 1659 if (!event.snapshot->has_more_to_sync) { |
1639 VLOG(1) << "OnSyncCycleCompleted sent"; | 1660 VLOG(1) << "Sending OnSyncCycleCompleted"; |
1640 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1661 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1641 OnSyncCycleCompleted(event.snapshot)); | 1662 OnSyncCycleCompleted(event.snapshot)); |
1642 } | 1663 } |
1643 | 1664 |
1644 // This is here for tests, which are still using p2p notifications. | 1665 // This is here for tests, which are still using p2p notifications. |
1645 // | 1666 // |
1646 // TODO(chron): Consider changing this back to track has_more_to_sync | 1667 // TODO(chron): Consider changing this back to track has_more_to_sync |
1647 // only notify peers if a successful commit has occurred. | 1668 // only notify peers if a successful commit has occurred. |
1648 bool is_notifiable_commit = | 1669 bool is_notifiable_commit = |
1649 (event.snapshot->syncer_status.num_successful_commits > 0); | 1670 (event.snapshot->syncer_status.num_successful_commits > 0); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2078 | 2099 |
2079 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2100 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
2080 i != types.end(); ++i) { | 2101 i != types.end(); ++i) { |
2081 if (!lookup->initial_sync_ended_for_type(*i)) | 2102 if (!lookup->initial_sync_ended_for_type(*i)) |
2082 return false; | 2103 return false; |
2083 } | 2104 } |
2084 return true; | 2105 return true; |
2085 } | 2106 } |
2086 | 2107 |
2087 } // namespace sync_api | 2108 } // namespace sync_api |
OLD | NEW |