Index: sync/engine/download_updates_command.cc |
diff --git a/sync/engine/download_updates_command.cc b/sync/engine/download_updates_command.cc |
index 22839f60d0ba3798e8e7bf695d0b71e15c4b6440..8a3078541a9aedaba7914fc099121382d17f2503 100644 |
--- a/sync/engine/download_updates_command.cc |
+++ b/sync/engine/download_updates_command.cc |
@@ -11,6 +11,7 @@ |
#include "sync/engine/syncer_proto_util.h" |
#include "sync/internal_api/public/base/model_type_payload_map.h" |
#include "sync/syncable/directory.h" |
+#include "sync/syncable/read_transaction.h" |
using sync_pb::DebugInfo; |
@@ -62,6 +63,17 @@ SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { |
} |
} |
+ bool need_encryption_key = false; |
+ if (session->context()->keystore_encryption_enabled()) { |
+ syncable::Directory* dir = session->context()->directory(); |
+ syncable::ReadTransaction trans(FROM_HERE, dir); |
+ Cryptographer* cryptographer = |
+ session->context()->directory()->GetCryptographer(&trans); |
+ need_encryption_key = !cryptographer->HasKeystoreKey(); |
+ get_updates->set_need_encryption_key(need_encryption_key); |
+ |
+ } |
+ |
// We want folders for our associated types, always. If we were to set |
// this to false, the server would send just the non-container items |
// (e.g. Bookmark URLs but not their containing folders). |
@@ -103,6 +115,28 @@ SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { |
<< " updates and indicated " |
<< update_response.get_updates().changes_remaining() |
<< " updates left on server."; |
+ |
+ if (need_encryption_key) { |
tim (not reviewing)
2012/07/26 21:53:15
Can you put this into a helper method for sake of
Nicolas Zea
2012/07/27 00:43:15
Done.
|
+ bool success = false; |
+ if (update_response.get_updates().has_encryption_key()) { |
+ syncable::Directory* dir = session->context()->directory(); |
+ syncable::ReadTransaction trans(FROM_HERE, dir); |
+ Cryptographer* cryptographer = |
+ session->context()->directory()->GetCryptographer(&trans); |
+ success = cryptographer->SetKeystoreKey( |
+ update_response.get_updates().encryption_key()); |
+ |
+ DVLOG(1) << "GetUpdates returned encryption key of length " |
+ << update_response.get_updates().encryption_key().length() |
+ << ". Cryptographer keystore key " |
+ << (success ? "" : "not ") << "updated."; |
+ } else { |
+ LOG(ERROR) << "Failed to receive encryption key from server."; |
+ } |
+ status->set_last_get_key_result( |
+ success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED); |
+ } |
+ |
return result; |
} |