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: sync/internal_api/write_node.cc

Issue 11571092: sync: Move unique_client_tag hashing code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo some changes and move a test to syncable_util_unittest Created 8 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
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/sync.gyp » ('j') | 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) 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/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "sync/internal_api/public/base_transaction.h" 9 #include "sync/internal_api/public/base_transaction.h"
10 #include "sync/internal_api/public/write_transaction.h" 10 #include "sync/internal_api/public/write_transaction.h"
11 #include "sync/internal_api/syncapi_internal.h" 11 #include "sync/internal_api/syncapi_internal.h"
12 #include "sync/protocol/app_specifics.pb.h" 12 #include "sync/protocol/app_specifics.pb.h"
13 #include "sync/protocol/autofill_specifics.pb.h" 13 #include "sync/protocol/autofill_specifics.pb.h"
14 #include "sync/protocol/bookmark_specifics.pb.h" 14 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/protocol/extension_specifics.pb.h" 15 #include "sync/protocol/extension_specifics.pb.h"
16 #include "sync/protocol/password_specifics.pb.h" 16 #include "sync/protocol/password_specifics.pb.h"
17 #include "sync/protocol/session_specifics.pb.h" 17 #include "sync/protocol/session_specifics.pb.h"
18 #include "sync/protocol/theme_specifics.pb.h" 18 #include "sync/protocol/theme_specifics.pb.h"
19 #include "sync/protocol/typed_url_specifics.pb.h" 19 #include "sync/protocol/typed_url_specifics.pb.h"
20 #include "sync/syncable/mutable_entry.h" 20 #include "sync/syncable/mutable_entry.h"
21 #include "sync/syncable/nigori_util.h" 21 #include "sync/syncable/nigori_util.h"
22 #include "sync/syncable/syncable_util.h"
22 #include "sync/util/cryptographer.h" 23 #include "sync/util/cryptographer.h"
23 24
24 using std::string; 25 using std::string;
25 using std::vector; 26 using std::vector;
26 27
27 namespace syncer { 28 namespace syncer {
28 29
29 using syncable::kEncryptedString; 30 using syncable::kEncryptedString;
30 using syncable::SPECIFICS; 31 using syncable::SPECIFICS;
31 32
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Find a node by client tag, and bind this WriteNode to it. 286 // Find a node by client tag, and bind this WriteNode to it.
286 // Return true if the write node was found, and was not deleted. 287 // Return true if the write node was found, and was not deleted.
287 // Undeleting a deleted node is possible by ClientTag. 288 // Undeleting a deleted node is possible by ClientTag.
288 BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup( 289 BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup(
289 ModelType model_type, 290 ModelType model_type,
290 const std::string& tag) { 291 const std::string& tag) {
291 DCHECK(!entry_) << "Init called twice"; 292 DCHECK(!entry_) << "Init called twice";
292 if (tag.empty()) 293 if (tag.empty())
293 return INIT_FAILED_PRECONDITION; 294 return INIT_FAILED_PRECONDITION;
294 295
295 const std::string hash = GenerateSyncableHash(model_type, tag); 296 const std::string hash = syncable::GenerateSyncableHash(model_type, tag);
296 297
297 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), 298 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
298 syncable::GET_BY_CLIENT_TAG, hash); 299 syncable::GET_BY_CLIENT_TAG, hash);
299 if (!entry_->good()) 300 if (!entry_->good())
300 return INIT_FAILED_ENTRY_NOT_GOOD; 301 return INIT_FAILED_ENTRY_NOT_GOOD;
301 if (entry_->Get(syncable::IS_DEL)) 302 if (entry_->Get(syncable::IS_DEL))
302 return INIT_FAILED_ENTRY_IS_DEL; 303 return INIT_FAILED_ENTRY_IS_DEL;
303 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; 304 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
304 } 305 }
305 306
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 ModelType model_type, 374 ModelType model_type,
374 const BaseNode& parent, 375 const BaseNode& parent,
375 const std::string& tag) { 376 const std::string& tag) {
376 // This DCHECK will only fail if init is called twice. 377 // This DCHECK will only fail if init is called twice.
377 DCHECK(!entry_); 378 DCHECK(!entry_);
378 if (tag.empty()) { 379 if (tag.empty()) {
379 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag."; 380 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag.";
380 return INIT_FAILED_EMPTY_TAG; 381 return INIT_FAILED_EMPTY_TAG;
381 } 382 }
382 383
383 const std::string hash = GenerateSyncableHash(model_type, tag); 384 const std::string hash = syncable::GenerateSyncableHash(model_type, tag);
384 385
385 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID); 386 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
386 387
387 // Start out with a dummy name. We expect 388 // Start out with a dummy name. We expect
388 // the caller to set a meaningful name after creation. 389 // the caller to set a meaningful name after creation.
389 string dummy(kDefaultNameForNewNodes); 390 string dummy(kDefaultNameForNewNodes);
390 391
391 // Check if we have this locally and need to undelete it. 392 // Check if we have this locally and need to undelete it.
392 scoped_ptr<syncable::MutableEntry> existing_entry( 393 scoped_ptr<syncable::MutableEntry> existing_entry(
393 new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), 394 new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 MarkForSyncing(); 506 MarkForSyncing();
506 507
507 return true; 508 return true;
508 } 509 }
509 510
510 void WriteNode::MarkForSyncing() { 511 void WriteNode::MarkForSyncing() {
511 syncable::MarkForSyncing(entry_); 512 syncable::MarkForSyncing(entry_);
512 } 513 }
513 514
514 } // namespace syncer 515 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698