Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/sync/internal_api/write_node.cc

Issue 7878005: [Sync] Fix encrypting of sync titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and add comment Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 syncable::AddDefaultExtensionValue(type, &generated_specifics); 70 syncable::AddDefaultExtensionValue(type, &generated_specifics);
71 if (!cryptographer->Encrypt(new_specifics, 71 if (!cryptographer->Encrypt(new_specifics,
72 generated_specifics.mutable_encrypted())) { 72 generated_specifics.mutable_encrypted())) {
73 NOTREACHED() << "Could not encrypt data for node of type " 73 NOTREACHED() << "Could not encrypt data for node of type "
74 << syncable::ModelTypeToString(type); 74 << syncable::ModelTypeToString(type);
75 return false; 75 return false;
76 } 76 }
77 } 77 }
78 78
79 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS); 79 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
80 if (AreSpecificsEqual(cryptographer, old_specifics, generated_specifics)) { 80 if (AreSpecificsEqual(cryptographer, old_specifics, generated_specifics) &&
81 (entry->Get(syncable::NON_UNIQUE_NAME) == kEncryptedString ||
82 !generated_specifics.has_encrypted())) {
81 // Even if the data is the same but the old specifics are encrypted with an 83 // Even if the data is the same but the old specifics are encrypted with an
82 // old key, we should go ahead and re-encrypt with the new key. 84 // old key, we should go ahead and re-encrypt with the new key.
83 if ((!old_specifics.has_encrypted() && 85 if ((!old_specifics.has_encrypted() &&
84 !generated_specifics.has_encrypted()) || 86 !generated_specifics.has_encrypted()) ||
85 cryptographer->CanDecryptUsingDefaultKey(old_specifics.encrypted())) { 87 cryptographer->CanDecryptUsingDefaultKey(old_specifics.encrypted())) {
86 VLOG(2) << "Specifics of type " << syncable::ModelTypeToString(type) 88 VLOG(2) << "Specifics of type " << syncable::ModelTypeToString(type)
87 << " already match, dropping change."; 89 << " already match, dropping change.";
88 return true; 90 return true;
89 } 91 }
90 // TODO(zea): Add some way to keep track of how often we're reencrypting 92 // TODO(zea): Add some way to keep track of how often we're reencrypting
(...skipping 30 matching lines...) Expand all
121 sync_pb::EntitySpecifics specifics = GetEntitySpecifics(); 123 sync_pb::EntitySpecifics specifics = GetEntitySpecifics();
122 std::string server_legal_name; 124 std::string server_legal_name;
123 SyncAPINameToServerName(title, &server_legal_name); 125 SyncAPINameToServerName(title, &server_legal_name);
124 126
125 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME); 127 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
126 128
127 if (server_legal_name == old_name) 129 if (server_legal_name == old_name)
128 return; // Skip redundant changes. 130 return; // Skip redundant changes.
129 131
130 // Only set NON_UNIQUE_NAME to the title if we're not encrypted. 132 // Only set NON_UNIQUE_NAME to the title if we're not encrypted.
131 if (specifics.has_encrypted()) { 133 Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
134 if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) {
132 if (old_name != kEncryptedString) 135 if (old_name != kEncryptedString)
133 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); 136 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
134 } else { 137 } else {
135 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name); 138 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
136 } 139 }
137 140
138 // For bookmarks, we also set the title field in the specifics. 141 // For bookmarks, we also set the title field in the specifics.
139 // TODO(zea): refactor bookmarks to not need this functionality. 142 // TODO(zea): refactor bookmarks to not need this functionality.
140 if (GetModelType() == syncable::BOOKMARKS) { 143 if (GetModelType() == syncable::BOOKMARKS) {
141 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name); 144 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name);
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); 529 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
527 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); 530 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
528 SetBookmarkSpecifics(new_value); 531 SetBookmarkSpecifics(new_value);
529 } 532 }
530 533
531 void WriteNode::MarkForSyncing() { 534 void WriteNode::MarkForSyncing() {
532 syncable::MarkForSyncing(entry_); 535 syncable::MarkForSyncing(entry_);
533 } 536 }
534 537
535 } // namespace sync_api 538 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698