OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync_file_system_service.h" | 5 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const fileapi::SyncFileStatusCallback& callback) { | 191 const fileapi::SyncFileStatusCallback& callback) { |
192 DCHECK(local_file_service_); | 192 DCHECK(local_file_service_); |
193 DCHECK(remote_file_service_); | 193 DCHECK(remote_file_service_); |
194 | 194 |
195 // It's possible to get an invalid FileEntry. | 195 // It's possible to get an invalid FileEntry. |
196 if (!url.is_valid()) { | 196 if (!url.is_valid()) { |
197 base::MessageLoopProxy::current()->PostTask( | 197 base::MessageLoopProxy::current()->PostTask( |
198 FROM_HERE, | 198 FROM_HERE, |
199 base::Bind(callback, | 199 base::Bind(callback, |
200 fileapi::SYNC_FILE_ERROR_INVALID_URL, | 200 fileapi::SYNC_FILE_ERROR_INVALID_URL, |
201 fileapi::SYNC_FILE_STATUS_UNKNOWN)); | 201 SYNC_FILE_STATUS_UNKNOWN)); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 if (remote_file_service_->IsConflicting(url)) { | 205 if (remote_file_service_->IsConflicting(url)) { |
206 base::MessageLoopProxy::current()->PostTask( | 206 base::MessageLoopProxy::current()->PostTask( |
207 FROM_HERE, | 207 FROM_HERE, |
208 base::Bind(callback, | 208 base::Bind(callback, |
209 fileapi::SYNC_STATUS_OK, | 209 fileapi::SYNC_STATUS_OK, |
210 fileapi::SYNC_FILE_STATUS_CONFLICTING)); | 210 SYNC_FILE_STATUS_CONFLICTING)); |
211 return; | 211 return; |
212 } | 212 } |
213 | 213 |
214 local_file_service_->HasPendingLocalChanges( | 214 local_file_service_->HasPendingLocalChanges( |
215 url, | 215 url, |
216 base::Bind(&SyncFileSystemService::DidGetLocalChangeStatus, | 216 base::Bind(&SyncFileSystemService::DidGetLocalChangeStatus, |
217 AsWeakPtr(), callback)); | 217 AsWeakPtr(), callback)); |
218 } | 218 } |
219 | 219 |
220 void SyncFileSystemService::AddSyncEventObserver(SyncEventObserver* observer) { | 220 void SyncFileSystemService::AddSyncEventObserver(SyncEventObserver* observer) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, | 418 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, |
419 AsWeakPtr())); | 419 AsWeakPtr())); |
420 } | 420 } |
421 | 421 |
422 void SyncFileSystemService::DidGetLocalChangeStatus( | 422 void SyncFileSystemService::DidGetLocalChangeStatus( |
423 const fileapi::SyncFileStatusCallback& callback, | 423 const fileapi::SyncFileStatusCallback& callback, |
424 fileapi::SyncStatusCode status, | 424 fileapi::SyncStatusCode status, |
425 bool has_pending_local_changes) { | 425 bool has_pending_local_changes) { |
426 callback.Run( | 426 callback.Run( |
427 status, | 427 status, |
428 has_pending_local_changes ? fileapi::SYNC_FILE_STATUS_HAS_PENDING_CHANGES | 428 has_pending_local_changes ? |
429 : fileapi::SYNC_FILE_STATUS_SYNCED); | 429 SYNC_FILE_STATUS_HAS_PENDING_CHANGES : SYNC_FILE_STATUS_SYNCED); |
430 } | 430 } |
431 | 431 |
432 void SyncFileSystemService::OnSyncEnabledForRemoteSync() { | 432 void SyncFileSystemService::OnSyncEnabledForRemoteSync() { |
433 is_waiting_remote_sync_enabled_ = false; | 433 is_waiting_remote_sync_enabled_ = false; |
434 MaybeStartRemoteSync(); | 434 MaybeStartRemoteSync(); |
435 } | 435 } |
436 | 436 |
437 void SyncFileSystemService::OnLocalChangeAvailable(int64 pending_changes) { | 437 void SyncFileSystemService::OnLocalChangeAvailable(int64 pending_changes) { |
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
439 DCHECK_GE(pending_changes, 0); | 439 DCHECK_GE(pending_changes, 0); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 507 |
508 void SyncFileSystemService::OnStateChanged() { | 508 void SyncFileSystemService::OnStateChanged() { |
509 ProfileSyncServiceBase* profile_sync_service = | 509 ProfileSyncServiceBase* profile_sync_service = |
510 ProfileSyncServiceFactory::GetForProfile(profile_); | 510 ProfileSyncServiceFactory::GetForProfile(profile_); |
511 if (profile_sync_service) | 511 if (profile_sync_service) |
512 UpdateSyncEnabledStatus(profile_sync_service); | 512 UpdateSyncEnabledStatus(profile_sync_service); |
513 } | 513 } |
514 | 514 |
515 void SyncFileSystemService::OnFileStatusChanged( | 515 void SyncFileSystemService::OnFileStatusChanged( |
516 const FileSystemURL& url, | 516 const FileSystemURL& url, |
517 fileapi::SyncFileStatus sync_status, | 517 SyncFileStatus sync_status, |
518 fileapi::SyncAction action_taken, | 518 SyncAction action_taken, |
519 fileapi::SyncDirection direction) { | 519 SyncDirection direction) { |
520 FOR_EACH_OBSERVER( | 520 FOR_EACH_OBSERVER( |
521 SyncEventObserver, observers_, | 521 SyncEventObserver, observers_, |
522 OnFileSynced(url, sync_status, action_taken, direction)); | 522 OnFileSynced(url, sync_status, action_taken, direction)); |
523 } | 523 } |
524 | 524 |
525 void SyncFileSystemService::UpdateSyncEnabledStatus( | 525 void SyncFileSystemService::UpdateSyncEnabledStatus( |
526 ProfileSyncServiceBase* profile_sync_service) { | 526 ProfileSyncServiceBase* profile_sync_service) { |
527 if (!profile_sync_service->HasSyncSetupCompleted()) | 527 if (!profile_sync_service->HasSyncSetupCompleted()) |
528 return; | 528 return; |
529 sync_enabled_ = profile_sync_service->GetPreferredDataTypes().Has( | 529 sync_enabled_ = profile_sync_service->GetPreferredDataTypes().Has( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 remote_file_service = mock_remote_file_service_.Pass(); | 575 remote_file_service = mock_remote_file_service_.Pass(); |
576 else | 576 else |
577 remote_file_service.reset(new DriveFileSyncService(profile)); | 577 remote_file_service.reset(new DriveFileSyncService(profile)); |
578 | 578 |
579 service->Initialize(local_file_service.Pass(), | 579 service->Initialize(local_file_service.Pass(), |
580 remote_file_service.Pass()); | 580 remote_file_service.Pass()); |
581 return service; | 581 return service; |
582 } | 582 } |
583 | 583 |
584 } // namespace sync_file_system | 584 } // namespace sync_file_system |
OLD | NEW |