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

Side by Side Diff: components/sync/syncable/mutable_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 | « components/sync/syncable/mutable_entry.h ('k') | components/sync/syncable/nigori_handler.h » ('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 2012 The Chromium Authors. All rights reserved. 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 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/syncable/mutable_entry.h" 5 #include "components/sync/syncable/mutable_entry.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "sync/internal_api/public/base/unique_position.h" 11 #include "components/sync/base/unique_position.h"
12 #include "sync/syncable/directory.h" 12 #include "components/sync/syncable/directory.h"
13 #include "sync/syncable/scoped_kernel_lock.h" 13 #include "components/sync/syncable/scoped_kernel_lock.h"
14 #include "sync/syncable/scoped_parent_child_index_updater.h" 14 #include "components/sync/syncable/scoped_parent_child_index_updater.h"
15 #include "sync/syncable/syncable-inl.h" 15 #include "components/sync/syncable/syncable-inl.h"
16 #include "sync/syncable/syncable_changes_version.h" 16 #include "components/sync/syncable/syncable_changes_version.h"
17 #include "sync/syncable/syncable_util.h" 17 #include "components/sync/syncable/syncable_util.h"
18 #include "sync/syncable/syncable_write_transaction.h" 18 #include "components/sync/syncable/syncable_write_transaction.h"
19 19
20 using std::string; 20 using std::string;
21 21
22 namespace syncer { 22 namespace syncer {
23 namespace syncable { 23 namespace syncable {
24 24
25 void MutableEntry::Init(WriteTransaction* trans, 25 void MutableEntry::Init(WriteTransaction* trans,
26 ModelType model_type, 26 ModelType model_type,
27 const Id& parent_id, 27 const Id& parent_id,
28 const string& name) { 28 const string& name) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 kernel_->put(UNIQUE_BOOKMARK_TAG, unique_tag); 89 kernel_->put(UNIQUE_BOOKMARK_TAG, unique_tag);
90 kernel_->put(UNIQUE_POSITION, UniquePosition::InitialPosition(unique_tag)); 90 kernel_->put(UNIQUE_POSITION, UniquePosition::InitialPosition(unique_tag));
91 } else { 91 } else {
92 DCHECK(!ShouldMaintainPosition()); 92 DCHECK(!ShouldMaintainPosition());
93 } 93 }
94 94
95 bool result = trans->directory()->InsertEntry(trans, kernel_); 95 bool result = trans->directory()->InsertEntry(trans, kernel_);
96 DCHECK(result); 96 DCHECK(result);
97 } 97 }
98 98
99 MutableEntry::MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, 99 MutableEntry::MutableEntry(WriteTransaction* trans,
100 CreateNewUpdateItem,
100 const Id& id) 101 const Id& id)
101 : ModelNeutralMutableEntry(trans, CREATE_NEW_UPDATE_ITEM, id), 102 : ModelNeutralMutableEntry(trans, CREATE_NEW_UPDATE_ITEM, id),
102 write_transaction_(trans) {} 103 write_transaction_(trans) {}
103 104
104 MutableEntry::MutableEntry(WriteTransaction* trans, GetById, const Id& id) 105 MutableEntry::MutableEntry(WriteTransaction* trans, GetById, const Id& id)
105 : ModelNeutralMutableEntry(trans, GET_BY_ID, id), 106 : ModelNeutralMutableEntry(trans, GET_BY_ID, id),
106 write_transaction_(trans) { 107 write_transaction_(trans) {}
107 }
108 108
109 MutableEntry::MutableEntry(WriteTransaction* trans, 109 MutableEntry::MutableEntry(WriteTransaction* trans,
110 GetByHandle, 110 GetByHandle,
111 int64_t metahandle) 111 int64_t metahandle)
112 : ModelNeutralMutableEntry(trans, GET_BY_HANDLE, metahandle), 112 : ModelNeutralMutableEntry(trans, GET_BY_HANDLE, metahandle),
113 write_transaction_(trans) {} 113 write_transaction_(trans) {}
114 114
115 MutableEntry::MutableEntry(WriteTransaction* trans, GetByClientTag, 115 MutableEntry::MutableEntry(WriteTransaction* trans,
116 GetByClientTag,
116 const std::string& tag) 117 const std::string& tag)
117 : ModelNeutralMutableEntry(trans, GET_BY_CLIENT_TAG, tag), 118 : ModelNeutralMutableEntry(trans, GET_BY_CLIENT_TAG, tag),
118 write_transaction_(trans) { 119 write_transaction_(trans) {}
119 }
120 120
121 MutableEntry::MutableEntry(WriteTransaction* trans, GetTypeRoot, ModelType type) 121 MutableEntry::MutableEntry(WriteTransaction* trans, GetTypeRoot, ModelType type)
122 : ModelNeutralMutableEntry(trans, GET_TYPE_ROOT, type), 122 : ModelNeutralMutableEntry(trans, GET_TYPE_ROOT, type),
123 write_transaction_(trans) { 123 write_transaction_(trans) {}
124 }
125 124
126 void MutableEntry::PutLocalExternalId(int64_t value) { 125 void MutableEntry::PutLocalExternalId(int64_t value) {
127 DCHECK(kernel_); 126 DCHECK(kernel_);
128 if (kernel_->ref(LOCAL_EXTERNAL_ID) != value) { 127 if (kernel_->ref(LOCAL_EXTERNAL_ID) != value) {
129 write_transaction()->TrackChangesTo(kernel_); 128 write_transaction()->TrackChangesTo(kernel_);
130 ScopedKernelLock lock(dir()); 129 ScopedKernelLock lock(dir());
131 kernel_->put(LOCAL_EXTERNAL_ID, value); 130 kernel_->put(LOCAL_EXTERNAL_ID, value);
132 MarkDirty(); 131 MarkDirty();
133 } 132 }
134 } 133 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (!GetId().ServerKnows() && !GetSyncing()) { 194 if (!GetId().ServerKnows() && !GetSyncing()) {
196 PutIsUnsynced(false); 195 PutIsUnsynced(false);
197 } 196 }
198 } 197 }
199 198
200 { 199 {
201 ScopedKernelLock lock(dir()); 200 ScopedKernelLock lock(dir());
202 // Some indices don't include deleted items and must be updated 201 // Some indices don't include deleted items and must be updated
203 // upon a value change. 202 // upon a value change.
204 ScopedParentChildIndexUpdater updater(lock, kernel_, 203 ScopedParentChildIndexUpdater updater(lock, kernel_,
205 &dir()->kernel()->parent_child_index); 204 &dir()->kernel()->parent_child_index);
206 205
207 kernel_->put(IS_DEL, value); 206 kernel_->put(IS_DEL, value);
208 MarkDirty(); 207 MarkDirty();
209 } 208 }
210 } 209 }
211 210
212 void MutableEntry::PutNonUniqueName(const std::string& value) { 211 void MutableEntry::PutNonUniqueName(const std::string& value) {
213 DCHECK(kernel_); 212 DCHECK(kernel_);
214 if (kernel_->ref(NON_UNIQUE_NAME) != value) { 213 if (kernel_->ref(NON_UNIQUE_NAME) != value) {
215 write_transaction()->TrackChangesTo(kernel_); 214 write_transaction()->TrackChangesTo(kernel_);
(...skipping 22 matching lines...) Expand all
238 } 237 }
239 } 238 }
240 239
241 void MutableEntry::PutUniquePosition(const UniquePosition& value) { 240 void MutableEntry::PutUniquePosition(const UniquePosition& value) {
242 DCHECK(kernel_); 241 DCHECK(kernel_);
243 if (!kernel_->ref(UNIQUE_POSITION).Equals(value)) { 242 if (!kernel_->ref(UNIQUE_POSITION).Equals(value)) {
244 write_transaction()->TrackChangesTo(kernel_); 243 write_transaction()->TrackChangesTo(kernel_);
245 // We should never overwrite a valid position with an invalid one. 244 // We should never overwrite a valid position with an invalid one.
246 DCHECK(value.IsValid()); 245 DCHECK(value.IsValid());
247 ScopedKernelLock lock(dir()); 246 ScopedKernelLock lock(dir());
248 ScopedParentChildIndexUpdater updater( 247 ScopedParentChildIndexUpdater updater(lock, kernel_,
249 lock, kernel_, &dir()->kernel()->parent_child_index); 248 &dir()->kernel()->parent_child_index);
250 kernel_->put(UNIQUE_POSITION, value); 249 kernel_->put(UNIQUE_POSITION, value);
251 MarkDirty(); 250 MarkDirty();
252 } 251 }
253 } 252 }
254 253
255 bool MutableEntry::PutPredecessor(const Id& predecessor_id) { 254 bool MutableEntry::PutPredecessor(const Id& predecessor_id) {
256 if (predecessor_id.IsNull()) { 255 if (predecessor_id.IsNull()) {
257 dir()->PutPredecessor(kernel_, NULL); 256 dir()->PutPredecessor(kernel_, NULL);
258 } else { 257 } else {
259 MutableEntry predecessor(write_transaction(), GET_BY_ID, predecessor_id); 258 MutableEntry predecessor(write_transaction(), GET_BY_ID, predecessor_id);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; 312 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing.";
314 if (!(e->PutIsUnsynced(true))) 313 if (!(e->PutIsUnsynced(true)))
315 return false; 314 return false;
316 if (e->GetSyncing()) 315 if (e->GetSyncing())
317 e->PutDirtySync(true); 316 e->PutDirtySync(true);
318 return true; 317 return true;
319 } 318 }
320 319
321 } // namespace syncable 320 } // namespace syncable
322 } // namespace syncer 321 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/mutable_entry.h ('k') | components/sync/syncable/nigori_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698