OLD | NEW |
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/syncable/model_neutral_mutable_entry.h" | 5 #include "sync/syncable/model_neutral_mutable_entry.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "sync/internal_api/public/base/unique_position.h" | 12 #include "sync/internal_api/public/base/unique_position.h" |
10 #include "sync/syncable/directory.h" | 13 #include "sync/syncable/directory.h" |
11 #include "sync/syncable/scoped_kernel_lock.h" | 14 #include "sync/syncable/scoped_kernel_lock.h" |
12 #include "sync/syncable/syncable_changes_version.h" | 15 #include "sync/syncable/syncable_changes_version.h" |
13 #include "sync/syncable/syncable_util.h" | 16 #include "sync/syncable/syncable_util.h" |
14 #include "sync/syncable/syncable_write_transaction.h" | 17 #include "sync/syncable/syncable_write_transaction.h" |
15 | 18 |
16 using std::string; | 19 using std::string; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 trans->TrackChangesTo(kernel.get()); | 84 trans->TrackChangesTo(kernel.get()); |
82 | 85 |
83 kernel_ = kernel.release(); | 86 kernel_ = kernel.release(); |
84 } | 87 } |
85 | 88 |
86 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 89 ModelNeutralMutableEntry::ModelNeutralMutableEntry( |
87 BaseWriteTransaction* trans, GetById, const Id& id) | 90 BaseWriteTransaction* trans, GetById, const Id& id) |
88 : Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) { | 91 : Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) { |
89 } | 92 } |
90 | 93 |
91 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 94 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, |
92 BaseWriteTransaction* trans, GetByHandle, int64 metahandle) | 95 GetByHandle, |
93 : Entry(trans, GET_BY_HANDLE, metahandle), base_write_transaction_(trans) { | 96 int64_t metahandle) |
94 } | 97 : Entry(trans, GET_BY_HANDLE, metahandle), base_write_transaction_(trans) {} |
95 | 98 |
96 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 99 ModelNeutralMutableEntry::ModelNeutralMutableEntry( |
97 BaseWriteTransaction* trans, GetByClientTag, const std::string& tag) | 100 BaseWriteTransaction* trans, GetByClientTag, const std::string& tag) |
98 : Entry(trans, GET_BY_CLIENT_TAG, tag), base_write_transaction_(trans) { | 101 : Entry(trans, GET_BY_CLIENT_TAG, tag), base_write_transaction_(trans) { |
99 } | 102 } |
100 | 103 |
101 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 104 ModelNeutralMutableEntry::ModelNeutralMutableEntry( |
102 BaseWriteTransaction* trans, GetTypeRoot, ModelType type) | 105 BaseWriteTransaction* trans, GetTypeRoot, ModelType type) |
103 : Entry(trans, GET_TYPE_ROOT, type), base_write_transaction_(trans) { | 106 : Entry(trans, GET_TYPE_ROOT, type), base_write_transaction_(trans) { |
104 } | 107 } |
105 | 108 |
106 void ModelNeutralMutableEntry::PutBaseVersion(int64 value) { | 109 void ModelNeutralMutableEntry::PutBaseVersion(int64_t value) { |
107 DCHECK(kernel_); | 110 DCHECK(kernel_); |
108 if (kernel_->ref(BASE_VERSION) != value) { | 111 if (kernel_->ref(BASE_VERSION) != value) { |
109 base_write_transaction_->TrackChangesTo(kernel_); | 112 base_write_transaction_->TrackChangesTo(kernel_); |
110 kernel_->put(BASE_VERSION, value); | 113 kernel_->put(BASE_VERSION, value); |
111 MarkDirty(); | 114 MarkDirty(); |
112 } | 115 } |
113 } | 116 } |
114 | 117 |
115 void ModelNeutralMutableEntry::PutServerVersion(int64 value) { | 118 void ModelNeutralMutableEntry::PutServerVersion(int64_t value) { |
116 DCHECK(kernel_); | 119 DCHECK(kernel_); |
117 if (kernel_->ref(SERVER_VERSION) != value) { | 120 if (kernel_->ref(SERVER_VERSION) != value) { |
118 base_write_transaction_->TrackChangesTo(kernel_); | 121 base_write_transaction_->TrackChangesTo(kernel_); |
119 ScopedKernelLock lock(dir()); | 122 ScopedKernelLock lock(dir()); |
120 kernel_->put(SERVER_VERSION, value); | 123 kernel_->put(SERVER_VERSION, value); |
121 MarkDirty(); | 124 MarkDirty(); |
122 } | 125 } |
123 } | 126 } |
124 | 127 |
125 void ModelNeutralMutableEntry::PutServerMtime(base::Time value) { | 128 void ModelNeutralMutableEntry::PutServerMtime(base::Time value) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 CHECK(!value.password().has_client_only_encrypted_data()); | 346 CHECK(!value.password().has_client_only_encrypted_data()); |
344 // TODO(ncarter): This is unfortunately heavyweight. Can we do | 347 // TODO(ncarter): This is unfortunately heavyweight. Can we do |
345 // better? | 348 // better? |
346 const std::string& serialized_value = value.SerializeAsString(); | 349 const std::string& serialized_value = value.SerializeAsString(); |
347 if (serialized_value != kernel_->ref(SERVER_SPECIFICS).SerializeAsString()) { | 350 if (serialized_value != kernel_->ref(SERVER_SPECIFICS).SerializeAsString()) { |
348 base_write_transaction_->TrackChangesTo(kernel_); | 351 base_write_transaction_->TrackChangesTo(kernel_); |
349 if (kernel_->ref(IS_UNAPPLIED_UPDATE)) { | 352 if (kernel_->ref(IS_UNAPPLIED_UPDATE)) { |
350 // Remove ourselves from unapplied_update_metahandles with our | 353 // Remove ourselves from unapplied_update_metahandles with our |
351 // old server type. | 354 // old server type. |
352 const ModelType old_server_type = kernel_->GetServerModelType(); | 355 const ModelType old_server_type = kernel_->GetServerModelType(); |
353 const int64 metahandle = kernel_->ref(META_HANDLE); | 356 const int64_t metahandle = kernel_->ref(META_HANDLE); |
354 size_t erase_count = | 357 size_t erase_count = |
355 dir()->kernel()->unapplied_update_metahandles[old_server_type] | 358 dir()->kernel()->unapplied_update_metahandles[old_server_type] |
356 .erase(metahandle); | 359 .erase(metahandle); |
357 DCHECK_EQ(erase_count, 1u); | 360 DCHECK_EQ(erase_count, 1u); |
358 } | 361 } |
359 | 362 |
360 // Check for potential sharing - SERVER_SPECIFICS is often | 363 // Check for potential sharing - SERVER_SPECIFICS is often |
361 // copied from SPECIFICS. | 364 // copied from SPECIFICS. |
362 if (serialized_value == kernel_->ref(SPECIFICS).SerializeAsString()) { | 365 if (serialized_value == kernel_->ref(SPECIFICS).SerializeAsString()) { |
363 kernel_->copy(SPECIFICS, SERVER_SPECIFICS); | 366 kernel_->copy(SPECIFICS, SERVER_SPECIFICS); |
364 } else { | 367 } else { |
365 kernel_->put(SERVER_SPECIFICS, value); | 368 kernel_->put(SERVER_SPECIFICS, value); |
366 } | 369 } |
367 MarkDirty(); | 370 MarkDirty(); |
368 | 371 |
369 if (kernel_->ref(IS_UNAPPLIED_UPDATE)) { | 372 if (kernel_->ref(IS_UNAPPLIED_UPDATE)) { |
370 // Add ourselves back into unapplied_update_metahandles with our | 373 // Add ourselves back into unapplied_update_metahandles with our |
371 // new server type. | 374 // new server type. |
372 const ModelType new_server_type = kernel_->GetServerModelType(); | 375 const ModelType new_server_type = kernel_->GetServerModelType(); |
373 const int64 metahandle = kernel_->ref(META_HANDLE); | 376 const int64_t metahandle = kernel_->ref(META_HANDLE); |
374 dir()->kernel()->unapplied_update_metahandles[new_server_type] | 377 dir()->kernel()->unapplied_update_metahandles[new_server_type] |
375 .insert(metahandle); | 378 .insert(metahandle); |
376 } | 379 } |
377 } | 380 } |
378 } | 381 } |
379 | 382 |
380 void ModelNeutralMutableEntry::PutBaseServerSpecifics( | 383 void ModelNeutralMutableEntry::PutBaseServerSpecifics( |
381 const sync_pb::EntitySpecifics& value) { | 384 const sync_pb::EntitySpecifics& value) { |
382 DCHECK(kernel_); | 385 DCHECK(kernel_); |
383 CHECK(!value.password().has_client_only_encrypted_data()); | 386 CHECK(!value.password().has_client_only_encrypted_data()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 DCHECK(!value || GetSyncing()); | 442 DCHECK(!value || GetSyncing()); |
440 kernel_->put(DIRTY_SYNC, value); | 443 kernel_->put(DIRTY_SYNC, value); |
441 } | 444 } |
442 | 445 |
443 void ModelNeutralMutableEntry::PutParentIdPropertyOnly(const Id& parent_id) { | 446 void ModelNeutralMutableEntry::PutParentIdPropertyOnly(const Id& parent_id) { |
444 base_write_transaction_->TrackChangesTo(kernel_); | 447 base_write_transaction_->TrackChangesTo(kernel_); |
445 dir()->ReindexParentId(base_write_transaction(), kernel_, parent_id); | 448 dir()->ReindexParentId(base_write_transaction(), kernel_, parent_id); |
446 MarkDirty(); | 449 MarkDirty(); |
447 } | 450 } |
448 | 451 |
449 void ModelNeutralMutableEntry::UpdateTransactionVersion(int64 value) { | 452 void ModelNeutralMutableEntry::UpdateTransactionVersion(int64_t value) { |
450 kernel_->put(TRANSACTION_VERSION, value); | 453 kernel_->put(TRANSACTION_VERSION, value); |
451 MarkDirty(); | 454 MarkDirty(); |
452 } | 455 } |
453 | 456 |
454 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) | 457 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) |
455 : Entry(trans), base_write_transaction_(trans) {} | 458 : Entry(trans), base_write_transaction_(trans) {} |
456 | 459 |
457 void ModelNeutralMutableEntry::MarkDirty() { | 460 void ModelNeutralMutableEntry::MarkDirty() { |
458 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); | 461 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); |
459 } | 462 } |
460 | 463 |
461 } // namespace syncable | 464 } // namespace syncable |
462 | 465 |
463 } // namespace syncer | 466 } // namespace syncer |
OLD | NEW |