| 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/drive_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 const GURL& origin, | 320 const GURL& origin, |
| 321 const fileapi::SyncStatusCallback& callback) { | 321 const fileapi::SyncStatusCallback& callback) { |
| 322 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DATABASE, "")); | 322 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DATABASE, "")); |
| 323 if (!token) { | 323 if (!token) { |
| 324 pending_tasks_.push_back(base::Bind( | 324 pending_tasks_.push_back(base::Bind( |
| 325 &DriveFileSyncService::UnregisterOriginForTrackingChanges, | 325 &DriveFileSyncService::UnregisterOriginForTrackingChanges, |
| 326 AsWeakPtr(), origin, callback)); | 326 AsWeakPtr(), origin, callback)); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 URLToChange::iterator found = url_to_change_.find(origin); | 330 OriginToChangesMap::iterator found = origin_to_changes_map_.find(origin); |
| 331 if (found != url_to_change_.end()) { | 331 if (found != origin_to_changes_map_.end()) { |
| 332 for (PathToChange::iterator itr = found->second.begin(); | 332 for (PathToChangeMap::iterator itr = found->second.begin(); |
| 333 itr != found->second.end(); ++itr) | 333 itr != found->second.end(); ++itr) |
| 334 pending_changes_.erase(itr->second.position_in_queue); | 334 pending_changes_.erase(itr->second.position_in_queue); |
| 335 url_to_change_.erase(found); | 335 origin_to_changes_map_.erase(found); |
| 336 } | 336 } |
| 337 | 337 |
| 338 metadata_store_->RemoveOrigin(origin, base::Bind( | 338 metadata_store_->RemoveOrigin(origin, base::Bind( |
| 339 &DriveFileSyncService::DidRemoveOriginOnMetadataStore, | 339 &DriveFileSyncService::DidRemoveOriginOnMetadataStore, |
| 340 AsWeakPtr(), base::Passed(&token), callback)); | 340 AsWeakPtr(), base::Passed(&token), callback)); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void DriveFileSyncService::ProcessRemoteChange( | 343 void DriveFileSyncService::ProcessRemoteChange( |
| 344 RemoteChangeProcessor* processor, | 344 RemoteChangeProcessor* processor, |
| 345 const fileapi::SyncOperationCallback& callback) { | 345 const fileapi::SyncOperationCallback& callback) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 364 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 364 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 365 callback.Run(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC, | 365 callback.Run(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC, |
| 366 fileapi::FileSystemURL(), | 366 fileapi::FileSystemURL(), |
| 367 fileapi::SYNC_OPERATION_NONE); | 367 fileapi::SYNC_OPERATION_NONE); |
| 368 return; | 368 return; |
| 369 } | 369 } |
| 370 | 370 |
| 371 const fileapi::FileSystemURL& url = pending_changes_.begin()->url; | 371 const fileapi::FileSystemURL& url = pending_changes_.begin()->url; |
| 372 const GURL& origin = url.origin(); | 372 const GURL& origin = url.origin(); |
| 373 const FilePath& path = url.path(); | 373 const FilePath& path = url.path(); |
| 374 DCHECK(ContainsKey(url_to_change_, origin)); | 374 DCHECK(ContainsKey(origin_to_changes_map_, origin)); |
| 375 PathToChange* path_to_change = &url_to_change_[origin]; | 375 PathToChangeMap* path_to_change = &origin_to_changes_map_[origin]; |
| 376 DCHECK(ContainsKey(*path_to_change, path)); | 376 DCHECK(ContainsKey(*path_to_change, path)); |
| 377 const RemoteChange& remote_change = (*path_to_change)[path]; | 377 const RemoteChange& remote_change = (*path_to_change)[path]; |
| 378 | 378 |
| 379 DVLOG(1) << "ProcessRemoteChange for " << url.DebugString() | 379 DVLOG(1) << "ProcessRemoteChange for " << url.DebugString() |
| 380 << " remote_change:" << remote_change.change.DebugString(); | 380 << " remote_change:" << remote_change.change.DebugString(); |
| 381 | 381 |
| 382 scoped_ptr<ProcessRemoteChangeParam> param(new ProcessRemoteChangeParam( | 382 scoped_ptr<ProcessRemoteChangeParam> param(new ProcessRemoteChangeParam( |
| 383 token.Pass(), processor, remote_change, callback)); | 383 token.Pass(), processor, remote_change, callback)); |
| 384 processor->PrepareForProcessRemoteChange( | 384 processor->PrepareForProcessRemoteChange( |
| 385 remote_change.url, | 385 remote_change.url, |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 GURL next_feed_url; | 880 GURL next_feed_url; |
| 881 if (feed->GetNextFeedURL(&next_feed_url)) { | 881 if (feed->GetNextFeedURL(&next_feed_url)) { |
| 882 sync_client_->ContinueListing( | 882 sync_client_->ContinueListing( |
| 883 next_feed_url, | 883 next_feed_url, |
| 884 base::Bind( | 884 base::Bind( |
| 885 &DriveFileSyncService::DidGetDirectoryContentForBatchSync, | 885 &DriveFileSyncService::DidGetDirectoryContentForBatchSync, |
| 886 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); | 886 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); |
| 887 return; | 887 return; |
| 888 } | 888 } |
| 889 | 889 |
| 890 // Move |origin| to the incremental sync origin set if the origin has no file. |
| 891 if (metadata_store_->IsBatchSyncOrigin(origin) && |
| 892 !ContainsKey(origin_to_changes_map_, origin)) { |
| 893 metadata_store_->MoveBatchSyncOriginToIncremental(origin); |
| 894 } |
| 895 |
| 890 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 896 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 891 } | 897 } |
| 892 | 898 |
| 893 void DriveFileSyncService::DidRemoveOriginOnMetadataStore( | 899 void DriveFileSyncService::DidRemoveOriginOnMetadataStore( |
| 894 scoped_ptr<TaskToken> token, | 900 scoped_ptr<TaskToken> token, |
| 895 const fileapi::SyncStatusCallback& callback, | 901 const fileapi::SyncStatusCallback& callback, |
| 896 fileapi::SyncStatusCode status) { | 902 fileapi::SyncStatusCode status) { |
| 897 NotifyTaskDone(status, token.Pass()); | 903 NotifyTaskDone(status, token.Pass()); |
| 898 callback.Run(status); | 904 callback.Run(status); |
| 899 } | 905 } |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 REMOTE_SYNC_TYPE_FETCH); | 1487 REMOTE_SYNC_TYPE_FETCH); |
| 1482 } | 1488 } |
| 1483 | 1489 |
| 1484 bool DriveFileSyncService::AppendRemoteChangeInternal( | 1490 bool DriveFileSyncService::AppendRemoteChangeInternal( |
| 1485 const GURL& origin, | 1491 const GURL& origin, |
| 1486 const FilePath& path, | 1492 const FilePath& path, |
| 1487 bool is_deleted, | 1493 bool is_deleted, |
| 1488 const std::string& resource_id, | 1494 const std::string& resource_id, |
| 1489 int64 changestamp, | 1495 int64 changestamp, |
| 1490 RemoteSyncType sync_type) { | 1496 RemoteSyncType sync_type) { |
| 1491 PathToChange* path_to_change = &url_to_change_[origin]; | 1497 PathToChangeMap* path_to_change = &origin_to_changes_map_[origin]; |
| 1492 PathToChange::iterator found = path_to_change->find(path); | 1498 PathToChangeMap::iterator found = path_to_change->find(path); |
| 1493 if (found != path_to_change->end()) { | 1499 if (found != path_to_change->end()) { |
| 1494 if (found->second.changestamp >= changestamp) | 1500 if (found->second.changestamp >= changestamp) |
| 1495 return false; | 1501 return false; |
| 1496 pending_changes_.erase(found->second.position_in_queue); | 1502 pending_changes_.erase(found->second.position_in_queue); |
| 1497 } | 1503 } |
| 1498 | 1504 |
| 1499 fileapi::FileSystemURL url( | 1505 fileapi::FileSystemURL url( |
| 1500 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path)); | 1506 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path)); |
| 1501 | 1507 |
| 1502 fileapi::FileChange::ChangeType change_type; | 1508 fileapi::FileChange::ChangeType change_type; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1520 << file_change.DebugString(); | 1526 << file_change.DebugString(); |
| 1521 | 1527 |
| 1522 (*path_to_change)[path] = RemoteChange( | 1528 (*path_to_change)[path] = RemoteChange( |
| 1523 changestamp, resource_id, sync_type, url, file_change, | 1529 changestamp, resource_id, sync_type, url, file_change, |
| 1524 inserted_to_queue.first); | 1530 inserted_to_queue.first); |
| 1525 return true; | 1531 return true; |
| 1526 } | 1532 } |
| 1527 | 1533 |
| 1528 void DriveFileSyncService::RemoveRemoteChange( | 1534 void DriveFileSyncService::RemoveRemoteChange( |
| 1529 const fileapi::FileSystemURL& url) { | 1535 const fileapi::FileSystemURL& url) { |
| 1530 URLToChange::iterator found_origin = url_to_change_.find(url.origin()); | 1536 OriginToChangesMap::iterator found_origin = |
| 1531 if (found_origin == url_to_change_.end()) | 1537 origin_to_changes_map_.find(url.origin()); |
| 1538 if (found_origin == origin_to_changes_map_.end()) |
| 1532 return; | 1539 return; |
| 1533 | 1540 |
| 1534 PathToChange* path_to_change = &found_origin->second; | 1541 PathToChangeMap* path_to_change = &found_origin->second; |
| 1535 PathToChange::iterator found_change = path_to_change->find(url.path()); | 1542 PathToChangeMap::iterator found_change = path_to_change->find(url.path()); |
| 1536 if (found_change == path_to_change->end()) | 1543 if (found_change == path_to_change->end()) |
| 1537 return; | 1544 return; |
| 1538 | 1545 |
| 1539 pending_changes_.erase(found_change->second.position_in_queue); | 1546 pending_changes_.erase(found_change->second.position_in_queue); |
| 1540 path_to_change->erase(found_change); | 1547 path_to_change->erase(found_change); |
| 1541 if (path_to_change->empty()) | 1548 if (path_to_change->empty()) |
| 1542 url_to_change_.erase(found_origin); | 1549 origin_to_changes_map_.erase(found_origin); |
| 1543 | 1550 |
| 1544 if (metadata_store_->IsBatchSyncOrigin(url.origin()) && | 1551 if (metadata_store_->IsBatchSyncOrigin(url.origin()) && |
| 1545 !ContainsKey(url_to_change_, url.origin())) { | 1552 !ContainsKey(origin_to_changes_map_, url.origin())) { |
| 1546 metadata_store_->MoveBatchSyncOriginToIncremental(url.origin()); | 1553 metadata_store_->MoveBatchSyncOriginToIncremental(url.origin()); |
| 1547 } | 1554 } |
| 1548 } | 1555 } |
| 1549 | 1556 |
| 1550 bool DriveFileSyncService::GetPendingChangeForFileSystemURL( | 1557 bool DriveFileSyncService::GetPendingChangeForFileSystemURL( |
| 1551 const fileapi::FileSystemURL& url, | 1558 const fileapi::FileSystemURL& url, |
| 1552 RemoteChange* change) const { | 1559 RemoteChange* change) const { |
| 1553 DCHECK(change); | 1560 DCHECK(change); |
| 1554 URLToChange::const_iterator found_url = url_to_change_.find(url.origin()); | 1561 OriginToChangesMap::const_iterator found_url = |
| 1555 if (found_url == url_to_change_.end()) | 1562 origin_to_changes_map_.find(url.origin()); |
| 1563 if (found_url == origin_to_changes_map_.end()) |
| 1556 return false; | 1564 return false; |
| 1557 const PathToChange& path_to_change = found_url->second; | 1565 const PathToChangeMap& path_to_change = found_url->second; |
| 1558 PathToChange::const_iterator found_path = path_to_change.find(url.path()); | 1566 PathToChangeMap::const_iterator found_path = path_to_change.find(url.path()); |
| 1559 if (found_path == path_to_change.end()) | 1567 if (found_path == path_to_change.end()) |
| 1560 return false; | 1568 return false; |
| 1561 *change = found_path->second; | 1569 *change = found_path->second; |
| 1562 return true; | 1570 return true; |
| 1563 } | 1571 } |
| 1564 | 1572 |
| 1565 void DriveFileSyncService::FetchChangesForIncrementalSync() { | 1573 void DriveFileSyncService::FetchChangesForIncrementalSync() { |
| 1566 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, | 1574 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, |
| 1567 "Fetching remote change list")); | 1575 "Fetching remote change list")); |
| 1568 if (!token) { | 1576 if (!token) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 fileapi::SyncStatusCode | 1700 fileapi::SyncStatusCode |
| 1693 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( | 1701 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( |
| 1694 google_apis::GDataErrorCode error) const { | 1702 google_apis::GDataErrorCode error) const { |
| 1695 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); | 1703 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
| 1696 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) | 1704 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) |
| 1697 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; | 1705 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; |
| 1698 return status; | 1706 return status; |
| 1699 } | 1707 } |
| 1700 | 1708 |
| 1701 } // namespace sync_file_system | 1709 } // namespace sync_file_system |
| OLD | NEW |