Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/public/write_node.h" | 5 #include "sync/internal_api/public/write_node.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "sync/internal_api/public/base_transaction.h" | 10 #include "sync/internal_api/public/base_transaction.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 } else { | 70 } else { |
| 71 // Non-bookmarks and legacy bookmarks (those with no title in their | 71 // Non-bookmarks and legacy bookmarks (those with no title in their |
| 72 // specifics) store their title in NON_UNIQUE_NAME. Non-legacy bookmarks | 72 // specifics) store their title in NON_UNIQUE_NAME. Non-legacy bookmarks |
| 73 // store their title in specifics as well as NON_UNIQUE_NAME. | 73 // store their title in specifics as well as NON_UNIQUE_NAME. |
| 74 current_legal_title = entry_->GetNonUniqueName(); | 74 current_legal_title = entry_->GetNonUniqueName(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool title_matches = (current_legal_title == new_legal_title); | 77 bool title_matches = (current_legal_title == new_legal_title); |
| 78 bool encrypted_without_overwriting_name = (needs_encryption && | 78 bool encrypted_without_overwriting_name = (needs_encryption && |
| 79 entry_->GetNonUniqueName() != kEncryptedString); | 79 entry_->GetNonUniqueName() != kEncryptedString); |
| 80 bool bookmark_title_updated = false; | |
|
Nicolas Zea
2015/05/15 20:15:17
Does it make sense to, instead of having this new
pavely
2015/05/15 21:45:28
I used title_matches first, but decided to use sep
| |
| 81 | |
| 82 // For bookmarks, we also set the title field in the specifics. | |
| 83 // TODO(zea): refactor bookmarks to not need this functionality. | |
| 84 sync_pb::EntitySpecifics specifics = GetEntitySpecifics(); | |
| 85 if (GetModelType() == BOOKMARKS && | |
| 86 specifics.bookmark().title() != new_legal_title) { | |
| 87 specifics.mutable_bookmark()->set_title(new_legal_title); | |
| 88 SetEntitySpecifics(specifics); // Does it's own encryption checking. | |
| 89 bookmark_title_updated = true; | |
| 90 } | |
| 80 | 91 |
| 81 // If the title matches and the NON_UNIQUE_NAME is properly overwritten as | 92 // If the title matches and the NON_UNIQUE_NAME is properly overwritten as |
| 82 // necessary, nothing needs to change. | 93 // necessary, nothing needs to change. |
| 83 if (title_matches && !encrypted_without_overwriting_name) { | 94 if (title_matches && !encrypted_without_overwriting_name && |
| 95 !bookmark_title_updated) { | |
| 84 DVLOG(2) << "Title matches, dropping change."; | 96 DVLOG(2) << "Title matches, dropping change."; |
| 85 return; | 97 return; |
| 86 } | 98 } |
| 87 | 99 |
| 88 // For bookmarks, we also set the title field in the specifics. | |
| 89 // TODO(zea): refactor bookmarks to not need this functionality. | |
| 90 if (GetModelType() == BOOKMARKS) { | |
| 91 sync_pb::EntitySpecifics specifics = GetEntitySpecifics(); | |
| 92 specifics.mutable_bookmark()->set_title(new_legal_title); | |
| 93 SetEntitySpecifics(specifics); // Does it's own encryption checking. | |
| 94 } | |
| 95 | |
| 96 // For bookmarks, this has to happen after we set the title in the specifics, | 100 // For bookmarks, this has to happen after we set the title in the specifics, |
| 97 // because the presence of a title in the NON_UNIQUE_NAME is what controls | 101 // because the presence of a title in the NON_UNIQUE_NAME is what controls |
| 98 // the logic deciding whether this is an empty node or a legacy bookmark. | 102 // the logic deciding whether this is an empty node or a legacy bookmark. |
| 99 // See BaseNode::GetUnencryptedSpecific(..). | 103 // See BaseNode::GetUnencryptedSpecific(..). |
| 100 if (needs_encryption) | 104 if (needs_encryption) |
| 101 entry_->PutNonUniqueName(kEncryptedString); | 105 entry_->PutNonUniqueName(kEncryptedString); |
| 102 else | 106 else |
| 103 entry_->PutNonUniqueName(new_legal_title); | 107 entry_->PutNonUniqueName(new_legal_title); |
| 104 | 108 |
| 105 DVLOG(1) << "Overwriting title of type " | 109 DVLOG(1) << "Overwriting title of type " |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 syncable::Id predecessor_id = predecessor ? | 539 syncable::Id predecessor_id = predecessor ? |
| 536 predecessor->GetEntry()->GetId() : syncable::Id(); | 540 predecessor->GetEntry()->GetId() : syncable::Id(); |
| 537 return entry_->PutPredecessor(predecessor_id); | 541 return entry_->PutPredecessor(predecessor_id); |
| 538 } | 542 } |
| 539 | 543 |
| 540 void WriteNode::MarkForSyncing() { | 544 void WriteNode::MarkForSyncing() { |
| 541 syncable::MarkForSyncing(entry_); | 545 syncable::MarkForSyncing(entry_); |
| 542 } | 546 } |
| 543 | 547 |
| 544 } // namespace syncer | 548 } // namespace syncer |
| OLD | NEW |