OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/engine/directory_update_handler.h" | 5 #include "sync/engine/directory_update_handler.h" |
6 | 6 |
7 #include "sync/engine/conflict_resolver.h" | 7 #include "sync/engine/conflict_resolver.h" |
8 #include "sync/engine/process_updates_util.h" | 8 #include "sync/engine/process_updates_util.h" |
9 #include "sync/engine/update_applicator.h" | 9 #include "sync/engine/update_applicator.h" |
10 #include "sync/sessions/directory_type_debug_info_emitter.h" | 10 #include "sync/sessions/directory_type_debug_info_emitter.h" |
11 #include "sync/syncable/directory.h" | 11 #include "sync/syncable/directory.h" |
12 #include "sync/syncable/model_neutral_mutable_entry.h" | |
12 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 13 #include "sync/syncable/syncable_model_neutral_write_transaction.h" |
13 #include "sync/syncable/syncable_write_transaction.h" | 14 #include "sync/syncable/syncable_write_transaction.h" |
14 | 15 |
15 namespace syncer { | 16 namespace syncer { |
16 | 17 |
17 using syncable::SYNCER; | 18 using syncable::SYNCER; |
18 | 19 |
19 DirectoryUpdateHandler::DirectoryUpdateHandler( | 20 DirectoryUpdateHandler::DirectoryUpdateHandler( |
20 syncable::Directory* dir, | 21 syncable::Directory* dir, |
21 ModelType type, | 22 ModelType type, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // TODO(zea): trigger the datatype's UpdateDataTypeContext method. | 59 // TODO(zea): trigger the datatype's UpdateDataTypeContext method. |
59 } else if (mutated_context.version() < local_context.version()) { | 60 } else if (mutated_context.version() < local_context.version()) { |
60 // A GetUpdates using the old context was in progress when the context was | 61 // A GetUpdates using the old context was in progress when the context was |
61 // set. Fail this get updates cycle, to force a retry. | 62 // set. Fail this get updates cycle, to force a retry. |
62 DVLOG(1) << "GU Context conflict detected, forcing GU retry."; | 63 DVLOG(1) << "GU Context conflict detected, forcing GU retry."; |
63 debug_info_emitter_->EmitUpdateCountersUpdate(); | 64 debug_info_emitter_->EmitUpdateCountersUpdate(); |
64 return DATATYPE_TRIGGERED_RETRY; | 65 return DATATYPE_TRIGGERED_RETRY; |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
69 // Auto-create permanent folder for the type if the progress marker | |
70 // changes from empty to non-empty. | |
71 if (!IsTypeWithServerGeneratedRoot(type_) && | |
72 dir_->HasEmptyDownloadProgress(type_) && | |
73 !progress_marker.token().empty() && | |
74 IsValidProgressMarker(progress_marker)) { | |
Nicolas Zea
2015/01/26 23:21:53
Should IsValidProgressMarker be performing the che
stanisc
2015/01/28 07:30:05
I guess that should be OK. I'll change this.
stanisc
2015/01/29 00:27:37
Done.
| |
75 CreateTypeRoot(&trans); | |
76 } | |
77 | |
68 UpdateSyncEntities(&trans, applicable_updates, status); | 78 UpdateSyncEntities(&trans, applicable_updates, status); |
69 | 79 |
70 if (IsValidProgressMarker(progress_marker)) { | 80 if (IsValidProgressMarker(progress_marker)) { |
71 ExpireEntriesIfNeeded(&trans, progress_marker); | 81 ExpireEntriesIfNeeded(&trans, progress_marker); |
72 UpdateProgressMarker(progress_marker); | 82 UpdateProgressMarker(progress_marker); |
73 } | 83 } |
84 | |
74 debug_info_emitter_->EmitUpdateCountersUpdate(); | 85 debug_info_emitter_->EmitUpdateCountersUpdate(); |
75 return SYNCER_OK; | 86 return SYNCER_OK; |
76 } | 87 } |
77 | 88 |
89 void DirectoryUpdateHandler::CreateTypeRoot( | |
90 syncable::ModelNeutralWriteTransaction* trans) { | |
91 syncable::ModelNeutralMutableEntry entry( | |
92 trans, syncable::CREATE_NEW_TYPE_ROOT, type_); | |
93 if (!entry.good()) { | |
94 // This will fail only if matching entry already exists. | |
95 DVLOG(1) << "Type root folder " | |
Nicolas Zea
2015/01/26 23:21:53
Comment that this is expected for older versions o
stanisc
2015/01/28 07:30:05
Actually for an older version of the server this w
Nicolas Zea
2015/01/30 00:07:21
Was there a comment you meant to put here?
| |
96 << ModelTypeToRootTag(type_) | |
97 << " already exists."; | |
98 return; | |
99 } | |
100 | |
101 entry.PutServerIsDir(true); | |
102 entry.PutUniqueServerTag(ModelTypeToRootTag(type_)); | |
103 } | |
104 | |
78 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { | 105 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { |
79 if (!IsApplyUpdatesRequired()) { | 106 if (!IsApplyUpdatesRequired()) { |
80 return; | 107 return; |
81 } | 108 } |
82 | 109 |
83 // This will invoke handlers that belong to the model and its thread, so we | 110 // This will invoke handlers that belong to the model and its thread, so we |
84 // switch to the appropriate thread before we start this work. | 111 // switch to the appropriate thread before we start this work. |
85 WorkCallback c = base::Bind( | 112 WorkCallback c = base::Bind( |
86 &DirectoryUpdateHandler::ApplyUpdatesImpl, | 113 &DirectoryUpdateHandler::ApplyUpdatesImpl, |
87 // We wait until the callback is executed. We can safely use Unretained. | 114 // We wait until the callback is executed. We can safely use Unretained. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 new_gc_directive.version_watermark())) { | 279 new_gc_directive.version_watermark())) { |
253 ExpireEntriesByVersion(dir_, trans, type_, | 280 ExpireEntriesByVersion(dir_, trans, type_, |
254 new_gc_directive.version_watermark()); | 281 new_gc_directive.version_watermark()); |
255 } | 282 } |
256 | 283 |
257 cached_gc_directive_.reset( | 284 cached_gc_directive_.reset( |
258 new sync_pb::GarbageCollectionDirective(new_gc_directive)); | 285 new sync_pb::GarbageCollectionDirective(new_gc_directive)); |
259 } | 286 } |
260 | 287 |
261 } // namespace syncer | 288 } // namespace syncer |
OLD | NEW |