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 <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 using fileapi::FileSystemURL; | 39 using fileapi::FileSystemURL; |
40 | 40 |
41 namespace sync_file_system { | 41 namespace sync_file_system { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); | 45 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); |
46 const base::FilePath::CharType kSyncFileSystemDir[] = | 46 const base::FilePath::CharType kSyncFileSystemDir[] = |
47 FILE_PATH_LITERAL("Sync FileSystem"); | 47 FILE_PATH_LITERAL("Sync FileSystem"); |
48 | 48 |
49 // Incremental sync polling interval. | |
50 // TODO(calvinlo): Improve polling algorithm dependent on whether push | |
51 // notifications are on or off. | |
52 const int64 kMinimumPollingDelaySeconds = 5; | |
53 const int64 kMaximumPollingDelaySeconds = 10 * 60; // 10 min | |
54 const int64 kPollingDelaySecondsWithNotification = 4 * 60 * 60; // 4 hr | |
55 const double kDelayMultiplier = 1.6; | |
56 | |
57 bool CreateTemporaryFile(const base::FilePath& dir_path, | 49 bool CreateTemporaryFile(const base::FilePath& dir_path, |
58 base::FilePath* temp_file) { | 50 base::FilePath* temp_file) { |
59 return file_util::CreateDirectory(dir_path) && | 51 return file_util::CreateDirectory(dir_path) && |
60 file_util::CreateTemporaryFileInDir(dir_path, temp_file); | 52 file_util::CreateTemporaryFileInDir(dir_path, temp_file); |
61 } | 53 } |
62 | 54 |
63 void DeleteTemporaryFile(const base::FilePath& file_path) { | 55 void DeleteTemporaryFile(const base::FilePath& file_path) { |
64 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)) { | 56 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)) { |
65 content::BrowserThread::PostTask( | 57 content::BrowserThread::PostTask( |
66 content::BrowserThread::FILE, FROM_HERE, | 58 content::BrowserThread::FILE, FROM_HERE, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 return left.changestamp > right.changestamp; | 260 return left.changestamp > right.changestamp; |
269 return false; | 261 return false; |
270 } | 262 } |
271 | 263 |
272 DriveFileSyncService::DriveFileSyncService(Profile* profile) | 264 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
273 : profile_(profile), | 265 : profile_(profile), |
274 last_operation_status_(SYNC_STATUS_OK), | 266 last_operation_status_(SYNC_STATUS_OK), |
275 state_(REMOTE_SERVICE_OK), | 267 state_(REMOTE_SERVICE_OK), |
276 sync_enabled_(true), | 268 sync_enabled_(true), |
277 largest_fetched_changestamp_(0), | 269 largest_fetched_changestamp_(0), |
278 polling_delay_seconds_(kMinimumPollingDelaySeconds), | |
279 may_have_unfetched_changes_(false), | 270 may_have_unfetched_changes_(false), |
280 remote_change_processor_(NULL), | 271 remote_change_processor_(NULL), |
281 conflict_resolution_(kDefaultPolicy), | 272 conflict_resolution_(kDefaultPolicy), |
282 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 273 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
283 temporary_file_dir_ = | 274 temporary_file_dir_ = |
284 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName); | 275 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName); |
285 token_.reset(new TaskToken(AsWeakPtr())); | 276 token_.reset(new TaskToken(AsWeakPtr())); |
286 | 277 |
287 sync_client_.reset(new DriveFileSyncClient(profile)); | 278 sync_client_.reset(new DriveFileSyncClient(profile)); |
288 sync_client_->AddObserver(this); | 279 sync_client_->AddObserver(this); |
(...skipping 13 matching lines...) Expand all Loading... |
302 DriveFileSyncService::~DriveFileSyncService() { | 293 DriveFileSyncService::~DriveFileSyncService() { |
303 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we | 294 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we |
304 // can safely discard the token. | 295 // can safely discard the token. |
305 weak_factory_.InvalidateWeakPtrs(); | 296 weak_factory_.InvalidateWeakPtrs(); |
306 if (sync_client_) | 297 if (sync_client_) |
307 sync_client_->RemoveObserver(this); | 298 sync_client_->RemoveObserver(this); |
308 token_.reset(); | 299 token_.reset(); |
309 | 300 |
310 google_apis::DriveNotificationManager* drive_notification_manager = | 301 google_apis::DriveNotificationManager* drive_notification_manager = |
311 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); | 302 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); |
312 DCHECK(drive_notification_manager); | 303 if (drive_notification_manager) |
313 drive_notification_manager->RemoveObserver(this); | 304 drive_notification_manager->RemoveObserver(this); |
314 } | 305 } |
315 | 306 |
316 // static | 307 // static |
317 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 308 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
318 Profile* profile, | 309 Profile* profile, |
319 const base::FilePath& base_dir, | 310 const base::FilePath& base_dir, |
320 scoped_ptr<DriveFileSyncClientInterface> sync_client, | 311 scoped_ptr<DriveFileSyncClientInterface> sync_client, |
321 scoped_ptr<DriveMetadataStore> metadata_store) { | 312 scoped_ptr<DriveMetadataStore> metadata_store) { |
322 return make_scoped_ptr(new DriveFileSyncService( | 313 return make_scoped_ptr(new DriveFileSyncService( |
323 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); | 314 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 if (old_state == GetCurrentState()) | 552 if (old_state == GetCurrentState()) |
562 return; | 553 return; |
563 | 554 |
564 if (!enabled) | 555 if (!enabled) |
565 last_operation_status_ = SYNC_STATUS_SYNC_DISABLED; | 556 last_operation_status_ = SYNC_STATUS_SYNC_DISABLED; |
566 | 557 |
567 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled"; | 558 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled"; |
568 FOR_EACH_OBSERVER( | 559 FOR_EACH_OBSERVER( |
569 Observer, service_observers_, | 560 Observer, service_observers_, |
570 OnRemoteServiceStateUpdated(GetCurrentState(), status_message)); | 561 OnRemoteServiceStateUpdated(GetCurrentState(), status_message)); |
571 | |
572 if (GetCurrentState() == REMOTE_SERVICE_OK) { | |
573 UpdatePollingDelay(kMinimumPollingDelaySeconds); | |
574 SchedulePolling(); | |
575 } | |
576 } | 562 } |
577 | 563 |
578 SyncStatusCode DriveFileSyncService::SetConflictResolutionPolicy( | 564 SyncStatusCode DriveFileSyncService::SetConflictResolutionPolicy( |
579 ConflictResolutionPolicy resolution) { | 565 ConflictResolutionPolicy resolution) { |
580 conflict_resolution_ = resolution; | 566 conflict_resolution_ = resolution; |
581 return SYNC_STATUS_OK; | 567 return SYNC_STATUS_OK; |
582 } | 568 } |
583 | 569 |
584 ConflictResolutionPolicy | 570 ConflictResolutionPolicy |
585 DriveFileSyncService::GetConflictResolutionPolicy() const { | 571 DriveFileSyncService::GetConflictResolutionPolicy() const { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 void DriveFileSyncService::OnAuthenticated() { | 622 void DriveFileSyncService::OnAuthenticated() { |
637 if (state_ == REMOTE_SERVICE_OK) | 623 if (state_ == REMOTE_SERVICE_OK) |
638 return; | 624 return; |
639 DVLOG(1) << "OnAuthenticated"; | 625 DVLOG(1) << "OnAuthenticated"; |
640 state_ = REMOTE_SERVICE_OK; | 626 state_ = REMOTE_SERVICE_OK; |
641 if (GetCurrentState() != REMOTE_SERVICE_OK) | 627 if (GetCurrentState() != REMOTE_SERVICE_OK) |
642 return; | 628 return; |
643 FOR_EACH_OBSERVER( | 629 FOR_EACH_OBSERVER( |
644 Observer, service_observers_, | 630 Observer, service_observers_, |
645 OnRemoteServiceStateUpdated(GetCurrentState(), "Authenticated")); | 631 OnRemoteServiceStateUpdated(GetCurrentState(), "Authenticated")); |
646 UpdatePollingDelay(kMinimumPollingDelaySeconds); | |
647 | 632 |
648 may_have_unfetched_changes_ = true; | 633 may_have_unfetched_changes_ = true; |
649 MaybeStartFetchChanges(); | 634 MaybeStartFetchChanges(); |
650 } | 635 } |
651 | 636 |
652 void DriveFileSyncService::OnNetworkConnected() { | 637 void DriveFileSyncService::OnNetworkConnected() { |
653 if (state_ == REMOTE_SERVICE_OK) | 638 if (state_ == REMOTE_SERVICE_OK) |
654 return; | 639 return; |
655 DVLOG(1) << "OnNetworkConnected"; | 640 DVLOG(1) << "OnNetworkConnected"; |
656 state_ = REMOTE_SERVICE_OK; | 641 state_ = REMOTE_SERVICE_OK; |
657 if (GetCurrentState() != REMOTE_SERVICE_OK) | 642 if (GetCurrentState() != REMOTE_SERVICE_OK) |
658 return; | 643 return; |
659 FOR_EACH_OBSERVER( | 644 FOR_EACH_OBSERVER( |
660 Observer, service_observers_, | 645 Observer, service_observers_, |
661 OnRemoteServiceStateUpdated(GetCurrentState(), "Network connected")); | 646 OnRemoteServiceStateUpdated(GetCurrentState(), "Network connected")); |
662 UpdatePollingDelay(kMinimumPollingDelaySeconds); | |
663 | 647 |
664 may_have_unfetched_changes_ = true; | 648 may_have_unfetched_changes_ = true; |
665 MaybeStartFetchChanges(); | 649 MaybeStartFetchChanges(); |
666 } | 650 } |
667 | 651 |
668 // Called by CreateForTesting. | 652 // Called by CreateForTesting. |
669 DriveFileSyncService::DriveFileSyncService( | 653 DriveFileSyncService::DriveFileSyncService( |
670 Profile* profile, | 654 Profile* profile, |
671 const base::FilePath& base_dir, | 655 const base::FilePath& base_dir, |
672 scoped_ptr<DriveFileSyncClientInterface> sync_client, | 656 scoped_ptr<DriveFileSyncClientInterface> sync_client, |
673 scoped_ptr<DriveMetadataStore> metadata_store) | 657 scoped_ptr<DriveMetadataStore> metadata_store) |
674 : profile_(profile), | 658 : profile_(profile), |
675 last_operation_status_(SYNC_STATUS_OK), | 659 last_operation_status_(SYNC_STATUS_OK), |
676 state_(REMOTE_SERVICE_OK), | 660 state_(REMOTE_SERVICE_OK), |
677 sync_enabled_(true), | 661 sync_enabled_(true), |
678 largest_fetched_changestamp_(0), | 662 largest_fetched_changestamp_(0), |
679 polling_delay_seconds_(-1), | |
680 may_have_unfetched_changes_(false), | 663 may_have_unfetched_changes_(false), |
681 remote_change_processor_(NULL), | 664 remote_change_processor_(NULL), |
682 conflict_resolution_(kDefaultPolicy), | 665 conflict_resolution_(kDefaultPolicy), |
683 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 666 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
684 DCHECK(profile); | 667 DCHECK(profile); |
685 temporary_file_dir_ = base_dir.Append(kTempDirName); | 668 temporary_file_dir_ = base_dir.Append(kTempDirName); |
686 | 669 |
687 token_.reset(new TaskToken(AsWeakPtr())); | 670 token_.reset(new TaskToken(AsWeakPtr())); |
688 sync_client_ = sync_client.Pass(); | 671 sync_client_ = sync_client.Pass(); |
689 metadata_store_ = metadata_store.Pass(); | 672 metadata_store_ = metadata_store.Pass(); |
(...skipping 30 matching lines...) Expand all Loading... |
720 | 703 |
721 if (token_->task_type() != TASK_TYPE_NONE) { | 704 if (token_->task_type() != TASK_TYPE_NONE) { |
722 DVLOG(2) << "NotifyTaskDone: " << token_->description() | 705 DVLOG(2) << "NotifyTaskDone: " << token_->description() |
723 << ": finished with status=" << status | 706 << ": finished with status=" << status |
724 << " (" << SyncStatusCodeToString(status) << ")" | 707 << " (" << SyncStatusCodeToString(status) << ")" |
725 << " " << token_->location().ToString(); | 708 << " " << token_->location().ToString(); |
726 | 709 |
727 RemoteServiceState old_state = GetCurrentState(); | 710 RemoteServiceState old_state = GetCurrentState(); |
728 UpdateServiceState(); | 711 UpdateServiceState(); |
729 | 712 |
730 // Reset the polling delay. This will adjust the polling timer | |
731 // based on the current service state. | |
732 UpdatePollingDelay(polling_delay_seconds_); | |
733 | |
734 // Notify remote sync service state if the state has been changed. | 713 // Notify remote sync service state if the state has been changed. |
735 if (!token_->description().empty() || old_state != GetCurrentState()) { | 714 if (!token_->description().empty() || old_state != GetCurrentState()) { |
736 FOR_EACH_OBSERVER( | 715 FOR_EACH_OBSERVER( |
737 Observer, service_observers_, | 716 Observer, service_observers_, |
738 OnRemoteServiceStateUpdated(GetCurrentState(), | 717 OnRemoteServiceStateUpdated(GetCurrentState(), |
739 token_->done_description())); | 718 token_->done_description())); |
740 } | 719 } |
741 } | 720 } |
742 | 721 |
743 token_->ResetTask(FROM_HERE); | 722 token_->ResetTask(FROM_HERE); |
744 if (!pending_tasks_.empty()) { | 723 if (!pending_tasks_.empty()) { |
745 base::Closure closure = pending_tasks_.front(); | 724 base::Closure closure = pending_tasks_.front(); |
746 pending_tasks_.pop_front(); | 725 pending_tasks_.pop_front(); |
747 closure.Run(); | 726 closure.Run(); |
748 return; | 727 return; |
749 } | 728 } |
750 | 729 |
751 if (GetCurrentState() == REMOTE_SERVICE_DISABLED) | 730 if (GetCurrentState() == REMOTE_SERVICE_DISABLED) |
752 return; | 731 return; |
753 | 732 |
754 MaybeStartFetchChanges(); | 733 MaybeStartFetchChanges(); |
755 | 734 |
756 SchedulePolling(); | |
757 | |
758 // Notify observer of the update of |pending_changes_|. | 735 // Notify observer of the update of |pending_changes_|. |
759 FOR_EACH_OBSERVER(Observer, service_observers_, | 736 FOR_EACH_OBSERVER(Observer, service_observers_, |
760 OnRemoteChangeQueueUpdated(pending_changes_.size())); | 737 OnRemoteChangeQueueUpdated(pending_changes_.size())); |
761 } | 738 } |
762 | 739 |
763 void DriveFileSyncService::UpdateServiceState() { | 740 void DriveFileSyncService::UpdateServiceState() { |
764 switch (last_operation_status_) { | 741 switch (last_operation_status_) { |
765 // Possible regular operation errors. | 742 // Possible regular operation errors. |
766 case SYNC_STATUS_OK: | 743 case SYNC_STATUS_OK: |
767 case SYNC_STATUS_FILE_BUSY: | 744 case SYNC_STATUS_FILE_BUSY: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 } | 830 } |
854 | 831 |
855 if (!sync_root_resource_id().empty()) | 832 if (!sync_root_resource_id().empty()) |
856 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id()); | 833 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id()); |
857 | 834 |
858 NotifyTaskDone(status, token.Pass()); | 835 NotifyTaskDone(status, token.Pass()); |
859 may_have_unfetched_changes_ = true; | 836 may_have_unfetched_changes_ = true; |
860 | 837 |
861 google_apis::DriveNotificationManager* drive_notification_manager = | 838 google_apis::DriveNotificationManager* drive_notification_manager = |
862 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); | 839 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); |
863 DCHECK(drive_notification_manager); | 840 if (drive_notification_manager) |
864 drive_notification_manager->AddObserver(this); | 841 drive_notification_manager->AddObserver(this); |
865 } | 842 } |
866 | 843 |
867 void DriveFileSyncService::UpdateRegisteredOrigins() { | 844 void DriveFileSyncService::UpdateRegisteredOrigins() { |
868 ExtensionService* extension_service = | 845 ExtensionService* extension_service = |
869 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 846 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
870 if (!extension_service) | 847 if (!extension_service) |
871 return; | 848 return; |
872 | 849 |
873 std::vector<GURL> origins; | 850 std::vector<GURL> origins; |
874 metadata_store_->GetAllOrigins(&origins); | 851 metadata_store_->GetAllOrigins(&origins); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); | 994 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); |
1018 return; | 995 return; |
1019 } | 996 } |
1020 | 997 |
1021 // Move |origin| to the incremental sync origin set if the origin has no file. | 998 // Move |origin| to the incremental sync origin set if the origin has no file. |
1022 if (metadata_store_->IsBatchSyncOrigin(origin) && | 999 if (metadata_store_->IsBatchSyncOrigin(origin) && |
1023 !ContainsKey(origin_to_changes_map_, origin)) { | 1000 !ContainsKey(origin_to_changes_map_, origin)) { |
1024 metadata_store_->MoveBatchSyncOriginToIncremental(origin); | 1001 metadata_store_->MoveBatchSyncOriginToIncremental(origin); |
1025 } | 1002 } |
1026 | 1003 |
1027 CheckForUpdates(); | 1004 may_have_unfetched_changes_ = true; |
| 1005 MaybeStartFetchChanges(); |
1028 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); | 1006 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); |
1029 } | 1007 } |
1030 | 1008 |
1031 void DriveFileSyncService::DidChangeOriginOnMetadataStore( | 1009 void DriveFileSyncService::DidChangeOriginOnMetadataStore( |
1032 scoped_ptr<TaskToken> token, | 1010 scoped_ptr<TaskToken> token, |
1033 const SyncStatusCallback& callback, | 1011 const SyncStatusCallback& callback, |
1034 SyncStatusCode status) { | 1012 SyncStatusCode status) { |
1035 NotifyTaskDone(status, token.Pass()); | 1013 NotifyTaskDone(status, token.Pass()); |
1036 callback.Run(status); | 1014 callback.Run(status); |
1037 } | 1015 } |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 } | 2077 } |
2100 return; | 2078 return; |
2101 } | 2079 } |
2102 | 2080 |
2103 if (may_have_unfetched_changes_ && | 2081 if (may_have_unfetched_changes_ && |
2104 !metadata_store_->incremental_sync_origins().empty()) { | 2082 !metadata_store_->incremental_sync_origins().empty()) { |
2105 FetchChangesForIncrementalSync(); | 2083 FetchChangesForIncrementalSync(); |
2106 } | 2084 } |
2107 } | 2085 } |
2108 | 2086 |
2109 void DriveFileSyncService::CheckForUpdates() { | 2087 void DriveFileSyncService::OnNotificationReceived() { |
2110 // TODO(calvinlo): Try to eliminate may_have_unfetched_changes_ variable. | 2088 // TODO(calvinlo): Try to eliminate may_have_unfetched_changes_ variable. |
2111 may_have_unfetched_changes_ = true; | 2089 may_have_unfetched_changes_ = true; |
2112 MaybeStartFetchChanges(); | 2090 MaybeStartFetchChanges(); |
2113 } | 2091 } |
2114 | 2092 |
2115 void DriveFileSyncService::FetchChangesForIncrementalSync() { | 2093 void DriveFileSyncService::FetchChangesForIncrementalSync() { |
2116 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, | 2094 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, |
2117 "Fetching remote change list")); | 2095 "Fetching remote change list")); |
2118 DCHECK(token); | 2096 DCHECK(token); |
2119 DCHECK(may_have_unfetched_changes_); | 2097 DCHECK(may_have_unfetched_changes_); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 metadata_store_->SetOriginRootDirectory(*itr, std::string()); | 2167 metadata_store_->SetOriginRootDirectory(*itr, std::string()); |
2190 } | 2168 } |
2191 | 2169 |
2192 GURL next_feed; | 2170 GURL next_feed; |
2193 if (changes->GetNextFeedURL(&next_feed)) | 2171 if (changes->GetNextFeedURL(&next_feed)) |
2194 may_have_unfetched_changes_ = true; | 2172 may_have_unfetched_changes_ = true; |
2195 | 2173 |
2196 if (!changes->entries().empty()) | 2174 if (!changes->entries().empty()) |
2197 largest_fetched_changestamp_ = changes->entries().back()->changestamp(); | 2175 largest_fetched_changestamp_ = changes->entries().back()->changestamp(); |
2198 | 2176 |
2199 if (has_new_changes) { | |
2200 UpdatePollingDelay(kMinimumPollingDelaySeconds); | |
2201 } else { | |
2202 // If the change_queue_ was not updated, update the polling delay to wait | |
2203 // longer. | |
2204 UpdatePollingDelay(static_cast<int64>( | |
2205 kDelayMultiplier * polling_delay_seconds_)); | |
2206 } | |
2207 | |
2208 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); | 2177 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); |
2209 } | 2178 } |
2210 | 2179 |
2211 bool DriveFileSyncService::GetOriginForEntry( | 2180 bool DriveFileSyncService::GetOriginForEntry( |
2212 const google_apis::ResourceEntry& entry, | 2181 const google_apis::ResourceEntry& entry, |
2213 GURL* origin_out) { | 2182 GURL* origin_out) { |
2214 typedef ScopedVector<google_apis::Link>::const_iterator iterator; | 2183 typedef ScopedVector<google_apis::Link>::const_iterator iterator; |
2215 for (iterator itr = entry.links().begin(); | 2184 for (iterator itr = entry.links().begin(); |
2216 itr != entry.links().end(); ++itr) { | 2185 itr != entry.links().end(); ++itr) { |
2217 if ((*itr)->type() != google_apis::Link::LINK_PARENT) | 2186 if ((*itr)->type() != google_apis::Link::LINK_PARENT) |
(...skipping 11 matching lines...) Expand all Loading... |
2229 if ((*itr)->href().GetOrigin() != resource_link.GetOrigin() || | 2198 if ((*itr)->href().GetOrigin() != resource_link.GetOrigin() || |
2230 (*itr)->href().path() != resource_link.path()) | 2199 (*itr)->href().path() != resource_link.path()) |
2231 continue; | 2200 continue; |
2232 | 2201 |
2233 *origin_out = origin; | 2202 *origin_out = origin; |
2234 return true; | 2203 return true; |
2235 } | 2204 } |
2236 return false; | 2205 return false; |
2237 } | 2206 } |
2238 | 2207 |
2239 void DriveFileSyncService::SchedulePolling() { | |
2240 if (polling_timer_.IsRunning() || | |
2241 polling_delay_seconds_ < 0 || | |
2242 GetCurrentState() == REMOTE_SERVICE_DISABLED) | |
2243 return; | |
2244 | |
2245 DVLOG(1) << "Polling scheduled" | |
2246 << " (delay:" << polling_delay_seconds_ << "s)"; | |
2247 | |
2248 polling_timer_.Start( | |
2249 FROM_HERE, base::TimeDelta::FromSeconds(polling_delay_seconds_), | |
2250 base::Bind(&DriveFileSyncService::OnPollingTimerFired, AsWeakPtr())); | |
2251 } | |
2252 | |
2253 void DriveFileSyncService::OnPollingTimerFired() { | |
2254 may_have_unfetched_changes_ = true; | |
2255 MaybeStartFetchChanges(); | |
2256 } | |
2257 | |
2258 void DriveFileSyncService::UpdatePollingDelay(int64 new_delay_sec) { | |
2259 // polling_delay_seconds_ made negative to disable polling for testing. | |
2260 if (polling_delay_seconds_ < 0) | |
2261 return; | |
2262 | |
2263 if (state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) { | |
2264 // If the service state is TEMPORARY_UNAVAILABLE, poll the service | |
2265 // with a modest duration (but more frequently than | |
2266 // kPollingDelaySecondsWithNotification) so that we have a mild chance | |
2267 // to recover the state. | |
2268 polling_delay_seconds_ = kMaximumPollingDelaySeconds; | |
2269 polling_timer_.Stop(); | |
2270 return; | |
2271 } | |
2272 | |
2273 int64 old_delay = polling_delay_seconds_; | |
2274 | |
2275 // Push notifications off. | |
2276 polling_delay_seconds_ = std::min(new_delay_sec, kMaximumPollingDelaySeconds); | |
2277 | |
2278 if (polling_delay_seconds_ < old_delay) | |
2279 polling_timer_.Stop(); | |
2280 } | |
2281 | |
2282 void DriveFileSyncService::NotifyObserversFileStatusChanged( | 2208 void DriveFileSyncService::NotifyObserversFileStatusChanged( |
2283 const FileSystemURL& url, | 2209 const FileSystemURL& url, |
2284 SyncFileStatus sync_status, | 2210 SyncFileStatus sync_status, |
2285 SyncAction action_taken, | 2211 SyncAction action_taken, |
2286 SyncDirection direction) { | 2212 SyncDirection direction) { |
2287 if (sync_status != SYNC_FILE_STATUS_SYNCED) { | 2213 if (sync_status != SYNC_FILE_STATUS_SYNCED) { |
2288 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); | 2214 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); |
2289 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); | 2215 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); |
2290 } | 2216 } |
2291 | 2217 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2358 pending_batch_sync_origins_.insert(origin); | 2284 pending_batch_sync_origins_.insert(origin); |
2359 } | 2285 } |
2360 callback.Run(status, resource_id); | 2286 callback.Run(status, resource_id); |
2361 } | 2287 } |
2362 | 2288 |
2363 std::string DriveFileSyncService::sync_root_resource_id() { | 2289 std::string DriveFileSyncService::sync_root_resource_id() { |
2364 return metadata_store_->sync_root_directory(); | 2290 return metadata_store_->sync_root_directory(); |
2365 } | 2291 } |
2366 | 2292 |
2367 } // namespace sync_file_system | 2293 } // namespace sync_file_system |
OLD | NEW |