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 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 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.
#include "components/sync/syncable/entry.h"
#include <iomanip>
#include "components/sync/syncable/directory.h"
#include "components/sync/syncable/syncable_base_transaction.h"
namespace syncer {
namespace syncable {
Entry::Entry(BaseTransaction* trans, GetById, const Id& id)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryById(id);
}
Entry::Entry(BaseTransaction* trans, GetByClientTag, const std::string& tag)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryByClientTag(tag);
}
Entry::Entry(BaseTransaction* trans, GetTypeRoot, ModelType type)
: basetrans_(trans) {
const std::string& tag = ModelTypeToRootTag(type);
kernel_ = trans->directory()->GetEntryByServerTag(tag);
}
Entry::Entry(BaseTransaction* trans, GetByHandle, int64_t metahandle)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryByHandle(metahandle);
}
Entry::Entry(BaseTransaction* trans, GetByServerTag, const std::string& tag)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryByServerTag(tag);
}
Directory* Entry::dir() const {
return basetrans_->directory();
}
base::DictionaryValue* Entry::ToValue(Cryptographer* cryptographer) const {
base::DictionaryValue* entry_info = new base::DictionaryValue();
entry_info->SetBoolean("good", good());
if (good()) {
entry_info->Set("kernel", kernel_->ToValue(cryptographer));
entry_info->Set("modelType", ModelTypeToValue(GetModelType()));
entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty",
ExistsOnClientBecauseNameIsNonEmpty());
entry_info->SetBoolean("isRoot", IsRoot());
}
return entry_info;
}
bool Entry::GetSyncing() const {
DCHECK(kernel_);
return kernel_->ref(SYNCING);
}
bool Entry::GetDirtySync() const {
DCHECK(kernel_);
return kernel_->ref(DIRTY_SYNC);
}
ModelType Entry::GetServerModelType() const {
ModelType specifics_type = kernel_->GetServerModelType();
if (specifics_type != UNSPECIFIED)
return specifics_type;
// Otherwise, we don't have a server type yet. That should only happen
// if the item is an uncommitted locally created item.
// It's possible we'll need to relax these checks in the future; they're
// just here for now as a safety measure.
DCHECK(GetIsUnsynced());
DCHECK_EQ(GetServerVersion(), 0);
DCHECK(GetServerIsDel());
// Note: can't enforce !GetId().ServerKnows() here because that could
// actually happen if we hit AttemptReuniteLostCommitResponses.
return UNSPECIFIED;
}
ModelType Entry::GetModelType() const {
ModelType specifics_type = GetModelTypeFromSpecifics(GetSpecifics());
if (specifics_type != UNSPECIFIED)
return specifics_type;
if (IsRoot())
return TOP_LEVEL_FOLDER;
// Loose check for server-created top-level folders that aren't
// bound to a particular model type.
if (!GetUniqueServerTag().empty() && GetIsDir())
return TOP_LEVEL_FOLDER;
return UNSPECIFIED;
}
Id Entry::GetPredecessorId() const {
return dir()->GetPredecessorId(kernel_);
}
Id Entry::GetSuccessorId() const {
return dir()->GetSuccessorId(kernel_);
}
Id Entry::GetFirstChildId() const {
return dir()->GetFirstChildId(basetrans_, kernel_);
}
void Entry::GetChildHandles(std::vector<int64_t>* result) const {
dir()->GetChildHandlesById(basetrans_, GetId(), result);
}
int Entry::GetTotalNodeCount() const {
return dir()->GetTotalNodeCount(basetrans_, kernel_);
}
int Entry::GetPositionIndex() const {
return dir()->GetPositionIndex(basetrans_, kernel_);
}
bool Entry::ShouldMaintainPosition() const {
return kernel_->ShouldMaintainPosition();
}
bool Entry::ShouldMaintainHierarchy() const {
return kernel_->ShouldMaintainHierarchy();
}
std::ostream& operator<<(std::ostream& os, const Entry& entry) {
os << *(entry.kernel_);
return os;
}
} // namespace syncable
} // namespace syncer
|