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

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

Issue 23578026: Use SNAPSHOT sync mode for LocalSync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on thread_bundle fix 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_sync_service.h" 5 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync_file_system/file_change.h" 11 #include "chrome/browser/sync_file_system/file_change.h"
12 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 12 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
13 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 13 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
14 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 14 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
15 #include "chrome/browser/sync_file_system/local_change_processor.h" 15 #include "chrome/browser/sync_file_system/local_change_processor.h"
16 #include "chrome/browser/sync_file_system/logger.h" 16 #include "chrome/browser/sync_file_system/logger.h"
17 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 17 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
21 #include "content/public/browser/storage_partition.h" 21 #include "content/public/browser/storage_partition.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 #include "webkit/browser/fileapi/file_system_context.h" 23 #include "webkit/browser/fileapi/file_system_context.h"
24 #include "webkit/browser/fileapi/file_system_url.h" 24 #include "webkit/browser/fileapi/file_system_url.h"
25 #include "webkit/common/blob/scoped_file.h"
25 26
26 using content::BrowserThread; 27 using content::BrowserThread;
27 using fileapi::FileSystemURL; 28 using fileapi::FileSystemURL;
28 29
29 namespace sync_file_system { 30 namespace sync_file_system {
30 31
31 namespace { 32 namespace {
32 33
33 void PrepareForProcessRemoteChangeCallbackAdapter( 34 void PrepareForProcessRemoteChangeCallbackAdapter(
34 const RemoteChangeProcessor::PrepareChangeCallback& callback, 35 const RemoteChangeProcessor::PrepareChangeCallback& callback,
35 SyncStatusCode status, 36 SyncStatusCode status,
36 const LocalFileSyncInfo& sync_file_info) { 37 const LocalFileSyncInfo& sync_file_info,
38 scoped_ptr<webkit_blob::ScopedFile> snapshot) {
37 callback.Run(status, sync_file_info.metadata, sync_file_info.changes); 39 callback.Run(status, sync_file_info.metadata, sync_file_info.changes);
38 } 40 }
39 41
40 } // namespace 42 } // namespace
41 43
42 LocalFileSyncService::OriginChangeMap::OriginChangeMap() 44 LocalFileSyncService::OriginChangeMap::OriginChangeMap()
43 : next_(change_count_map_.end()) {} 45 : next_(change_count_map_.end()) {}
44 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {} 46 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {}
45 47
46 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) { 48 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 disabled_origins_.erase(origin); 92 disabled_origins_.erase(origin);
91 else 93 else
92 disabled_origins_.insert(origin); 94 disabled_origins_.insert(origin);
93 } 95 }
94 96
95 // LocalFileSyncService ------------------------------------------------------- 97 // LocalFileSyncService -------------------------------------------------------
96 98
97 LocalFileSyncService::LocalFileSyncService(Profile* profile) 99 LocalFileSyncService::LocalFileSyncService(Profile* profile)
98 : profile_(profile), 100 : profile_(profile),
99 sync_context_(new LocalFileSyncContext( 101 sync_context_(new LocalFileSyncContext(
102 profile_->GetPath(),
100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(), 103 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(),
101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO) 104 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)
102 .get())), 105 .get())),
103 local_change_processor_(NULL) { 106 local_change_processor_(NULL) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 sync_context_->AddOriginChangeObserver(this); 108 sync_context_->AddOriginChangeObserver(this);
106 } 109 }
107 110
108 LocalFileSyncService::~LocalFileSyncService() { 111 LocalFileSyncService::~LocalFileSyncService() {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 DVLOG(1) << "Local sync is finished with: " << status 358 DVLOG(1) << "Local sync is finished with: " << status
356 << " on " << url.DebugString(); 359 << " on " << url.DebugString();
357 DCHECK(!local_sync_callback_.is_null()); 360 DCHECK(!local_sync_callback_.is_null());
358 SyncFileCallback callback = local_sync_callback_; 361 SyncFileCallback callback = local_sync_callback_;
359 local_sync_callback_.Reset(); 362 local_sync_callback_.Reset();
360 callback.Run(status, url); 363 callback.Run(status, url);
361 } 364 }
362 365
363 void LocalFileSyncService::DidGetFileForLocalSync( 366 void LocalFileSyncService::DidGetFileForLocalSync(
364 SyncStatusCode status, 367 SyncStatusCode status,
365 const LocalFileSyncInfo& sync_file_info) { 368 const LocalFileSyncInfo& sync_file_info,
369 scoped_ptr<webkit_blob::ScopedFile> snapshot) {
366 DCHECK(!local_sync_callback_.is_null()); 370 DCHECK(!local_sync_callback_.is_null());
367 if (status != SYNC_STATUS_OK) { 371 if (status != SYNC_STATUS_OK) {
368 RunLocalSyncCallback(status, sync_file_info.url); 372 RunLocalSyncCallback(status, sync_file_info.url);
369 return; 373 return;
370 } 374 }
371 if (sync_file_info.changes.empty()) { 375 if (sync_file_info.changes.empty()) {
372 // There's a slight chance this could happen. 376 // There's a slight chance this could happen.
373 SyncFileCallback callback = local_sync_callback_; 377 SyncFileCallback callback = local_sync_callback_;
374 local_sync_callback_.Reset(); 378 local_sync_callback_.Reset();
375 ProcessLocalChange(callback); 379 ProcessLocalChange(callback);
376 return; 380 return;
377 } 381 }
378 382
379 FileChange next_change = sync_file_info.changes.front(); 383 FileChange next_change = sync_file_info.changes.front();
380 DVLOG(1) << "ProcessLocalChange: " << sync_file_info.url.DebugString() 384 DVLOG(1) << "ProcessLocalChange: " << sync_file_info.url.DebugString()
381 << " change:" << next_change.DebugString(); 385 << " change:" << next_change.DebugString();
382 386
383 local_change_processor_->ApplyLocalChange( 387 local_change_processor_->ApplyLocalChange(
384 next_change, 388 next_change,
385 sync_file_info.local_file_path, 389 sync_file_info.local_file_path,
386 sync_file_info.metadata, 390 sync_file_info.metadata,
387 sync_file_info.url, 391 sync_file_info.url,
388 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL, 392 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
389 AsWeakPtr(), sync_file_info, 393 AsWeakPtr(), base::Passed(&snapshot), sync_file_info,
390 next_change, sync_file_info.changes.PopAndGetNewList())); 394 next_change, sync_file_info.changes.PopAndGetNewList()));
391 } 395 }
392 396
393 void LocalFileSyncService::ProcessNextChangeForURL( 397 void LocalFileSyncService::ProcessNextChangeForURL(
398 scoped_ptr<webkit_blob::ScopedFile> snapshot,
394 const LocalFileSyncInfo& sync_file_info, 399 const LocalFileSyncInfo& sync_file_info,
395 const FileChange& processed_change, 400 const FileChange& processed_change,
396 const FileChangeList& changes, 401 const FileChangeList& changes,
397 SyncStatusCode status) { 402 SyncStatusCode status) {
398 DVLOG(1) << "Processed one local change: " 403 DVLOG(1) << "Processed one local change: "
399 << sync_file_info.url.DebugString() 404 << sync_file_info.url.DebugString()
400 << " change:" << processed_change.DebugString() 405 << " change:" << processed_change.DebugString()
401 << " status:" << status; 406 << " status:" << status;
402 407
403 if (status == SYNC_STATUS_RETRY) { 408 if (status == SYNC_STATUS_RETRY) {
404 local_change_processor_->ApplyLocalChange( 409 local_change_processor_->ApplyLocalChange(
405 processed_change, 410 processed_change,
406 sync_file_info.local_file_path, 411 sync_file_info.local_file_path,
407 sync_file_info.metadata, 412 sync_file_info.metadata,
408 sync_file_info.url, 413 sync_file_info.url,
409 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL, 414 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
410 AsWeakPtr(), sync_file_info, processed_change, changes)); 415 AsWeakPtr(), base::Passed(&snapshot),
416 sync_file_info, processed_change, changes));
411 return; 417 return;
412 } 418 }
413 419
414 if (status == SYNC_FILE_ERROR_NOT_FOUND && 420 if (status == SYNC_FILE_ERROR_NOT_FOUND &&
415 processed_change.change() == FileChange::FILE_CHANGE_DELETE) { 421 processed_change.change() == FileChange::FILE_CHANGE_DELETE) {
416 // This must be ok (and could happen). 422 // This must be ok (and could happen).
417 status = SYNC_STATUS_OK; 423 status = SYNC_STATUS_OK;
418 } 424 }
419 425
420 const FileSystemURL& url = sync_file_info.url; 426 const FileSystemURL& url = sync_file_info.url;
421 if (status != SYNC_STATUS_OK || changes.empty()) { 427 if (status != SYNC_STATUS_OK || changes.empty()) {
422 DCHECK(ContainsKey(origin_to_contexts_, url.origin())); 428 DCHECK(ContainsKey(origin_to_contexts_, url.origin()));
423 sync_context_->CommitChangeStatusForURL( 429 sync_context_->CommitChangeStatusForURL(
424 origin_to_contexts_[url.origin()], url, status, 430 origin_to_contexts_[url.origin()], url, status,
425 base::Bind(&LocalFileSyncService::RunLocalSyncCallback, 431 base::Bind(&LocalFileSyncService::RunLocalSyncCallback,
426 AsWeakPtr(), status, url)); 432 AsWeakPtr(), status, url));
427 return; 433 return;
428 } 434 }
429 435
430 FileChange next_change = changes.front(); 436 FileChange next_change = changes.front();
431 local_change_processor_->ApplyLocalChange( 437 local_change_processor_->ApplyLocalChange(
432 changes.front(), 438 changes.front(),
433 sync_file_info.local_file_path, 439 sync_file_info.local_file_path,
434 sync_file_info.metadata, 440 sync_file_info.metadata,
435 url, 441 url,
436 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL, 442 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
437 AsWeakPtr(), sync_file_info, 443 AsWeakPtr(), base::Passed(&snapshot), sync_file_info,
438 next_change, changes.PopAndGetNewList())); 444 next_change, changes.PopAndGetNewList()));
439 } 445 }
440 446
441 } // namespace sync_file_system 447 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698