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

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

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years 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
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 20 matching lines...) Expand all
31 namespace sync_api { 31 namespace sync_api {
32 32
33 static const char kDefaultNameForNewNodes[] = " "; 33 static const char kDefaultNameForNewNodes[] = " ";
34 34
35 bool WriteNode::UpdateEntryWithEncryption( 35 bool WriteNode::UpdateEntryWithEncryption(
36 browser_sync::Cryptographer* cryptographer, 36 browser_sync::Cryptographer* cryptographer,
37 const sync_pb::EntitySpecifics& new_specifics, 37 const sync_pb::EntitySpecifics& new_specifics,
38 syncable::MutableEntry* entry) { 38 syncable::MutableEntry* entry) {
39 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); 39 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
40 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); 40 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
41 syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes(); 41 syncable::ModelEnumSet encrypted_types = cryptographer->GetEncryptedTypes();
42 sync_pb::EntitySpecifics generated_specifics; 42 sync_pb::EntitySpecifics generated_specifics;
43 if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) || 43 if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) ||
44 !cryptographer->is_initialized()) { 44 !cryptographer->is_initialized()) {
45 // No encryption required or we are unable to encrypt. 45 // No encryption required or we are unable to encrypt.
46 generated_specifics.CopyFrom(new_specifics); 46 generated_specifics.CopyFrom(new_specifics);
47 } else { 47 } else {
48 // Encrypt new_specifics into generated_specifics. 48 // Encrypt new_specifics into generated_specifics.
49 if (VLOG_IS_ON(2)) { 49 if (VLOG_IS_ON(2)) {
50 scoped_ptr<DictionaryValue> value(entry->ToValue()); 50 scoped_ptr<DictionaryValue> value(entry->ToValue());
51 std::string info; 51 std::string info;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 std::string server_legal_name; 112 std::string server_legal_name;
113 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name); 113 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name);
114 114
115 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME); 115 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
116 116
117 if (server_legal_name == old_name) 117 if (server_legal_name == old_name)
118 return; // Skip redundant changes. 118 return; // Skip redundant changes.
119 119
120 // Only set NON_UNIQUE_NAME to the title if we're not encrypted. 120 // Only set NON_UNIQUE_NAME to the title if we're not encrypted.
121 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); 121 Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
122 if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) { 122 if (cryptographer->GetEncryptedTypes().Has(GetModelType())) {
123 if (old_name != kEncryptedString) 123 if (old_name != kEncryptedString)
124 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); 124 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
125 } else { 125 } else {
126 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name); 126 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
127 } 127 }
128 128
129 // For bookmarks, we also set the title field in the specifics. 129 // For bookmarks, we also set the title field in the specifics.
130 // TODO(zea): refactor bookmarks to not need this functionality. 130 // TODO(zea): refactor bookmarks to not need this functionality.
131 if (GetModelType() == syncable::BOOKMARKS) { 131 if (GetModelType() == syncable::BOOKMARKS) {
132 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name); 132 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); 518 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
519 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); 519 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
520 SetBookmarkSpecifics(new_value); 520 SetBookmarkSpecifics(new_value);
521 } 521 }
522 522
523 void WriteNode::MarkForSyncing() { 523 void WriteNode::MarkForSyncing() {
524 syncable::MarkForSyncing(entry_); 524 syncable::MarkForSyncing(entry_);
525 } 525 }
526 526
527 } // namespace sync_api 527 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698