OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "sync/internal_api/sync_encryption_handler_impl.h" | 5 #include "sync/internal_api/sync_encryption_handler_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/json/json_string_value_serializer.h" | 16 #include "base/json/json_string_value_serializer.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/location.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" |
19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
20 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" |
21 #include "sync/internal_api/public/read_node.h" | 23 #include "sync/internal_api/public/read_node.h" |
22 #include "sync/internal_api/public/read_transaction.h" | 24 #include "sync/internal_api/public/read_transaction.h" |
23 #include "sync/internal_api/public/user_share.h" | 25 #include "sync/internal_api/public/user_share.h" |
24 #include "sync/internal_api/public/util/experiments.h" | 26 #include "sync/internal_api/public/util/experiments.h" |
25 #include "sync/internal_api/public/util/sync_string_conversions.h" | 27 #include "sync/internal_api/public/util/sync_string_conversions.h" |
26 #include "sync/internal_api/public/write_node.h" | 28 #include "sync/internal_api/public/write_node.h" |
27 #include "sync/internal_api/public/write_transaction.h" | 29 #include "sync/internal_api/public/write_transaction.h" |
28 #include "sync/protocol/encryption.pb.h" | 30 #include "sync/protocol/encryption.pb.h" |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 } | 651 } |
650 | 652 |
651 // Note: this is called from within a syncable transaction, so we need to post | 653 // Note: this is called from within a syncable transaction, so we need to post |
652 // tasks if we want to do any work that creates a new sync_api transaction. | 654 // tasks if we want to do any work that creates a new sync_api transaction. |
653 void SyncEncryptionHandlerImpl::ApplyNigoriUpdate( | 655 void SyncEncryptionHandlerImpl::ApplyNigoriUpdate( |
654 const sync_pb::NigoriSpecifics& nigori, | 656 const sync_pb::NigoriSpecifics& nigori, |
655 syncable::BaseTransaction* const trans) { | 657 syncable::BaseTransaction* const trans) { |
656 DCHECK(thread_checker_.CalledOnValidThread()); | 658 DCHECK(thread_checker_.CalledOnValidThread()); |
657 DCHECK(trans); | 659 DCHECK(trans); |
658 if (!ApplyNigoriUpdateImpl(nigori, trans)) { | 660 if (!ApplyNigoriUpdateImpl(nigori, trans)) { |
659 base::MessageLoop::current()->PostTask( | 661 base::ThreadTaskRunnerHandle::Get()->PostTask( |
660 FROM_HERE, | 662 FROM_HERE, base::Bind(&SyncEncryptionHandlerImpl::RewriteNigori, |
661 base::Bind(&SyncEncryptionHandlerImpl::RewriteNigori, | 663 weak_ptr_factory_.GetWeakPtr())); |
662 weak_ptr_factory_.GetWeakPtr())); | |
663 } | 664 } |
664 | 665 |
665 FOR_EACH_OBSERVER( | 666 FOR_EACH_OBSERVER( |
666 SyncEncryptionHandler::Observer, | 667 SyncEncryptionHandler::Observer, |
667 observers_, | 668 observers_, |
668 OnCryptographerStateChanged( | 669 OnCryptographerStateChanged( |
669 &UnlockVaultMutable(trans)->cryptographer)); | 670 &UnlockVaultMutable(trans)->cryptographer)); |
670 } | 671 } |
671 | 672 |
672 void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes( | 673 void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // be able to decrypt them using either the keystore decryptor token | 738 // be able to decrypt them using either the keystore decryptor token |
738 // or the existing keystore keys. | 739 // or the existing keystore keys. |
739 DecryptPendingKeysWithKeystoreKey(keystore_key_, | 740 DecryptPendingKeysWithKeystoreKey(keystore_key_, |
740 nigori.keystore_decryptor_token(), | 741 nigori.keystore_decryptor_token(), |
741 cryptographer); | 742 cryptographer); |
742 } | 743 } |
743 | 744 |
744 // Note that triggering migration will have no effect if we're already | 745 // Note that triggering migration will have no effect if we're already |
745 // properly migrated with the newest keystore keys. | 746 // properly migrated with the newest keystore keys. |
746 if (ShouldTriggerMigration(nigori, *cryptographer)) { | 747 if (ShouldTriggerMigration(nigori, *cryptographer)) { |
747 base::MessageLoop::current()->PostTask( | 748 base::ThreadTaskRunnerHandle::Get()->PostTask( |
748 FROM_HERE, | 749 FROM_HERE, base::Bind(&SyncEncryptionHandlerImpl::RewriteNigori, |
749 base::Bind(&SyncEncryptionHandlerImpl::RewriteNigori, | 750 weak_ptr_factory_.GetWeakPtr())); |
750 weak_ptr_factory_.GetWeakPtr())); | |
751 } | 751 } |
752 | 752 |
753 return true; | 753 return true; |
754 } | 754 } |
755 | 755 |
756 ModelTypeSet SyncEncryptionHandlerImpl::GetEncryptedTypes( | 756 ModelTypeSet SyncEncryptionHandlerImpl::GetEncryptedTypes( |
757 syncable::BaseTransaction* const trans) const { | 757 syncable::BaseTransaction* const trans) const { |
758 return UnlockVault(trans).encrypted_types; | 758 return UnlockVault(trans).encrypted_types; |
759 } | 759 } |
760 | 760 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 | 1693 |
1694 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { | 1694 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { |
1695 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) | 1695 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) |
1696 return migration_time(); | 1696 return migration_time(); |
1697 else if (passphrase_type_ == CUSTOM_PASSPHRASE) | 1697 else if (passphrase_type_ == CUSTOM_PASSPHRASE) |
1698 return custom_passphrase_time(); | 1698 return custom_passphrase_time(); |
1699 return base::Time(); | 1699 return base::Time(); |
1700 } | 1700 } |
1701 | 1701 |
1702 } // namespace syncer | 1702 } // namespace syncer |
OLD | NEW |