1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
#define SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
#pragma once
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "sync/engine/syncer_command.h"
#include "sync/engine/syncer_util.h"
#include "sync/sessions/ordered_commit_set.h"
#include "sync/sessions/sync_session.h"
using std::pair;
using std::vector;
namespace browser_sync {
class GetCommitIdsCommand : public SyncerCommand {
friend class SyncerTest;
public:
explicit GetCommitIdsCommand(int commit_batch_size);
virtual ~GetCommitIdsCommand();
// SyncerCommand implementation.
virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE;
// Builds a vector of IDs that should be committed.
void BuildCommitIds(syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
const std::set<int64>& ready_unsynced_set);
// Fill |ready_unsynced_set| with all entries from |unsynced_handles| that
// are ready to commit.
// An entry is not considered ready for commit if any are true:
// 1. It's in conflict.
// 2. It requires encryption (either the type is encrypted but a passphrase
// is missing from the cryptographer, or the entry itself wasn't properly
// encrypted).
// 3. It's type is currently throttled.
// 4. It's a delete but has not been committed.
void FilterUnreadyEntries(
syncable::BaseTransaction* trans,
syncable::ModelTypeSet throttled_types,
syncable::ModelTypeSet encrypted_types,
bool passphrase_missing,
const syncable::Directory::UnsyncedMetaHandles& unsynced_handles,
std::set<int64>* ready_unsynced_set);
private:
// Add all the uncommitted parents (and their predecessors) of |item| to
// |result| if they are ready to commit. Entries are added in root->child
// order and predecessor->successor order.
// Returns values:
// False: if a dependent item was in conflict, and hence no child cannot be
// committed.
// True: if all parents and their predecessors were checked for commit
// readiness and were added to |result| as necessary.
bool AddUncommittedParentsAndTheirPredecessors(
syncable::BaseTransaction* trans,
const ModelSafeRoutingInfo& routes,
const std::set<int64>& ready_unsynced_set,
const syncable::Entry& item,
sessions::OrderedCommitSet* result) const;
// OrderedCommitSet helpers for adding predecessors in order.
// Adds |item| to |result| if it's ready for committing and was not already
// present.
// Prereq: |item| is unsynced.
// Returns values:
// False: if |item| was in conflict.
// True: if |item| was checked for commit readiness and added to |result|
// as necessary.
bool AddItem(const std::set<int64>& ready_unsynced_set,
const syncable::Entry& item,
sessions::OrderedCommitSet* result) const;
// Adds item and all its unsynced predecessors to |result| as necessary, as
// long as no item was in conflict.
// Return values:
// False: if there was an entry in conflict.
// True: if all entries were checked for commit readiness and added to
// |result| as necessary.
bool AddItemThenPredecessors(syncable::BaseTransaction* trans,
const std::set<int64>& ready_unsynced_set,
const syncable::Entry& item,
sessions::OrderedCommitSet* result) const;
// Appends all commit ready predecessors of |item|, followed by |item| itself,
// to |ordered_commit_set_|, iff item and all its predecessors not in
// conflict.
// Return values:
// False: if there was an entry in conflict.
// True: if all entries were checked for commit readiness and added to
// |result| as necessary.
bool AddPredecessorsThenItem(syncable::BaseTransaction* trans,
const ModelSafeRoutingInfo& routes,
const std::set<int64>& ready_unsynced_set,
const syncable::Entry& item,
sessions::OrderedCommitSet* result) const;
bool IsCommitBatchFull() const;
void AddCreatesAndMoves(syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
const std::set<int64>& ready_unsynced_set);
void AddDeletes(syncable::WriteTransaction* write_transaction,
const std::set<int64>& ready_unsynced_set);
scoped_ptr<sessions::OrderedCommitSet> ordered_commit_set_;
int requested_commit_batch_size_;
DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand);
};
} // namespace browser_sync
#endif // SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
|