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

Side by Side Diff: components/sync/syncable/write_node.cc

Issue 2502253003: [Sync] Move GenerateSyncableHash to base. (Closed)
Patch Set: Keep full syncable/ DEP. Created 4 years, 1 month 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
OLDNEW
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 "components/sync/syncable/write_node.h" 5 #include "components/sync/syncable/write_node.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/sync/base/cryptographer.h" 12 #include "components/sync/base/cryptographer.h"
13 #include "components/sync/base/hash_util.h"
13 #include "components/sync/base/sync_features.h" 14 #include "components/sync/base/sync_features.h"
14 #include "components/sync/engine/engine_util.h" 15 #include "components/sync/engine/engine_util.h"
15 #include "components/sync/protocol/bookmark_specifics.pb.h" 16 #include "components/sync/protocol/bookmark_specifics.pb.h"
16 #include "components/sync/protocol/typed_url_specifics.pb.h" 17 #include "components/sync/protocol/typed_url_specifics.pb.h"
17 #include "components/sync/syncable/base_transaction.h" 18 #include "components/sync/syncable/base_transaction.h"
18 #include "components/sync/syncable/mutable_entry.h" 19 #include "components/sync/syncable/mutable_entry.h"
19 #include "components/sync/syncable/nigori_util.h" 20 #include "components/sync/syncable/nigori_util.h"
20 #include "components/sync/syncable/syncable_util.h"
21 #include "components/sync/syncable/write_transaction.h" 21 #include "components/sync/syncable/write_transaction.h"
22 22
23 using std::string; 23 using std::string;
24 using std::vector; 24 using std::vector;
25 25
26 namespace syncer { 26 namespace syncer {
27 27
28 using syncable::kEncryptedString; 28 using syncable::kEncryptedString;
29 using syncable::SPECIFICS; 29 using syncable::SPECIFICS;
30 30
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // Find a node by client tag, and bind this WriteNode to it. 229 // Find a node by client tag, and bind this WriteNode to it.
230 // Return true if the write node was found, and was not deleted. 230 // Return true if the write node was found, and was not deleted.
231 // Undeleting a deleted node is possible by ClientTag. 231 // Undeleting a deleted node is possible by ClientTag.
232 BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup( 232 BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup(
233 ModelType model_type, 233 ModelType model_type,
234 const std::string& tag) { 234 const std::string& tag) {
235 DCHECK(!entry_) << "Init called twice"; 235 DCHECK(!entry_) << "Init called twice";
236 if (tag.empty()) 236 if (tag.empty())
237 return INIT_FAILED_PRECONDITION; 237 return INIT_FAILED_PRECONDITION;
238 238
239 const std::string hash = syncable::GenerateSyncableHash(model_type, tag); 239 const std::string hash = GenerateSyncableHash(model_type, tag);
240 240
241 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), 241 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
242 syncable::GET_BY_CLIENT_TAG, hash); 242 syncable::GET_BY_CLIENT_TAG, hash);
243 if (!entry_->good()) 243 if (!entry_->good())
244 return INIT_FAILED_ENTRY_NOT_GOOD; 244 return INIT_FAILED_ENTRY_NOT_GOOD;
245 if (entry_->GetIsDel()) 245 if (entry_->GetIsDel())
246 return INIT_FAILED_ENTRY_IS_DEL; 246 return INIT_FAILED_ENTRY_IS_DEL;
247 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; 247 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
248 } 248 }
249 249
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 ModelType model_type, 320 ModelType model_type,
321 const syncable::Id& parent_id, 321 const syncable::Id& parent_id,
322 const std::string& tag) { 322 const std::string& tag) {
323 // This DCHECK will only fail if init is called twice. 323 // This DCHECK will only fail if init is called twice.
324 DCHECK(!entry_); 324 DCHECK(!entry_);
325 if (tag.empty()) { 325 if (tag.empty()) {
326 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag."; 326 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag.";
327 return INIT_FAILED_EMPTY_TAG; 327 return INIT_FAILED_EMPTY_TAG;
328 } 328 }
329 329
330 const std::string hash = syncable::GenerateSyncableHash(model_type, tag); 330 const std::string hash = GenerateSyncableHash(model_type, tag);
331 331
332 // Start out with a dummy name. We expect 332 // Start out with a dummy name. We expect
333 // the caller to set a meaningful name after creation. 333 // the caller to set a meaningful name after creation.
334 string dummy(kDefaultNameForNewNodes); 334 string dummy(kDefaultNameForNewNodes);
335 335
336 // Check if we have this locally and need to undelete it. 336 // Check if we have this locally and need to undelete it.
337 std::unique_ptr<syncable::MutableEntry> existing_entry( 337 std::unique_ptr<syncable::MutableEntry> existing_entry(
338 new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), 338 new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
339 syncable::GET_BY_CLIENT_TAG, hash)); 339 syncable::GET_BY_CLIENT_TAG, hash));
340 340
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 syncable::Id predecessor_id = 478 syncable::Id predecessor_id =
479 predecessor ? predecessor->GetSyncId() : syncable::Id(); 479 predecessor ? predecessor->GetSyncId() : syncable::Id();
480 return entry_->PutPredecessor(predecessor_id); 480 return entry_->PutPredecessor(predecessor_id);
481 } 481 }
482 482
483 void WriteNode::MarkForSyncing() { 483 void WriteNode::MarkForSyncing() {
484 syncable::MarkForSyncing(entry_); 484 syncable::MarkForSyncing(entry_);
485 } 485 }
486 486
487 } // namespace syncer 487 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/syncable_util_unittest.cc ('k') | components/sync/test/fake_server/bookmark_entity_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698