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

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 pass #2 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 const syncable::ModelEnumSet encrypted_types =
42 cryptographer->GetEncryptedTypes();
42 sync_pb::EntitySpecifics generated_specifics; 43 sync_pb::EntitySpecifics generated_specifics;
43 if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) || 44 if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) ||
44 !cryptographer->is_initialized()) { 45 !cryptographer->is_initialized()) {
45 // No encryption required or we are unable to encrypt. 46 // No encryption required or we are unable to encrypt.
46 generated_specifics.CopyFrom(new_specifics); 47 generated_specifics.CopyFrom(new_specifics);
47 } else { 48 } else {
48 // Encrypt new_specifics into generated_specifics. 49 // Encrypt new_specifics into generated_specifics.
49 if (VLOG_IS_ON(2)) { 50 if (VLOG_IS_ON(2)) {
50 scoped_ptr<DictionaryValue> value(entry->ToValue()); 51 scoped_ptr<DictionaryValue> value(entry->ToValue());
51 std::string info; 52 std::string info;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 std::string server_legal_name; 113 std::string server_legal_name;
113 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name); 114 SyncAPINameToServerName(WideToUTF8(title), &server_legal_name);
114 115
115 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME); 116 string old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
116 117
117 if (server_legal_name == old_name) 118 if (server_legal_name == old_name)
118 return; // Skip redundant changes. 119 return; // Skip redundant changes.
119 120
120 // Only set NON_UNIQUE_NAME to the title if we're not encrypted. 121 // Only set NON_UNIQUE_NAME to the title if we're not encrypted.
121 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); 122 Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
122 if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) { 123 if (cryptographer->GetEncryptedTypes().Has(GetModelType())) {
123 if (old_name != kEncryptedString) 124 if (old_name != kEncryptedString)
124 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); 125 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
125 } else { 126 } else {
126 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name); 127 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
127 } 128 }
128 129
129 // For bookmarks, we also set the title field in the specifics. 130 // For bookmarks, we also set the title field in the specifics.
130 // TODO(zea): refactor bookmarks to not need this functionality. 131 // TODO(zea): refactor bookmarks to not need this functionality.
131 if (GetModelType() == syncable::BOOKMARKS) { 132 if (GetModelType() == syncable::BOOKMARKS) {
132 specifics.MutableExtension(sync_pb::bookmark)->set_title(server_legal_name); 133 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(); 519 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
519 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); 520 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
520 SetBookmarkSpecifics(new_value); 521 SetBookmarkSpecifics(new_value);
521 } 522 }
522 523
523 void WriteNode::MarkForSyncing() { 524 void WriteNode::MarkForSyncing() {
524 syncable::MarkForSyncing(entry_); 525 syncable::MarkForSyncing(entry_);
525 } 526 }
526 527
527 } // namespace sync_api 528 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | chrome/browser/sync/js/js_sync_manager_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698