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

Side by Side Diff: sync/syncable/entry.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
« no previous file with comments | « sync/syncable/entry.h ('k') | sync/syncable/entry_kernel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sync/syncable/entry.h"
6
7 #include <stdint.h>
8
9 #include <iomanip>
10
11 #include "sync/syncable/directory.h"
12 #include "sync/syncable/syncable_base_transaction.h"
13
14 namespace syncer {
15 namespace syncable {
16
17 Entry::Entry(BaseTransaction* trans, GetById, const Id& id)
18 : basetrans_(trans) {
19 kernel_ = trans->directory()->GetEntryById(id);
20 }
21
22 Entry::Entry(BaseTransaction* trans, GetByClientTag, const std::string& tag)
23 : basetrans_(trans) {
24 kernel_ = trans->directory()->GetEntryByClientTag(tag);
25 }
26
27 Entry::Entry(BaseTransaction* trans, GetTypeRoot, ModelType type)
28 : basetrans_(trans) {
29 const std::string& tag = ModelTypeToRootTag(type);
30 kernel_ = trans->directory()->GetEntryByServerTag(tag);
31 }
32
33 Entry::Entry(BaseTransaction* trans, GetByHandle, int64_t metahandle)
34 : basetrans_(trans) {
35 kernel_ = trans->directory()->GetEntryByHandle(metahandle);
36 }
37
38 Entry::Entry(BaseTransaction* trans, GetByServerTag, const std::string& tag)
39 : basetrans_(trans) {
40 kernel_ = trans->directory()->GetEntryByServerTag(tag);
41 }
42
43 Directory* Entry::dir() const {
44 return basetrans_->directory();
45 }
46
47 base::DictionaryValue* Entry::ToValue(Cryptographer* cryptographer) const {
48 base::DictionaryValue* entry_info = new base::DictionaryValue();
49 entry_info->SetBoolean("good", good());
50 if (good()) {
51 entry_info->Set("kernel", kernel_->ToValue(cryptographer));
52 entry_info->Set("modelType",
53 ModelTypeToValue(GetModelType()));
54 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty",
55 ExistsOnClientBecauseNameIsNonEmpty());
56 entry_info->SetBoolean("isRoot", IsRoot());
57 }
58 return entry_info;
59 }
60
61 bool Entry::GetSyncing() const {
62 DCHECK(kernel_);
63 return kernel_->ref(SYNCING);
64 }
65
66 bool Entry::GetDirtySync() const {
67 DCHECK(kernel_);
68 return kernel_->ref(DIRTY_SYNC);
69 }
70
71 ModelType Entry::GetServerModelType() const {
72 ModelType specifics_type = kernel_->GetServerModelType();
73 if (specifics_type != UNSPECIFIED)
74 return specifics_type;
75
76 // Otherwise, we don't have a server type yet. That should only happen
77 // if the item is an uncommitted locally created item.
78 // It's possible we'll need to relax these checks in the future; they're
79 // just here for now as a safety measure.
80 DCHECK(GetIsUnsynced());
81 DCHECK_EQ(GetServerVersion(), 0);
82 DCHECK(GetServerIsDel());
83 // Note: can't enforce !GetId().ServerKnows() here because that could
84 // actually happen if we hit AttemptReuniteLostCommitResponses.
85 return UNSPECIFIED;
86 }
87
88 ModelType Entry::GetModelType() const {
89 ModelType specifics_type = GetModelTypeFromSpecifics(GetSpecifics());
90 if (specifics_type != UNSPECIFIED)
91 return specifics_type;
92 if (IsRoot())
93 return TOP_LEVEL_FOLDER;
94 // Loose check for server-created top-level folders that aren't
95 // bound to a particular model type.
96 if (!GetUniqueServerTag().empty() && GetIsDir())
97 return TOP_LEVEL_FOLDER;
98
99 return UNSPECIFIED;
100 }
101
102 Id Entry::GetPredecessorId() const {
103 return dir()->GetPredecessorId(kernel_);
104 }
105
106 Id Entry::GetSuccessorId() const {
107 return dir()->GetSuccessorId(kernel_);
108 }
109
110 Id Entry::GetFirstChildId() const {
111 return dir()->GetFirstChildId(basetrans_, kernel_);
112 }
113
114 void Entry::GetChildHandles(std::vector<int64_t>* result) const {
115 dir()->GetChildHandlesById(basetrans_, GetId(), result);
116 }
117
118 int Entry::GetTotalNodeCount() const {
119 return dir()->GetTotalNodeCount(basetrans_, kernel_);
120 }
121
122 int Entry::GetPositionIndex() const {
123 return dir()->GetPositionIndex(basetrans_, kernel_);
124 }
125
126 bool Entry::ShouldMaintainPosition() const {
127 return kernel_->ShouldMaintainPosition();
128 }
129
130 bool Entry::ShouldMaintainHierarchy() const {
131 return kernel_->ShouldMaintainHierarchy();
132 }
133
134 std::ostream& operator<<(std::ostream& os, const Entry& entry) {
135 os << *(entry.kernel_);
136 return os;
137 }
138
139 } // namespace syncable
140 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/entry.h ('k') | sync/syncable/entry_kernel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698