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/directory.h" | 5 #include "sync/syncable/directory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "sync/internal_api/public/base/attachment_id_proto.h" | 16 #include "sync/internal_api/public/base/attachment_id_proto.h" |
17 #include "sync/internal_api/public/base/unique_position.h" | 17 #include "sync/internal_api/public/base/unique_position.h" |
18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
19 #include "sync/syncable/entry.h" | 19 #include "sync/syncable/entry.h" |
20 #include "sync/syncable/entry_kernel.h" | 20 #include "sync/syncable/entry_kernel.h" |
21 #include "sync/syncable/in_memory_directory_backing_store.h" | 21 #include "sync/syncable/in_memory_directory_backing_store.h" |
| 22 #include "sync/syncable/model_neutral_mutable_entry.h" |
22 #include "sync/syncable/on_disk_directory_backing_store.h" | 23 #include "sync/syncable/on_disk_directory_backing_store.h" |
23 #include "sync/syncable/scoped_kernel_lock.h" | 24 #include "sync/syncable/scoped_kernel_lock.h" |
24 #include "sync/syncable/scoped_parent_child_index_updater.h" | 25 #include "sync/syncable/scoped_parent_child_index_updater.h" |
25 #include "sync/syncable/syncable-inl.h" | 26 #include "sync/syncable/syncable-inl.h" |
26 #include "sync/syncable/syncable_base_transaction.h" | 27 #include "sync/syncable/syncable_base_transaction.h" |
27 #include "sync/syncable/syncable_changes_version.h" | 28 #include "sync/syncable/syncable_changes_version.h" |
28 #include "sync/syncable/syncable_read_transaction.h" | 29 #include "sync/syncable/syncable_read_transaction.h" |
29 #include "sync/syncable/syncable_util.h" | 30 #include "sync/syncable/syncable_util.h" |
30 #include "sync/syncable/syncable_write_transaction.h" | 31 #include "sync/syncable/syncable_write_transaction.h" |
31 | 32 |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 return initial_sync_ended_types; | 979 return initial_sync_ended_types; |
979 } | 980 } |
980 | 981 |
981 bool Directory::InitialSyncEndedForType(ModelType type) { | 982 bool Directory::InitialSyncEndedForType(ModelType type) { |
982 syncable::ReadTransaction trans(FROM_HERE, this); | 983 syncable::ReadTransaction trans(FROM_HERE, this); |
983 return InitialSyncEndedForType(&trans, type); | 984 return InitialSyncEndedForType(&trans, type); |
984 } | 985 } |
985 | 986 |
986 bool Directory::InitialSyncEndedForType( | 987 bool Directory::InitialSyncEndedForType( |
987 BaseTransaction* trans, ModelType type) { | 988 BaseTransaction* trans, ModelType type) { |
988 // True iff the type's root node has been created. | 989 // True iff the type's root node has been created and changes |
989 syncable::Entry entry(trans, syncable::GET_TYPE_ROOT, type); | 990 // for the type have been applied at least once. |
990 return entry.good(); | 991 Entry root(trans, GET_TYPE_ROOT, type); |
| 992 return root.good() && root.GetBaseVersion() != CHANGES_VERSION; |
| 993 } |
| 994 |
| 995 void Directory::MarkInitialSyncEndedForType(BaseWriteTransaction* trans, |
| 996 ModelType type) { |
| 997 // If the root folder is downloaded for the server, the root's base version |
| 998 // get updated automatically at the end of update cycle when the update gets |
| 999 // applied. However if this is a type with client generated root, the root |
| 1000 // node gets created locally and never goes through the update cycle. In that |
| 1001 // case its base version has to be explictly changed from CHANGES_VERSION |
| 1002 // at the end of the initial update cycle to mark the type as downloaded. |
| 1003 // See Directory::InitialSyncEndedForType |
| 1004 DCHECK(IsTypeWithClientGeneratedRoot(type)); |
| 1005 ModelNeutralMutableEntry root(trans, GET_TYPE_ROOT, type); |
| 1006 |
| 1007 // Some tests don't bother creating type root. Need to check if the root |
| 1008 // exists before clearing its base version. |
| 1009 if (root.good() && root.GetBaseVersion() == CHANGES_VERSION) { |
| 1010 root.PutBaseVersion(0); |
| 1011 } |
991 } | 1012 } |
992 | 1013 |
993 string Directory::store_birthday() const { | 1014 string Directory::store_birthday() const { |
994 ScopedKernelLock lock(this); | 1015 ScopedKernelLock lock(this); |
995 return kernel_->persisted_info.store_birthday; | 1016 return kernel_->persisted_info.store_birthday; |
996 } | 1017 } |
997 | 1018 |
998 void Directory::set_store_birthday(const string& store_birthday) { | 1019 void Directory::set_store_birthday(const string& store_birthday) { |
999 ScopedKernelLock lock(this); | 1020 ScopedKernelLock lock(this); |
1000 if (kernel_->persisted_info.store_birthday == store_birthday) | 1021 if (kernel_->persisted_info.store_birthday == store_birthday) |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 Directory::Kernel* Directory::kernel() { | 1584 Directory::Kernel* Directory::kernel() { |
1564 return kernel_; | 1585 return kernel_; |
1565 } | 1586 } |
1566 | 1587 |
1567 const Directory::Kernel* Directory::kernel() const { | 1588 const Directory::Kernel* Directory::kernel() const { |
1568 return kernel_; | 1589 return kernel_; |
1569 } | 1590 } |
1570 | 1591 |
1571 } // namespace syncable | 1592 } // namespace syncable |
1572 } // namespace syncer | 1593 } // namespace syncer |
OLD | NEW |