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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_change_tracker.cc

Issue 24106002: Add SNAPSHOT sync mode to LocalFileSyncContext::PrepareForSync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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 <queue> 7 #include <queue>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 DCHECK(changes); 143 DCHECK(changes);
144 changes->clear(); 144 changes->clear();
145 FileChangeMap::iterator found = changes_.find(url); 145 FileChangeMap::iterator found = changes_.find(url);
146 if (found == changes_.end()) 146 if (found == changes_.end())
147 return; 147 return;
148 *changes = found->second.change_list; 148 *changes = found->second.change_list;
149 } 149 }
150 150
151 void LocalFileChangeTracker::ClearChangesForURL(const FileSystemURL& url) { 151 void LocalFileChangeTracker::ClearChangesForURL(const FileSystemURL& url) {
152 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 152 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
153 // TODO(nhiroki): propagate the error code (see http://crbug.com/152127).
154 ClearDirtyOnDatabase(url); 153 ClearDirtyOnDatabase(url);
155 154 mirror_changes_.erase(url);
156 FileChangeMap::iterator found = changes_.find(url); 155 FileChangeMap::iterator found = changes_.find(url);
157 if (found == changes_.end()) 156 if (found == changes_.end())
158 return; 157 return;
159 change_seqs_.erase(found->second.change_seq); 158 change_seqs_.erase(found->second.change_seq);
160 changes_.erase(found); 159 changes_.erase(found);
161 UpdateNumChanges(); 160 UpdateNumChanges();
162 } 161 }
163 162
163 void LocalFileChangeTracker::CreateFreshMirrorForURL(
164 const fileapi::FileSystemURL& url) {
165 DCHECK(!ContainsKey(mirror_changes_, url));
166 mirror_changes_[url] = ChangeInfo();
167 }
168
169 void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL(
170 const fileapi::FileSystemURL& url) {
171 FileChangeMap::iterator found = mirror_changes_.find(url);
172 if (found == mirror_changes_.end())
173 return;
174 mirror_changes_.erase(found);
175
176 if (ContainsKey(changes_, url))
177 MarkDirtyOnDatabase(url);
178 else
179 ClearDirtyOnDatabase(url);
180 UpdateNumChanges();
181 }
182
183 void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL(
184 const fileapi::FileSystemURL& url) {
185 FileChangeMap::iterator found = mirror_changes_.find(url);
186 if (found == mirror_changes_.end() || found->second.change_list.empty()) {
187 ClearChangesForURL(url);
188 return;
189 }
190 const ChangeInfo& info = found->second;
191 change_seqs_[info.change_seq] = url;
192 changes_[url] = info;
193 RemoveMirrorAndCommitChangesForURL(url);
194 }
195
164 SyncStatusCode LocalFileChangeTracker::Initialize( 196 SyncStatusCode LocalFileChangeTracker::Initialize(
165 FileSystemContext* file_system_context) { 197 FileSystemContext* file_system_context) {
166 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 198 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
167 DCHECK(!initialized_); 199 DCHECK(!initialized_);
168 DCHECK(file_system_context); 200 DCHECK(file_system_context);
169 201
170 SyncStatusCode status = CollectLastDirtyChanges(file_system_context); 202 SyncStatusCode status = CollectLastDirtyChanges(file_system_context);
171 if (status == SYNC_STATUS_OK) 203 if (status == SYNC_STATUS_OK)
172 initialized_ = true; 204 initialized_ = true;
173 return status; 205 return status;
174 } 206 }
175 207
176 void LocalFileChangeTracker::UpdateNumChanges() { 208 void LocalFileChangeTracker::UpdateNumChanges() {
177 base::AutoLock lock(num_changes_lock_); 209 base::AutoLock lock(num_changes_lock_);
178 num_changes_ = static_cast<int64>(change_seqs_.size()); 210 num_changes_ = static_cast<int64>(change_seqs_.size());
179 } 211 }
180 212
181 void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) { 213 void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) {
182 std::deque<FileSystemURL> url_deque; 214 std::deque<FileSystemURL> url_deque;
183 GetNextChangedURLs(&url_deque, 0); 215 GetNextChangedURLs(&url_deque, 0);
184 urls->clear(); 216 urls->clear();
185 urls->insert(url_deque.begin(), url_deque.end()); 217 urls->insert(url_deque.begin(), url_deque.end());
186 } 218 }
187 219
188 void LocalFileChangeTracker::DropAllChanges() { 220 void LocalFileChangeTracker::DropAllChanges() {
189 changes_.clear(); 221 changes_.clear();
190 change_seqs_.clear(); 222 change_seqs_.clear();
223 mirror_changes_.clear();
191 } 224 }
192 225
193 SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase( 226 SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase(
194 const FileSystemURL& url) { 227 const FileSystemURL& url) {
195 std::string serialized_url; 228 std::string serialized_url;
196 if (!SerializeSyncableFileSystemURL(url, &serialized_url)) 229 if (!SerializeSyncableFileSystemURL(url, &serialized_url))
197 return SYNC_FILE_ERROR_INVALID_URL; 230 return SYNC_FILE_ERROR_INVALID_URL;
198 231
199 return tracker_db_->MarkDirty(serialized_url); 232 return tracker_db_->MarkDirty(serialized_url);
200 } 233 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 LOG(WARNING) << "Failed to access local file."; 304 LOG(WARNING) << "Failed to access local file.";
272 break; 305 break;
273 } 306 }
274 } 307 }
275 return SYNC_STATUS_OK; 308 return SYNC_STATUS_OK;
276 } 309 }
277 310
278 void LocalFileChangeTracker::RecordChange( 311 void LocalFileChangeTracker::RecordChange(
279 const FileSystemURL& url, const FileChange& change) { 312 const FileSystemURL& url, const FileChange& change) {
280 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 313 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
281 ChangeInfo& info = changes_[url]; 314 int change_seq = current_change_seq_++;
282 if (info.change_seq >= 0) 315 RecordChangeToChangeMaps(url, change, change_seq, &changes_, &change_seqs_);
283 change_seqs_.erase(info.change_seq); 316 if (ContainsKey(mirror_changes_, url))
284 info.change_list.Update(change); 317 RecordChangeToChangeMaps(url, change, change_seq, &mirror_changes_, NULL);
285 if (info.change_list.empty()) {
286 changes_.erase(url);
287 UpdateNumChanges();
288 return;
289 }
290 info.change_seq = current_change_seq_++;
291 change_seqs_[info.change_seq] = url;
292 UpdateNumChanges(); 318 UpdateNumChanges();
293 } 319 }
294 320
321 void LocalFileChangeTracker::RecordChangeToChangeMaps(
322 const FileSystemURL& url,
323 const FileChange& change,
324 int new_change_seq,
325 FileChangeMap* changes,
326 ChangeSeqMap* change_seqs) {
327 ChangeInfo& info = (*changes)[url];
328 if (info.change_seq >= 0 && change_seqs)
329 change_seqs->erase(info.change_seq);
330 info.change_list.Update(change);
331 if (info.change_list.empty()) {
332 changes->erase(url);
333 return;
334 }
335 info.change_seq = new_change_seq;
336 if (change_seqs)
337 (*change_seqs)[info.change_seq] = url;
338 }
339
295 // TrackerDB ------------------------------------------------------------------- 340 // TrackerDB -------------------------------------------------------------------
296 341
297 LocalFileChangeTracker::TrackerDB::TrackerDB(const base::FilePath& base_path) 342 LocalFileChangeTracker::TrackerDB::TrackerDB(const base::FilePath& base_path)
298 : base_path_(base_path), 343 : base_path_(base_path),
299 db_status_(SYNC_STATUS_OK) {} 344 db_status_(SYNC_STATUS_OK) {}
300 345
301 SyncStatusCode LocalFileChangeTracker::TrackerDB::Init( 346 SyncStatusCode LocalFileChangeTracker::TrackerDB::Init(
302 RecoveryOption recovery_option) { 347 RecoveryOption recovery_option) {
303 if (db_.get() && db_status_ == SYNC_STATUS_OK) 348 if (db_.get() && db_status_ == SYNC_STATUS_OK)
304 return SYNC_STATUS_OK; 349 return SYNC_STATUS_OK;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 db_.reset(); 465 db_.reset();
421 return db_status_; 466 return db_status_;
422 } 467 }
423 dirty_files->push(url); 468 dirty_files->push(url);
424 iter->Next(); 469 iter->Next();
425 } 470 }
426 return SYNC_STATUS_OK; 471 return SYNC_STATUS_OK;
427 } 472 }
428 473
429 } // namespace sync_file_system 474 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698