| 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/encryption/nigori_util.h" |
| 11 #include "chrome/browser/sync/engine/syncapi_internal.h" | 11 #include "chrome/browser/sync/engine/syncapi_internal.h" |
| 12 #include "chrome/browser/sync/internal_api/base_transaction.h" | 12 #include "chrome/browser/sync/internal_api/base_transaction.h" |
| 13 #include "chrome/browser/sync/internal_api/write_transaction.h" | 13 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 14 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 15 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 18 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 19 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
| 20 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
| 21 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
| 22 #include "chrome/browser/sync/syncable/syncable.h" | 22 #include "chrome/browser/sync/syncable/syncable.h" |
| 23 #include "chrome/browser/sync/util/cryptographer.h" | 23 #include "chrome/browser/sync/encryption/cryptographer.h" |
| 24 | 24 |
| 25 using browser_sync::Cryptographer; | 25 using browser_sync::Cryptographer; |
| 26 using browser_sync::encryption::kEncryptedString; |
| 27 using browser_sync::encryption::SpecificsNeedsEncryption; |
| 26 using std::string; | 28 using std::string; |
| 27 using std::vector; | 29 using std::vector; |
| 28 using syncable::kEncryptedString; | |
| 29 using syncable::SPECIFICS; | 30 using syncable::SPECIFICS; |
| 30 | 31 |
| 32 |
| 31 namespace sync_api { | 33 namespace sync_api { |
| 32 | 34 |
| 33 static const char kDefaultNameForNewNodes[] = " "; | 35 static const char kDefaultNameForNewNodes[] = " "; |
| 34 | 36 |
| 35 bool WriteNode::UpdateEntryWithEncryption( | 37 bool WriteNode::UpdateEntryWithEncryption( |
| 36 browser_sync::Cryptographer* cryptographer, | 38 browser_sync::Cryptographer* cryptographer, |
| 37 const sync_pb::EntitySpecifics& new_specifics, | 39 const sync_pb::EntitySpecifics& new_specifics, |
| 38 syncable::MutableEntry* entry) { | 40 syncable::MutableEntry* entry) { |
| 39 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); | 41 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); |
| 40 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); | 42 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name); | 115 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name); |
| 114 | 116 |
| 115 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME); | 117 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME); |
| 116 | 118 |
| 117 if (server_legal_name == old_name) | 119 if (server_legal_name == old_name) |
| 118 return; // Skip redundant changes. | 120 return; // Skip redundant changes. |
| 119 | 121 |
| 120 // Only set NON_UNIQUE_NAME to the title if we're not encrypted. | 122 // Only set NON_UNIQUE_NAME to the title if we're not encrypted. |
| 121 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); | 123 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); |
| 122 if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) { | 124 if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) { |
| 123 if (old_name != kEncryptedString) | 125 if (old_name != browser_sync::encryption::kEncryptedString) |
| 124 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); | 126 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); |
| 125 } else { | 127 } else { |
| 126 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name); | 128 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name); |
| 127 } | 129 } |
| 128 | 130 |
| 129 // For bookmarks, we also set the title field in the specifics. | 131 // For bookmarks, we also set the title field in the specifics. |
| 130 // TODO(zea): refactor bookmarks to not need this functionality. | 132 // TODO(zea): refactor bookmarks to not need this functionality. |
| 131 if (GetModelType() == syncable::BOOKMARKS) { | 133 if (GetModelType() == syncable::BOOKMARKS) { |
| 132 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name); | 134 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name); |
| 133 SetEntitySpecifics(specifics); // Does it's own encryption checking. | 135 SetEntitySpecifics(specifics); // Does it's own encryption checking. |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 520 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
| 519 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 521 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
| 520 SetBookmarkSpecifics(new_value); | 522 SetBookmarkSpecifics(new_value); |
| 521 } | 523 } |
| 522 | 524 |
| 523 void WriteNode::MarkForSyncing() { | 525 void WriteNode::MarkForSyncing() { |
| 524 syncable::MarkForSyncing(entry_); | 526 syncable::MarkForSyncing(entry_); |
| 525 } | 527 } |
| 526 | 528 |
| 527 } // namespace sync_api | 529 } // namespace sync_api |
| OLD | NEW |