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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service.cc

Issue 11665029: Sync FileSystem: Mark empty batch sync origin as incremental sync origin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert android exclusion Created 7 years, 11 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 (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
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
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
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 if (metadata_store_->IsBatchSyncOrigin(origin) &&
kinuko 2013/01/07 09:28:31 nit: can you add a brief comment like: 'Move the o
tzik 2013/01/07 11:16:14 Done.
891 !ContainsKey(origin_to_changes_map_, origin)) {
892 metadata_store_->MoveBatchSyncOriginToIncremental(origin);
893 }
894
890 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); 895 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass());
891 } 896 }
892 897
893 void DriveFileSyncService::DidRemoveOriginOnMetadataStore( 898 void DriveFileSyncService::DidRemoveOriginOnMetadataStore(
894 scoped_ptr<TaskToken> token, 899 scoped_ptr<TaskToken> token,
895 const fileapi::SyncStatusCallback& callback, 900 const fileapi::SyncStatusCallback& callback,
896 fileapi::SyncStatusCode status) { 901 fileapi::SyncStatusCode status) {
897 NotifyTaskDone(status, token.Pass()); 902 NotifyTaskDone(status, token.Pass());
898 callback.Run(status); 903 callback.Run(status);
899 } 904 }
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 REMOTE_SYNC_TYPE_FETCH); 1486 REMOTE_SYNC_TYPE_FETCH);
1482 } 1487 }
1483 1488
1484 bool DriveFileSyncService::AppendRemoteChangeInternal( 1489 bool DriveFileSyncService::AppendRemoteChangeInternal(
1485 const GURL& origin, 1490 const GURL& origin,
1486 const FilePath& path, 1491 const FilePath& path,
1487 bool is_deleted, 1492 bool is_deleted,
1488 const std::string& resource_id, 1493 const std::string& resource_id,
1489 int64 changestamp, 1494 int64 changestamp,
1490 RemoteSyncType sync_type) { 1495 RemoteSyncType sync_type) {
1491 PathToChange* path_to_change = &url_to_change_[origin]; 1496 PathToChangeMap* path_to_change = &origin_to_changes_map_[origin];
1492 PathToChange::iterator found = path_to_change->find(path); 1497 PathToChangeMap::iterator found = path_to_change->find(path);
1493 if (found != path_to_change->end()) { 1498 if (found != path_to_change->end()) {
1494 if (found->second.changestamp >= changestamp) 1499 if (found->second.changestamp >= changestamp)
1495 return false; 1500 return false;
1496 pending_changes_.erase(found->second.position_in_queue); 1501 pending_changes_.erase(found->second.position_in_queue);
1497 } 1502 }
1498 1503
1499 fileapi::FileSystemURL url( 1504 fileapi::FileSystemURL url(
1500 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path)); 1505 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path));
1501 1506
1502 fileapi::FileChange::ChangeType change_type; 1507 fileapi::FileChange::ChangeType change_type;
(...skipping 17 matching lines...) Expand all
1520 << file_change.DebugString(); 1525 << file_change.DebugString();
1521 1526
1522 (*path_to_change)[path] = RemoteChange( 1527 (*path_to_change)[path] = RemoteChange(
1523 changestamp, resource_id, sync_type, url, file_change, 1528 changestamp, resource_id, sync_type, url, file_change,
1524 inserted_to_queue.first); 1529 inserted_to_queue.first);
1525 return true; 1530 return true;
1526 } 1531 }
1527 1532
1528 void DriveFileSyncService::RemoveRemoteChange( 1533 void DriveFileSyncService::RemoveRemoteChange(
1529 const fileapi::FileSystemURL& url) { 1534 const fileapi::FileSystemURL& url) {
1530 URLToChange::iterator found_origin = url_to_change_.find(url.origin()); 1535 OriginToChangesMap::iterator found_origin =
1531 if (found_origin == url_to_change_.end()) 1536 origin_to_changes_map_.find(url.origin());
1537 if (found_origin == origin_to_changes_map_.end())
1532 return; 1538 return;
1533 1539
1534 PathToChange* path_to_change = &found_origin->second; 1540 PathToChangeMap* path_to_change = &found_origin->second;
1535 PathToChange::iterator found_change = path_to_change->find(url.path()); 1541 PathToChangeMap::iterator found_change = path_to_change->find(url.path());
1536 if (found_change == path_to_change->end()) 1542 if (found_change == path_to_change->end())
1537 return; 1543 return;
1538 1544
1539 pending_changes_.erase(found_change->second.position_in_queue); 1545 pending_changes_.erase(found_change->second.position_in_queue);
1540 path_to_change->erase(found_change); 1546 path_to_change->erase(found_change);
1541 if (path_to_change->empty()) 1547 if (path_to_change->empty())
1542 url_to_change_.erase(found_origin); 1548 origin_to_changes_map_.erase(found_origin);
1543 1549
1544 if (metadata_store_->IsBatchSyncOrigin(url.origin()) && 1550 if (metadata_store_->IsBatchSyncOrigin(url.origin()) &&
1545 !ContainsKey(url_to_change_, url.origin())) { 1551 !ContainsKey(origin_to_changes_map_, url.origin())) {
1546 metadata_store_->MoveBatchSyncOriginToIncremental(url.origin()); 1552 metadata_store_->MoveBatchSyncOriginToIncremental(url.origin());
1547 } 1553 }
1548 } 1554 }
1549 1555
1550 bool DriveFileSyncService::GetPendingChangeForFileSystemURL( 1556 bool DriveFileSyncService::GetPendingChangeForFileSystemURL(
1551 const fileapi::FileSystemURL& url, 1557 const fileapi::FileSystemURL& url,
1552 RemoteChange* change) const { 1558 RemoteChange* change) const {
1553 DCHECK(change); 1559 DCHECK(change);
1554 URLToChange::const_iterator found_url = url_to_change_.find(url.origin()); 1560 OriginToChangesMap::const_iterator found_url =
1555 if (found_url == url_to_change_.end()) 1561 origin_to_changes_map_.find(url.origin());
1562 if (found_url == origin_to_changes_map_.end())
1556 return false; 1563 return false;
1557 const PathToChange& path_to_change = found_url->second; 1564 const PathToChangeMap& path_to_change = found_url->second;
1558 PathToChange::const_iterator found_path = path_to_change.find(url.path()); 1565 PathToChangeMap::const_iterator found_path = path_to_change.find(url.path());
1559 if (found_path == path_to_change.end()) 1566 if (found_path == path_to_change.end())
1560 return false; 1567 return false;
1561 *change = found_path->second; 1568 *change = found_path->second;
1562 return true; 1569 return true;
1563 } 1570 }
1564 1571
1565 void DriveFileSyncService::FetchChangesForIncrementalSync() { 1572 void DriveFileSyncService::FetchChangesForIncrementalSync() {
1566 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, 1573 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE,
1567 "Fetching remote change list")); 1574 "Fetching remote change list"));
1568 if (!token) { 1575 if (!token) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 fileapi::SyncStatusCode 1699 fileapi::SyncStatusCode
1693 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( 1700 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper(
1694 google_apis::GDataErrorCode error) const { 1701 google_apis::GDataErrorCode error) const {
1695 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); 1702 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error);
1696 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) 1703 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated())
1697 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; 1704 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED;
1698 return status; 1705 return status;
1699 } 1706 }
1700 1707
1701 } // namespace sync_file_system 1708 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698