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

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

Issue 11416339: Sync FileSystem: Update polling delay when remote change-list did not update change_queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years 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
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 NotifyTaskDone(status, param->token.Pass()); 1302 NotifyTaskDone(status, param->token.Pass());
1303 if (status == fileapi::SYNC_STATUS_OK) { 1303 if (status == fileapi::SYNC_STATUS_OK) {
1304 param->callback.Run(status, param->remote_change.url, 1304 param->callback.Run(status, param->remote_change.url,
1305 param->operation_type); 1305 param->operation_type);
1306 } else { 1306 } else {
1307 param->callback.Run(status, param->remote_change.url, 1307 param->callback.Run(status, param->remote_change.url,
1308 fileapi::SYNC_OPERATION_NONE); 1308 fileapi::SYNC_OPERATION_NONE);
1309 } 1309 }
1310 } 1310 }
1311 1311
1312 void DriveFileSyncService::AppendNewRemoteChange( 1312 bool DriveFileSyncService::AppendNewRemoteChange(
1313 const GURL& origin, 1313 const GURL& origin,
1314 const google_apis::DocumentEntry& entry, 1314 const google_apis::DocumentEntry& entry,
1315 int64 changestamp, 1315 int64 changestamp,
1316 RemoteSyncType sync_type) { 1316 RemoteSyncType sync_type) {
1317 // TODO(tzik): Normalize the path here. 1317 // TODO(tzik): Normalize the path here.
1318 FilePath path = FilePath::FromUTF8Unsafe(UTF16ToUTF8(entry.title())); 1318 FilePath path = FilePath::FromUTF8Unsafe(UTF16ToUTF8(entry.title()));
1319 1319
1320 PathToChange* path_to_change = &url_to_change_[origin]; 1320 PathToChange* path_to_change = &url_to_change_[origin];
1321 PathToChange::iterator found = path_to_change->find(path); 1321 PathToChange::iterator found = path_to_change->find(path);
1322 if (found != path_to_change->end()) { 1322 if (found != path_to_change->end()) {
1323 if (found->second.changestamp >= changestamp) 1323 if (found->second.changestamp >= changestamp)
1324 return; 1324 return false;
1325 pending_changes_.erase(found->second.position_in_queue); 1325 pending_changes_.erase(found->second.position_in_queue);
1326 } 1326 }
1327 1327
1328 fileapi::FileSystemURL url( 1328 fileapi::FileSystemURL url(
1329 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path)); 1329 fileapi::CreateSyncableFileSystemURL(origin, kServiceName, path));
1330 1330
1331 fileapi::FileChange::ChangeType change_type; 1331 fileapi::FileChange::ChangeType change_type;
1332 fileapi::SyncFileType file_type; 1332 fileapi::SyncFileType file_type;
1333 if (entry.deleted()) { 1333 if (entry.deleted()) {
1334 change_type = fileapi::FileChange::FILE_CHANGE_DELETE; 1334 change_type = fileapi::FileChange::FILE_CHANGE_DELETE;
1335 file_type = fileapi::SYNC_FILE_TYPE_UNKNOWN; 1335 file_type = fileapi::SYNC_FILE_TYPE_UNKNOWN;
1336 } else { 1336 } else {
1337 change_type = fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE; 1337 change_type = fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE;
1338 if (entry.is_folder()) 1338 if (entry.is_folder())
1339 file_type = fileapi::SYNC_FILE_TYPE_DIRECTORY; 1339 file_type = fileapi::SYNC_FILE_TYPE_DIRECTORY;
1340 else 1340 else
1341 file_type = fileapi::SYNC_FILE_TYPE_FILE; 1341 file_type = fileapi::SYNC_FILE_TYPE_FILE;
1342 } 1342 }
1343 1343
1344 fileapi::FileChange file_change(change_type, file_type); 1344 fileapi::FileChange file_change(change_type, file_type);
1345 1345
1346 std::pair<PendingChangeQueue::iterator, bool> inserted_to_queue = 1346 std::pair<PendingChangeQueue::iterator, bool> inserted_to_queue =
1347 pending_changes_.insert(ChangeQueueItem(changestamp, sync_type, url)); 1347 pending_changes_.insert(ChangeQueueItem(changestamp, sync_type, url));
1348 DCHECK(inserted_to_queue.second); 1348 DCHECK(inserted_to_queue.second);
1349 1349
1350 (*path_to_change)[path] = RemoteChange( 1350 (*path_to_change)[path] = RemoteChange(
1351 changestamp, entry.resource_id(), url, file_change, 1351 changestamp, entry.resource_id(), url, file_change,
1352 inserted_to_queue.first); 1352 inserted_to_queue.first);
1353 return true;
1353 } 1354 }
1354 1355
1355 void DriveFileSyncService::RemoveRemoteChange( 1356 void DriveFileSyncService::RemoveRemoteChange(
1356 const fileapi::FileSystemURL& url) { 1357 const fileapi::FileSystemURL& url) {
1357 URLToChange::iterator found_origin = url_to_change_.find(url.origin()); 1358 URLToChange::iterator found_origin = url_to_change_.find(url.origin());
1358 if (found_origin == url_to_change_.end()) 1359 if (found_origin == url_to_change_.end())
1359 return; 1360 return;
1360 1361
1361 PathToChange* path_to_change = &found_origin->second; 1362 PathToChange* path_to_change = &found_origin->second;
1362 PathToChange::iterator found_change = path_to_change->find(url.path()); 1363 PathToChange::iterator found_change = path_to_change->find(url.path());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 token->set_completion_callback(base::Bind(&EnablePolling, &polling_enabled_)); 1403 token->set_completion_callback(base::Bind(&EnablePolling, &polling_enabled_));
1403 1404
1404 if (metadata_store_->incremental_sync_origins().empty()) { 1405 if (metadata_store_->incremental_sync_origins().empty()) {
1405 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); 1406 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass());
1406 return; 1407 return;
1407 } 1408 }
1408 1409
1409 sync_client_->ListChanges( 1410 sync_client_->ListChanges(
1410 largest_fetched_changestamp_ + 1, 1411 largest_fetched_changestamp_ + 1,
1411 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync, 1412 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync,
1412 AsWeakPtr(), base::Passed(&token))); 1413 AsWeakPtr(), base::Passed(&token), false));
1413 } 1414 }
1414 1415
1415 void DriveFileSyncService::DidFetchChangesForIncrementalSync( 1416 void DriveFileSyncService::DidFetchChangesForIncrementalSync(
1416 scoped_ptr<TaskToken> token, 1417 scoped_ptr<TaskToken> token,
1418 bool has_new_changes,
1417 google_apis::GDataErrorCode error, 1419 google_apis::GDataErrorCode error,
1418 scoped_ptr<google_apis::DocumentFeed> changes) { 1420 scoped_ptr<google_apis::DocumentFeed> changes) {
1419 if (error != google_apis::HTTP_SUCCESS) { 1421 if (error != google_apis::HTTP_SUCCESS) {
1420 NotifyTaskDone(GDataErrorCodeToSyncStatusCodeWrapper(error), token.Pass()); 1422 NotifyTaskDone(GDataErrorCodeToSyncStatusCodeWrapper(error), token.Pass());
1421 return; 1423 return;
1422 } 1424 }
1423 1425
1424 typedef ScopedVector<google_apis::DocumentEntry>::const_iterator iterator; 1426 typedef ScopedVector<google_apis::DocumentEntry>::const_iterator iterator;
1425 for (iterator itr = changes->entries().begin(); 1427 for (iterator itr = changes->entries().begin();
1426 itr != changes->entries().end(); ++itr) { 1428 itr != changes->entries().end(); ++itr) {
1427 const google_apis::DocumentEntry& entry = **itr; 1429 const google_apis::DocumentEntry& entry = **itr;
1428 GURL origin; 1430 GURL origin;
1429 if (!GetOriginForEntry(entry, &origin)) 1431 if (!GetOriginForEntry(entry, &origin))
1430 continue; 1432 continue;
1431 1433
1432 AppendNewRemoteChange(origin, entry, entry.changestamp(), 1434 has_new_changes = has_new_changes ||
1433 REMOTE_SYNC_TYPE_INCREMENTAL); 1435 AppendNewRemoteChange(origin, entry, entry.changestamp(),
1436 REMOTE_SYNC_TYPE_INCREMENTAL);
1434 } 1437 }
1435 1438
1436 GURL next_feed; 1439 GURL next_feed;
1437 if (changes->GetNextFeedURL(&next_feed)) { 1440 if (changes->GetNextFeedURL(&next_feed)) {
1438 sync_client_->ContinueListing( 1441 sync_client_->ContinueListing(
1439 next_feed, 1442 next_feed,
1440 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync, 1443 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync,
1441 AsWeakPtr(), base::Passed(&token))); 1444 AsWeakPtr(), base::Passed(&token), has_new_changes));
1442 return; 1445 return;
1443 } 1446 }
1444 1447
1445 largest_fetched_changestamp_ = changes->largest_changestamp(); 1448 largest_fetched_changestamp_ = changes->largest_changestamp();
1446 1449
1447 if (changes->start_index() == 0 && changes->entries().empty()) { 1450 if (has_new_changes) {
1448 // If this set of changes is the first feed and it's empty, update 1451 polling_delay_seconds_ = kMinimumPollingDelaySeconds;
1449 // the polling delay to wait longer. 1452 } else {
1453 // If the change_queue_ was not updated, update the polling delay to wait
1454 // longer.
1450 polling_delay_seconds_ = std::min( 1455 polling_delay_seconds_ = std::min(
1451 static_cast<int64>(kDelayMultiplier * polling_delay_seconds_), 1456 static_cast<int64>(kDelayMultiplier * polling_delay_seconds_),
1452 kMaximumPollingDelaySeconds); 1457 kMaximumPollingDelaySeconds);
1453 } else {
1454 polling_delay_seconds_ = kMinimumPollingDelaySeconds;
1455 } 1458 }
1456 1459
1457 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); 1460 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass());
1458 } 1461 }
1459 1462
1460 bool DriveFileSyncService::GetOriginForEntry( 1463 bool DriveFileSyncService::GetOriginForEntry(
1461 const google_apis::DocumentEntry& entry, 1464 const google_apis::DocumentEntry& entry,
1462 GURL* origin_out) { 1465 GURL* origin_out) {
1463 typedef ScopedVector<google_apis::Link>::const_iterator iterator; 1466 typedef ScopedVector<google_apis::Link>::const_iterator iterator;
1464 for (iterator itr = entry.links().begin(); 1467 for (iterator itr = entry.links().begin();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 fileapi::SyncStatusCode 1514 fileapi::SyncStatusCode
1512 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( 1515 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper(
1513 google_apis::GDataErrorCode error) const { 1516 google_apis::GDataErrorCode error) const {
1514 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); 1517 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error);
1515 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) 1518 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated())
1516 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; 1519 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED;
1517 return status; 1520 return status;
1518 } 1521 }
1519 1522
1520 } // namespace sync_file_system 1523 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698