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 "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <queue> | 8 #include <queue> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 num_changes_(0) { | 87 num_changes_(0) { |
88 } | 88 } |
89 | 89 |
90 LocalFileChangeTracker::~LocalFileChangeTracker() { | 90 LocalFileChangeTracker::~LocalFileChangeTracker() { |
91 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 91 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
92 tracker_db_.reset(); | 92 tracker_db_.reset(); |
93 } | 93 } |
94 | 94 |
95 void LocalFileChangeTracker::OnStartUpdate(const FileSystemURL& url) { | 95 void LocalFileChangeTracker::OnStartUpdate(const FileSystemURL& url) { |
96 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 96 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
97 if (ContainsKey(changes_, url) || ContainsKey(demoted_changes_, url)) | 97 if (base::ContainsKey(changes_, url) || |
| 98 base::ContainsKey(demoted_changes_, url)) { |
98 return; | 99 return; |
| 100 } |
99 // TODO(nhiroki): propagate the error code (see http://crbug.com/152127). | 101 // TODO(nhiroki): propagate the error code (see http://crbug.com/152127). |
100 MarkDirtyOnDatabase(url); | 102 MarkDirtyOnDatabase(url); |
101 } | 103 } |
102 | 104 |
103 void LocalFileChangeTracker::OnEndUpdate(const FileSystemURL& url) {} | 105 void LocalFileChangeTracker::OnEndUpdate(const FileSystemURL& url) {} |
104 | 106 |
105 void LocalFileChangeTracker::OnCreateFile(const FileSystemURL& url) { | 107 void LocalFileChangeTracker::OnCreateFile(const FileSystemURL& url) { |
106 RecordChange(url, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 108 RecordChange(url, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
107 SYNC_FILE_TYPE_FILE)); | 109 SYNC_FILE_TYPE_FILE)); |
108 } | 110 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (found == changes_.end()) | 173 if (found == changes_.end()) |
172 return; | 174 return; |
173 change_seqs_.erase(found->second.change_seq); | 175 change_seqs_.erase(found->second.change_seq); |
174 changes_.erase(found); | 176 changes_.erase(found); |
175 UpdateNumChanges(); | 177 UpdateNumChanges(); |
176 } | 178 } |
177 | 179 |
178 void LocalFileChangeTracker::CreateFreshMirrorForURL( | 180 void LocalFileChangeTracker::CreateFreshMirrorForURL( |
179 const storage::FileSystemURL& url) { | 181 const storage::FileSystemURL& url) { |
180 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 182 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
181 DCHECK(!ContainsKey(mirror_changes_, url)); | 183 DCHECK(!base::ContainsKey(mirror_changes_, url)); |
182 mirror_changes_[url] = ChangeInfo(); | 184 mirror_changes_[url] = ChangeInfo(); |
183 } | 185 } |
184 | 186 |
185 void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL( | 187 void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL( |
186 const storage::FileSystemURL& url) { | 188 const storage::FileSystemURL& url) { |
187 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 189 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
188 FileChangeMap::iterator found = mirror_changes_.find(url); | 190 FileChangeMap::iterator found = mirror_changes_.find(url); |
189 if (found == mirror_changes_.end()) | 191 if (found == mirror_changes_.end()) |
190 return; | 192 return; |
191 mirror_changes_.erase(found); | 193 mirror_changes_.erase(found); |
192 | 194 |
193 if (ContainsKey(changes_, url) || ContainsKey(demoted_changes_, url)) | 195 if (base::ContainsKey(changes_, url) || |
| 196 base::ContainsKey(demoted_changes_, url)) { |
194 MarkDirtyOnDatabase(url); | 197 MarkDirtyOnDatabase(url); |
195 else | 198 } else { |
196 ClearDirtyOnDatabase(url); | 199 ClearDirtyOnDatabase(url); |
| 200 } |
197 UpdateNumChanges(); | 201 UpdateNumChanges(); |
198 } | 202 } |
199 | 203 |
200 void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL( | 204 void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL( |
201 const storage::FileSystemURL& url) { | 205 const storage::FileSystemURL& url) { |
202 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 206 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
203 FileChangeMap::iterator found = mirror_changes_.find(url); | 207 FileChangeMap::iterator found = mirror_changes_.find(url); |
204 if (found == mirror_changes_.end() || found->second.change_list.empty()) { | 208 if (found == mirror_changes_.end() || found->second.change_list.empty()) { |
205 ClearChangesForURL(url); | 209 ClearChangesForURL(url); |
206 return; | 210 return; |
207 } | 211 } |
208 const ChangeInfo& info = found->second; | 212 const ChangeInfo& info = found->second; |
209 if (ContainsKey(demoted_changes_, url)) { | 213 if (base::ContainsKey(demoted_changes_, url)) { |
210 DCHECK(!ContainsKey(changes_, url)); | 214 DCHECK(!base::ContainsKey(changes_, url)); |
211 demoted_changes_[url] = info; | 215 demoted_changes_[url] = info; |
212 } else { | 216 } else { |
213 DCHECK(!ContainsKey(demoted_changes_, url)); | 217 DCHECK(!base::ContainsKey(demoted_changes_, url)); |
214 change_seqs_[info.change_seq] = url; | 218 change_seqs_[info.change_seq] = url; |
215 changes_[url] = info; | 219 changes_[url] = info; |
216 } | 220 } |
217 RemoveMirrorAndCommitChangesForURL(url); | 221 RemoveMirrorAndCommitChangesForURL(url); |
218 } | 222 } |
219 | 223 |
220 void LocalFileChangeTracker::DemoteChangesForURL( | 224 void LocalFileChangeTracker::DemoteChangesForURL( |
221 const storage::FileSystemURL& url) { | 225 const storage::FileSystemURL& url) { |
222 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 226 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
223 | 227 |
224 FileChangeMap::iterator found = changes_.find(url); | 228 FileChangeMap::iterator found = changes_.find(url); |
225 if (found == changes_.end()) | 229 if (found == changes_.end()) |
226 return; | 230 return; |
227 DCHECK(!ContainsKey(demoted_changes_, url)); | 231 DCHECK(!base::ContainsKey(demoted_changes_, url)); |
228 change_seqs_.erase(found->second.change_seq); | 232 change_seqs_.erase(found->second.change_seq); |
229 demoted_changes_.insert(*found); | 233 demoted_changes_.insert(*found); |
230 changes_.erase(found); | 234 changes_.erase(found); |
231 UpdateNumChanges(); | 235 UpdateNumChanges(); |
232 } | 236 } |
233 | 237 |
234 void LocalFileChangeTracker::PromoteDemotedChangesForURL( | 238 void LocalFileChangeTracker::PromoteDemotedChangesForURL( |
235 const storage::FileSystemURL& url) { | 239 const storage::FileSystemURL& url) { |
236 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 240 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
237 | 241 |
238 FileChangeMap::iterator iter = demoted_changes_.find(url); | 242 FileChangeMap::iterator iter = demoted_changes_.find(url); |
239 if (iter == demoted_changes_.end()) | 243 if (iter == demoted_changes_.end()) |
240 return; | 244 return; |
241 | 245 |
242 FileChangeList::List change_list = iter->second.change_list.list(); | 246 FileChangeList::List change_list = iter->second.change_list.list(); |
243 // Make sure that this URL is in no queues. | 247 // Make sure that this URL is in no queues. |
244 DCHECK(!ContainsKey(change_seqs_, iter->second.change_seq)); | 248 DCHECK(!base::ContainsKey(change_seqs_, iter->second.change_seq)); |
245 DCHECK(!ContainsKey(changes_, url)); | 249 DCHECK(!base::ContainsKey(changes_, url)); |
246 | 250 |
247 change_seqs_[iter->second.change_seq] = url; | 251 change_seqs_[iter->second.change_seq] = url; |
248 changes_.insert(*iter); | 252 changes_.insert(*iter); |
249 demoted_changes_.erase(iter); | 253 demoted_changes_.erase(iter); |
250 UpdateNumChanges(); | 254 UpdateNumChanges(); |
251 } | 255 } |
252 | 256 |
253 bool LocalFileChangeTracker::PromoteDemotedChanges() { | 257 bool LocalFileChangeTracker::PromoteDemotedChanges() { |
254 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 258 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
255 if (demoted_changes_.empty()) | 259 if (demoted_changes_.empty()) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 break; | 414 break; |
411 } | 415 } |
412 } | 416 } |
413 return SYNC_STATUS_OK; | 417 return SYNC_STATUS_OK; |
414 } | 418 } |
415 | 419 |
416 void LocalFileChangeTracker::RecordChange( | 420 void LocalFileChangeTracker::RecordChange( |
417 const FileSystemURL& url, const FileChange& change) { | 421 const FileSystemURL& url, const FileChange& change) { |
418 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 422 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
419 int change_seq = current_change_seq_number_++; | 423 int change_seq = current_change_seq_number_++; |
420 if (ContainsKey(demoted_changes_, url)) { | 424 if (base::ContainsKey(demoted_changes_, url)) { |
421 RecordChangeToChangeMaps(url, change, change_seq, | 425 RecordChangeToChangeMaps(url, change, change_seq, |
422 &demoted_changes_, nullptr); | 426 &demoted_changes_, nullptr); |
423 } else { | 427 } else { |
424 RecordChangeToChangeMaps(url, change, change_seq, &changes_, &change_seqs_); | 428 RecordChangeToChangeMaps(url, change, change_seq, &changes_, &change_seqs_); |
425 } | 429 } |
426 if (ContainsKey(mirror_changes_, url)) { | 430 if (base::ContainsKey(mirror_changes_, url)) { |
427 RecordChangeToChangeMaps(url, change, change_seq, &mirror_changes_, | 431 RecordChangeToChangeMaps(url, change, change_seq, &mirror_changes_, |
428 nullptr); | 432 nullptr); |
429 } | 433 } |
430 UpdateNumChanges(); | 434 UpdateNumChanges(); |
431 } | 435 } |
432 | 436 |
433 // static | 437 // static |
434 void LocalFileChangeTracker::RecordChangeToChangeMaps( | 438 void LocalFileChangeTracker::RecordChangeToChangeMaps( |
435 const FileSystemURL& url, | 439 const FileSystemURL& url, |
436 const FileChange& change, | 440 const FileChange& change, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 if (!status.ok() && !status.IsNotFound()) { | 623 if (!status.ok() && !status.IsNotFound()) { |
620 HandleError(FROM_HERE, status); | 624 HandleError(FROM_HERE, status); |
621 db_status_ = LevelDBStatusToSyncStatusCode(status); | 625 db_status_ = LevelDBStatusToSyncStatusCode(status); |
622 db_.reset(); | 626 db_.reset(); |
623 return db_status_; | 627 return db_status_; |
624 } | 628 } |
625 return SYNC_STATUS_OK; | 629 return SYNC_STATUS_OK; |
626 } | 630 } |
627 | 631 |
628 } // namespace sync_file_system | 632 } // namespace sync_file_system |
OLD | NEW |