| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 base::Owned(local_metadata), | 214 base::Owned(local_metadata), |
| 215 base::Owned(remote_metadata)); | 215 base::Owned(remote_metadata)); |
| 216 scoped_refptr<SharedCallbackRunner> callback_runner( | 216 scoped_refptr<SharedCallbackRunner> callback_runner( |
| 217 new SharedCallbackRunner(completion_callback)); | 217 new SharedCallbackRunner(completion_callback)); |
| 218 local_file_service_->GetLocalFileMetadata( | 218 local_file_service_->GetLocalFileMetadata( |
| 219 url, callback_runner->CreateAssignAndRunCallback(local_metadata)); | 219 url, callback_runner->CreateAssignAndRunCallback(local_metadata)); |
| 220 remote_file_service_->GetRemoteFileMetadata( | 220 remote_file_service_->GetRemoteFileMetadata( |
| 221 url, callback_runner->CreateAssignAndRunCallback(remote_metadata)); | 221 url, callback_runner->CreateAssignAndRunCallback(remote_metadata)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void SyncFileSystemService::GetFileSyncStatus( |
| 225 const fileapi::FileSystemURL& url, |
| 226 const fileapi::SyncFileStatusCallback& callback) { |
| 227 DCHECK(local_file_service_); |
| 228 DCHECK(remote_file_service_); |
| 229 |
| 230 if (!ContainsKey(initialized_app_origins_, url.origin())) { |
| 231 base::MessageLoopProxy::current()->PostTask( |
| 232 FROM_HERE, |
| 233 base::Bind(callback, |
| 234 fileapi::SYNC_STATUS_NOT_INITIALIZED, |
| 235 fileapi::SYNC_FILE_STATUS_UNKNOWN)); |
| 236 return; |
| 237 } |
| 238 |
| 239 if (remote_file_service_->IsConflicting(url)) { |
| 240 base::MessageLoopProxy::current()->PostTask( |
| 241 FROM_HERE, |
| 242 base::Bind(callback, |
| 243 fileapi::SYNC_STATUS_OK, |
| 244 fileapi::SYNC_FILE_STATUS_CONFLICTING)); |
| 245 return; |
| 246 } |
| 247 |
| 248 local_file_service_->HasPendingLocalChanges( |
| 249 url, |
| 250 base::Bind(&SyncFileSystemService::DidGetLocalChangeStatus, |
| 251 AsWeakPtr(), callback)); |
| 252 } |
| 253 |
| 224 void SyncFileSystemService::AddSyncEventObserver(SyncEventObserver* observer) { | 254 void SyncFileSystemService::AddSyncEventObserver(SyncEventObserver* observer) { |
| 225 observers_.AddObserver(observer); | 255 observers_.AddObserver(observer); |
| 226 } | 256 } |
| 227 | 257 |
| 228 void SyncFileSystemService::RemoveSyncEventObserver( | 258 void SyncFileSystemService::RemoveSyncEventObserver( |
| 229 SyncEventObserver* observer) { | 259 SyncEventObserver* observer) { |
| 230 observers_.RemoveObserver(observer); | 260 observers_.RemoveObserver(observer); |
| 231 } | 261 } |
| 232 | 262 |
| 233 SyncFileSystemService::SyncFileSystemService(Profile* profile) | 263 SyncFileSystemService::SyncFileSystemService(Profile* profile) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 pending_local_changes_ = 0; | 408 pending_local_changes_ = 0; |
| 379 return; | 409 return; |
| 380 } else if (status == fileapi::SYNC_STATUS_HAS_CONFLICT) { | 410 } else if (status == fileapi::SYNC_STATUS_HAS_CONFLICT) { |
| 381 // TODO(kinuko,tzik): Handle conflict! | 411 // TODO(kinuko,tzik): Handle conflict! |
| 382 } | 412 } |
| 383 base::MessageLoopProxy::current()->PostTask( | 413 base::MessageLoopProxy::current()->PostTask( |
| 384 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, | 414 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, |
| 385 AsWeakPtr())); | 415 AsWeakPtr())); |
| 386 } | 416 } |
| 387 | 417 |
| 418 void SyncFileSystemService::DidGetLocalChangeStatus( |
| 419 const fileapi::SyncFileStatusCallback& callback, |
| 420 bool has_pending_local_changes) { |
| 421 callback.Run( |
| 422 fileapi::SYNC_STATUS_OK, |
| 423 has_pending_local_changes ? fileapi::SYNC_FILE_STATUS_HAS_PENDING_CHANGES |
| 424 : fileapi::SYNC_FILE_STATUS_SYNCED); |
| 425 } |
| 426 |
| 388 void SyncFileSystemService::OnSyncEnabledForRemoteSync() { | 427 void SyncFileSystemService::OnSyncEnabledForRemoteSync() { |
| 389 is_waiting_remote_sync_enabled_ = false; | 428 is_waiting_remote_sync_enabled_ = false; |
| 390 MaybeStartRemoteSync(); | 429 MaybeStartRemoteSync(); |
| 391 } | 430 } |
| 392 | 431 |
| 393 void SyncFileSystemService::OnLocalChangeAvailable(int64 pending_changes) { | 432 void SyncFileSystemService::OnLocalChangeAvailable(int64 pending_changes) { |
| 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 395 DCHECK_GE(pending_changes, 0); | 434 DCHECK_GE(pending_changes, 0); |
| 396 DVLOG(1) << "OnLocalChangeAvailable: " << pending_changes; | 435 DVLOG(1) << "OnLocalChangeAvailable: " << pending_changes; |
| 397 pending_local_changes_ = pending_changes; | 436 pending_local_changes_ = pending_changes; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 remote_file_service = mock_remote_file_service_.Pass(); | 511 remote_file_service = mock_remote_file_service_.Pass(); |
| 473 else | 512 else |
| 474 remote_file_service.reset(new DriveFileSyncService(profile)); | 513 remote_file_service.reset(new DriveFileSyncService(profile)); |
| 475 | 514 |
| 476 service->Initialize(local_file_service.Pass(), | 515 service->Initialize(local_file_service.Pass(), |
| 477 remote_file_service.Pass()); | 516 remote_file_service.Pass()); |
| 478 return service; | 517 return service; |
| 479 } | 518 } |
| 480 | 519 |
| 481 } // namespace sync_file_system | 520 } // namespace sync_file_system |
| OLD | NEW |