Chromium Code Reviews| Index: chrome/browser/sync/util/cryptographer.h |
| diff --git a/chrome/browser/sync/util/cryptographer.h b/chrome/browser/sync/util/cryptographer.h |
| index ac2d4eb90732a5a12a870da1f070abddf2012fda..d732f263277936085a1a3720f036cc6478047e09 100644 |
| --- a/chrome/browser/sync/util/cryptographer.h |
| +++ b/chrome/browser/sync/util/cryptographer.h |
| @@ -12,6 +12,7 @@ |
| #include "base/gtest_prod_util.h" |
| #include "base/memory/linked_ptr.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| #include "chrome/browser/sync/syncable/model_type.h" |
| #include "chrome/browser/sync/util/nigori.h" |
| @@ -43,7 +44,25 @@ struct KeyParams { |
| // delayed until after it can be decrypted. |
| class Cryptographer { |
| public: |
| - Cryptographer(); |
| + // All Observer methods are done synchronously, so they're called |
| + // under a transaction (since all Cryptographer operations are done |
| + // under a transaction). |
| + class Observer { |
| + public: |
| + virtual void OnEncryptedTypesChanged( |
| + const syncable::ModelTypeSet& encrypted_types, |
| + bool encrypt_everything) = 0; |
| + |
| + // Send when all encrypted types have finished encryption. |
| + // Guaranteed to be called immeduately after a call of |
|
Nicolas Zea
2011/10/21 14:29:07
immediately
akalin
2011/10/22 03:28:38
Rendered moot
|
| + // OnEncryptedTypesChanged(). |
| + virtual void OnEncryptionComplete() = 0; |
| + |
| + protected: |
| + virtual ~Observer(); |
| + }; |
| + |
| + explicit Cryptographer(); |
| ~Cryptographer(); |
| // When update on cryptographer is called this enum tells if the |
| @@ -54,6 +73,10 @@ class Cryptographer { |
| NEEDS_PASSPHRASE |
| }; |
| + // Manage observers. |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| // |restored_bootstrap_token| can be provided via this method to bootstrap |
| // Cryptographer instance into the ready state (is_ready will be true). |
| // It must be a string that was previously built by the |
| @@ -156,10 +179,17 @@ class Cryptographer { |
| // Return the set of encrypted types. |
| syncable::ModelTypeSet GetEncryptedTypes() const; |
| + // Triggers an OnEncryptedTypesChanged and an OnEncryptionComplete |
| + // notifiation. |
|
Nicolas Zea
2011/10/21 14:29:07
Is it necessary to always trigger the OnEncryptedT
akalin
2011/10/22 03:28:38
Yeah, fixed. It should only trigger when it actua
|
| + void MarkEncryptionComplete(); |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack); |
| typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; |
| + // Calls OnEncryptedTypesChanged() on all observers. |
| + void EmitEncryptedTypesChangeNotification(); |
|
Nicolas Zea
2011/10/21 14:29:07
EncryptedTypesChange... -> EncryptedTypesChanged..
akalin
2011/10/22 03:28:38
Done.
|
| + |
| // Helper method to instantiate Nigori instances for each set of key |
| // parameters in |bag| and setting the default encryption key to |
| // |default_key_name|. |
| @@ -173,6 +203,8 @@ class Cryptographer { |
| bool PackBootstrapToken(const Nigori* nigori, std::string* pack_into) const; |
| Nigori* UnpackBootstrapToken(const std::string& token) const; |
| + ObserverList<Observer> observers_; |
| + |
| NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. |
| NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. |