| 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/write_node.h" | 5 #include "chrome/browser/sync/internal_api/write_node.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/sync/engine/nigori_util.h" | 10 #include "chrome/browser/sync/engine/nigori_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 out->append(" "); | 44 out->append(" "); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool WriteNode::UpdateEntryWithEncryption( | 47 bool WriteNode::UpdateEntryWithEncryption( |
| 48 browser_sync::Cryptographer* cryptographer, | 48 browser_sync::Cryptographer* cryptographer, |
| 49 const sync_pb::EntitySpecifics& new_specifics, | 49 const sync_pb::EntitySpecifics& new_specifics, |
| 50 syncable::MutableEntry* entry) { | 50 syncable::MutableEntry* entry) { |
| 51 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); | 51 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); |
| 52 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); | 52 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); |
| 53 syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes(); | 53 syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes(); |
| 54 | |
| 55 sync_pb::EntitySpecifics generated_specifics; | 54 sync_pb::EntitySpecifics generated_specifics; |
| 56 if (type == syncable::PASSWORDS || // Has own encryption scheme. | 55 if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) || |
| 57 type == syncable::NIGORI || // Encrypted separately. | 56 !cryptographer->is_initialized()) { |
| 58 encrypted_types.count(type) == 0 || | 57 // No encryption required or we are unable to encrypt. |
| 59 new_specifics.has_encrypted()) { | |
| 60 // No encryption required. | |
| 61 generated_specifics.CopyFrom(new_specifics); | 58 generated_specifics.CopyFrom(new_specifics); |
| 62 } else { | 59 } else { |
| 63 // Encrypt new_specifics into generated_specifics. | 60 // Encrypt new_specifics into generated_specifics. |
| 64 if (VLOG_IS_ON(2)) { | 61 if (VLOG_IS_ON(2)) { |
| 65 scoped_ptr<DictionaryValue> value(entry->ToValue()); | 62 scoped_ptr<DictionaryValue> value(entry->ToValue()); |
| 66 std::string info; | 63 std::string info; |
| 67 base::JSONWriter::Write(value.get(), true, &info); | 64 base::JSONWriter::Write(value.get(), true, &info); |
| 68 VLOG(2) << "Encrypting specifics of type " | 65 VLOG(2) << "Encrypting specifics of type " |
| 69 << syncable::ModelTypeToString(type) | 66 << syncable::ModelTypeToString(type) |
| 70 << " with content: " | 67 << " with content: " |
| 71 << info; | 68 << info; |
| 72 } | 69 } |
| 73 if (!cryptographer->is_initialized()) | |
| 74 return false; | |
| 75 syncable::AddDefaultExtensionValue(type, &generated_specifics); | 70 syncable::AddDefaultExtensionValue(type, &generated_specifics); |
| 76 if (!cryptographer->Encrypt(new_specifics, | 71 if (!cryptographer->Encrypt(new_specifics, |
| 77 generated_specifics.mutable_encrypted())) { | 72 generated_specifics.mutable_encrypted())) { |
| 78 NOTREACHED() << "Could not encrypt data for node of type " | 73 NOTREACHED() << "Could not encrypt data for node of type " |
| 79 << syncable::ModelTypeToString(type); | 74 << syncable::ModelTypeToString(type); |
| 80 return false; | 75 return false; |
| 81 } | 76 } |
| 82 } | 77 } |
| 83 | 78 |
| 84 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS); | 79 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 526 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
| 532 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 527 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
| 533 SetBookmarkSpecifics(new_value); | 528 SetBookmarkSpecifics(new_value); |
| 534 } | 529 } |
| 535 | 530 |
| 536 void WriteNode::MarkForSyncing() { | 531 void WriteNode::MarkForSyncing() { |
| 537 syncable::MarkForSyncing(entry_); | 532 syncable::MarkForSyncing(entry_); |
| 538 } | 533 } |
| 539 | 534 |
| 540 } // namespace sync_api | 535 } // namespace sync_api |
| OLD | NEW |