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

Side by Side Diff: components/sync/engine_impl/get_commit_ids.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/engine/get_commit_ids.h" 5 #include "components/sync/engine_impl/get_commit_ids.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "sync/engine/syncer_util.h" 14 #include "components/sync/base/cryptographer.h"
15 #include "sync/syncable/directory.h" 15 #include "components/sync/engine_impl/syncer_util.h"
16 #include "sync/syncable/entry.h" 16 #include "components/sync/syncable/directory.h"
17 #include "sync/syncable/nigori_handler.h" 17 #include "components/sync/syncable/entry.h"
18 #include "sync/syncable/nigori_util.h" 18 #include "components/sync/syncable/nigori_handler.h"
19 #include "sync/syncable/syncable_base_transaction.h" 19 #include "components/sync/syncable/nigori_util.h"
20 #include "sync/syncable/syncable_util.h" 20 #include "components/sync/syncable/syncable_base_transaction.h"
21 #include "sync/util/cryptographer.h" 21 #include "components/sync/syncable/syncable_util.h"
22 22
23 using std::set; 23 using std::set;
24 using std::vector; 24 using std::vector;
25 25
26 namespace syncer { 26 namespace syncer {
27 27
28 namespace { 28 namespace {
29 29
30 // Forward-declare some helper functions. This gives us more options for 30 // Forward-declare some helper functions. This gives us more options for
31 // ordering the function defintions within this file. 31 // ordering the function defintions within this file.
(...skipping 13 matching lines...) Expand all
45 // |max_entries| of them in the output parameter |out|. 45 // |max_entries| of them in the output parameter |out|.
46 // 46 //
47 // See the header file for an explanation of commit ordering. 47 // See the header file for an explanation of commit ordering.
48 void OrderCommitIds(syncable::BaseTransaction* trans, 48 void OrderCommitIds(syncable::BaseTransaction* trans,
49 size_t max_entries, 49 size_t max_entries,
50 const std::set<int64_t>& ready_unsynced_set, 50 const std::set<int64_t>& ready_unsynced_set,
51 std::vector<int64_t>* out); 51 std::vector<int64_t>* out);
52 52
53 } // namespace 53 } // namespace
54 54
55 void GetCommitIdsForType( 55 void GetCommitIdsForType(syncable::BaseTransaction* trans,
56 syncable::BaseTransaction* trans, 56 ModelType type,
57 ModelType type, 57 size_t max_entries,
58 size_t max_entries, 58 syncable::Directory::Metahandles* out) {
59 syncable::Directory::Metahandles* out) {
60 syncable::Directory* dir = trans->directory(); 59 syncable::Directory* dir = trans->directory();
61 60
62 // Gather the full set of unsynced items and store it in the session. They 61 // Gather the full set of unsynced items and store it in the session. They
63 // are not in the correct order for commit. 62 // are not in the correct order for commit.
64 std::set<int64_t> ready_unsynced_set; 63 std::set<int64_t> ready_unsynced_set;
65 syncable::Directory::Metahandles all_unsynced_handles; 64 syncable::Directory::Metahandles all_unsynced_handles;
66 GetUnsyncedEntries(trans, &all_unsynced_handles); 65 GetUnsyncedEntries(trans, &all_unsynced_handles);
67 66
68 ModelTypeSet encrypted_types; 67 ModelTypeSet encrypted_types;
69 bool passphrase_missing = false; 68 bool passphrase_missing = false;
70 Cryptographer* cryptographer = dir->GetCryptographer(trans); 69 Cryptographer* cryptographer = dir->GetCryptographer(trans);
71 if (cryptographer) { 70 if (cryptographer) {
72 encrypted_types = dir->GetNigoriHandler()->GetEncryptedTypes(trans); 71 encrypted_types = dir->GetNigoriHandler()->GetEncryptedTypes(trans);
73 passphrase_missing = cryptographer->has_pending_keys(); 72 passphrase_missing = cryptographer->has_pending_keys();
74 } 73 }
75 74
76 // We filter out all unready entries from the set of unsynced handles. This 75 // We filter out all unready entries from the set of unsynced handles. This
77 // new set of ready and unsynced items is then what we use to determine what 76 // new set of ready and unsynced items is then what we use to determine what
78 // is a candidate for commit. The caller is responsible for ensuring that no 77 // is a candidate for commit. The caller is responsible for ensuring that no
79 // throttled types are included among the requested_types. 78 // throttled types are included among the requested_types.
80 FilterUnreadyEntries(trans, 79 FilterUnreadyEntries(trans, ModelTypeSet(type), encrypted_types,
81 ModelTypeSet(type), 80 passphrase_missing, all_unsynced_handles,
82 encrypted_types,
83 passphrase_missing,
84 all_unsynced_handles,
85 &ready_unsynced_set); 81 &ready_unsynced_set);
86 82
87 OrderCommitIds(trans, max_entries, ready_unsynced_set, out); 83 OrderCommitIds(trans, max_entries, ready_unsynced_set, out);
88 84
89 for (size_t i = 0; i < out->size(); i++) { 85 for (size_t i = 0; i < out->size(); i++) {
90 DVLOG(1) << "Debug commit batch result:" << (*out)[i]; 86 DVLOG(1) << "Debug commit batch result:" << (*out)[i];
91 } 87 }
92 } 88 }
93 89
94 namespace { 90 namespace {
95 91
96 bool IsEntryInConflict(const syncable::Entry& entry) { 92 bool IsEntryInConflict(const syncable::Entry& entry) {
97 if (entry.GetIsUnsynced() && 93 if (entry.GetIsUnsynced() && entry.GetServerVersion() > 0 &&
98 entry.GetServerVersion() > 0 &&
99 (entry.GetServerVersion() > entry.GetBaseVersion())) { 94 (entry.GetServerVersion() > entry.GetBaseVersion())) {
100 // The local and server versions don't match. The item must be in 95 // The local and server versions don't match. The item must be in
101 // conflict, so there's no point in attempting to commit. 96 // conflict, so there's no point in attempting to commit.
102 DCHECK(entry.GetIsUnappliedUpdate()); 97 DCHECK(entry.GetIsUnappliedUpdate());
103 DVLOG(1) << "Excluding entry from commit due to version mismatch " 98 DVLOG(1) << "Excluding entry from commit due to version mismatch " << entry;
104 << entry;
105 return true; 99 return true;
106 } 100 }
107 return false; 101 return false;
108 } 102 }
109 103
110 // Return true if this entry has any attachments that haven't yet been uploaded 104 // Return true if this entry has any attachments that haven't yet been uploaded
111 // to the server. 105 // to the server.
112 bool HasAttachmentNotOnServer(const syncable::Entry& entry) { 106 bool HasAttachmentNotOnServer(const syncable::Entry& entry) {
113 const sync_pb::AttachmentMetadata& metadata = entry.GetAttachmentMetadata(); 107 const sync_pb::AttachmentMetadata& metadata = entry.GetAttachmentMetadata();
114 for (int i = 0; i < metadata.record_size(); ++i) { 108 for (int i = 0; i < metadata.record_size(); ++i) {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 483
490 void Traversal::AddCreatesAndMoves( 484 void Traversal::AddCreatesAndMoves(
491 const std::set<int64_t>& ready_unsynced_set) { 485 const std::set<int64_t>& ready_unsynced_set) {
492 // Add moves and creates, and prepend their uncommitted parents. 486 // Add moves and creates, and prepend their uncommitted parents.
493 for (std::set<int64_t>::const_iterator iter = ready_unsynced_set.begin(); 487 for (std::set<int64_t>::const_iterator iter = ready_unsynced_set.begin();
494 !IsFull() && iter != ready_unsynced_set.end(); ++iter) { 488 !IsFull() && iter != ready_unsynced_set.end(); ++iter) {
495 int64_t metahandle = *iter; 489 int64_t metahandle = *iter;
496 if (HaveItem(metahandle)) 490 if (HaveItem(metahandle))
497 continue; 491 continue;
498 492
499 syncable::Entry entry(trans_, 493 syncable::Entry entry(trans_, syncable::GET_BY_HANDLE, metahandle);
500 syncable::GET_BY_HANDLE,
501 metahandle);
502 if (!entry.GetIsDel()) { 494 if (!entry.GetIsDel()) {
503 if (SupportsHierarchy(entry)) { 495 if (SupportsHierarchy(entry)) {
504 // We only commit an item + its dependencies if it and all its 496 // We only commit an item + its dependencies if it and all its
505 // dependencies are not in conflict. 497 // dependencies are not in conflict.
506 syncable::Directory::Metahandles item_dependencies; 498 syncable::Directory::Metahandles item_dependencies;
507 AddUncommittedParents(ready_unsynced_set, entry, &item_dependencies); 499 AddUncommittedParents(ready_unsynced_set, entry, &item_dependencies);
508 TryAddItem(ready_unsynced_set, entry, &item_dependencies); 500 TryAddItem(ready_unsynced_set, entry, &item_dependencies);
509 AppendManyToTraversal(item_dependencies); 501 AppendManyToTraversal(item_dependencies);
510 } else { 502 } else {
511 // No hierarchy dependencies, just commit the item itself. 503 // No hierarchy dependencies, just commit the item itself.
(...skipping 19 matching lines...) Expand all
531 int64_t metahandle = *iter; 523 int64_t metahandle = *iter;
532 524
533 if (HaveItem(metahandle)) 525 if (HaveItem(metahandle))
534 continue; 526 continue;
535 527
536 if (std::find(deletion_list.begin(), deletion_list.end(), metahandle) != 528 if (std::find(deletion_list.begin(), deletion_list.end(), metahandle) !=
537 deletion_list.end()) { 529 deletion_list.end()) {
538 continue; 530 continue;
539 } 531 }
540 532
541 syncable::Entry entry(trans_, syncable::GET_BY_HANDLE, 533 syncable::Entry entry(trans_, syncable::GET_BY_HANDLE, metahandle);
542 metahandle);
543 534
544 if (entry.GetIsDel()) { 535 if (entry.GetIsDel()) {
545 if (SupportsHierarchy(entry)) { 536 if (SupportsHierarchy(entry)) {
546 syncable::Directory::Metahandles parents; 537 syncable::Directory::Metahandles parents;
547 AddDeletedParents(ready_unsynced_set, entry, deletion_list, &parents); 538 AddDeletedParents(ready_unsynced_set, entry, deletion_list, &parents);
548 // Append parents and chilren in top to bottom order. 539 // Append parents and chilren in top to bottom order.
549 deletion_list.insert(deletion_list.end(), parents.begin(), 540 deletion_list.insert(deletion_list.end(), parents.begin(),
550 parents.end()); 541 parents.end());
551 } 542 }
552 deletion_list.push_back(metahandle); 543 deletion_list.push_back(metahandle);
(...skipping 28 matching lines...) Expand all
581 // Add moves and creates, and prepend their uncommitted parents. 572 // Add moves and creates, and prepend their uncommitted parents.
582 traversal.AddCreatesAndMoves(ready_unsynced_set); 573 traversal.AddCreatesAndMoves(ready_unsynced_set);
583 574
584 // Add all deletes. 575 // Add all deletes.
585 traversal.AddDeletes(ready_unsynced_set); 576 traversal.AddDeletes(ready_unsynced_set);
586 } 577 }
587 578
588 } // namespace 579 } // namespace
589 580
590 } // namespace syncer 581 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/get_commit_ids.h ('k') | components/sync/engine_impl/get_updates_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698