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

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

Issue 13976019: Reland of https://codereview.chromium.org/13891016/. This includes the fix for the Segfault on Chro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase before dcommit attempt Created 7 years, 8 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 <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 28 matching lines...) Expand all
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
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
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (old_state == GetCurrentState()) 539 if (old_state == GetCurrentState())
549 return; 540 return;
550 541
551 if (!enabled) 542 if (!enabled)
552 last_operation_status_ = SYNC_STATUS_SYNC_DISABLED; 543 last_operation_status_ = SYNC_STATUS_SYNC_DISABLED;
553 544
554 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled"; 545 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled";
555 FOR_EACH_OBSERVER( 546 FOR_EACH_OBSERVER(
556 Observer, service_observers_, 547 Observer, service_observers_,
557 OnRemoteServiceStateUpdated(GetCurrentState(), status_message)); 548 OnRemoteServiceStateUpdated(GetCurrentState(), status_message));
558
559 if (GetCurrentState() == REMOTE_SERVICE_OK) {
560 UpdatePollingDelay(kMinimumPollingDelaySeconds);
561 SchedulePolling();
562 }
563 } 549 }
564 550
565 SyncStatusCode DriveFileSyncService::SetConflictResolutionPolicy( 551 SyncStatusCode DriveFileSyncService::SetConflictResolutionPolicy(
566 ConflictResolutionPolicy resolution) { 552 ConflictResolutionPolicy resolution) {
567 conflict_resolution_ = resolution; 553 conflict_resolution_ = resolution;
568 return SYNC_STATUS_OK; 554 return SYNC_STATUS_OK;
569 } 555 }
570 556
571 ConflictResolutionPolicy 557 ConflictResolutionPolicy
572 DriveFileSyncService::GetConflictResolutionPolicy() const { 558 DriveFileSyncService::GetConflictResolutionPolicy() const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 void DriveFileSyncService::OnAuthenticated() { 609 void DriveFileSyncService::OnAuthenticated() {
624 if (state_ == REMOTE_SERVICE_OK) 610 if (state_ == REMOTE_SERVICE_OK)
625 return; 611 return;
626 DVLOG(1) << "OnAuthenticated"; 612 DVLOG(1) << "OnAuthenticated";
627 state_ = REMOTE_SERVICE_OK; 613 state_ = REMOTE_SERVICE_OK;
628 if (GetCurrentState() != REMOTE_SERVICE_OK) 614 if (GetCurrentState() != REMOTE_SERVICE_OK)
629 return; 615 return;
630 FOR_EACH_OBSERVER( 616 FOR_EACH_OBSERVER(
631 Observer, service_observers_, 617 Observer, service_observers_,
632 OnRemoteServiceStateUpdated(GetCurrentState(), "Authenticated")); 618 OnRemoteServiceStateUpdated(GetCurrentState(), "Authenticated"));
633 UpdatePollingDelay(kMinimumPollingDelaySeconds);
634 619
635 may_have_unfetched_changes_ = true; 620 may_have_unfetched_changes_ = true;
636 MaybeStartFetchChanges(); 621 MaybeStartFetchChanges();
637 } 622 }
638 623
639 void DriveFileSyncService::OnNetworkConnected() { 624 void DriveFileSyncService::OnNetworkConnected() {
640 if (state_ == REMOTE_SERVICE_OK) 625 if (state_ == REMOTE_SERVICE_OK)
641 return; 626 return;
642 DVLOG(1) << "OnNetworkConnected"; 627 DVLOG(1) << "OnNetworkConnected";
643 state_ = REMOTE_SERVICE_OK; 628 state_ = REMOTE_SERVICE_OK;
644 if (GetCurrentState() != REMOTE_SERVICE_OK) 629 if (GetCurrentState() != REMOTE_SERVICE_OK)
645 return; 630 return;
646 FOR_EACH_OBSERVER( 631 FOR_EACH_OBSERVER(
647 Observer, service_observers_, 632 Observer, service_observers_,
648 OnRemoteServiceStateUpdated(GetCurrentState(), "Network connected")); 633 OnRemoteServiceStateUpdated(GetCurrentState(), "Network connected"));
649 UpdatePollingDelay(kMinimumPollingDelaySeconds);
650 634
651 may_have_unfetched_changes_ = true; 635 may_have_unfetched_changes_ = true;
652 MaybeStartFetchChanges(); 636 MaybeStartFetchChanges();
653 } 637 }
654 638
655 // Called by CreateForTesting. 639 // Called by CreateForTesting.
656 DriveFileSyncService::DriveFileSyncService( 640 DriveFileSyncService::DriveFileSyncService(
657 Profile* profile, 641 Profile* profile,
658 const base::FilePath& base_dir, 642 const base::FilePath& base_dir,
659 scoped_ptr<DriveFileSyncClientInterface> sync_client, 643 scoped_ptr<DriveFileSyncClientInterface> sync_client,
660 scoped_ptr<DriveMetadataStore> metadata_store) 644 scoped_ptr<DriveMetadataStore> metadata_store)
661 : profile_(profile), 645 : profile_(profile),
662 last_operation_status_(SYNC_STATUS_OK), 646 last_operation_status_(SYNC_STATUS_OK),
663 state_(REMOTE_SERVICE_OK), 647 state_(REMOTE_SERVICE_OK),
664 sync_enabled_(true), 648 sync_enabled_(true),
665 largest_fetched_changestamp_(0), 649 largest_fetched_changestamp_(0),
666 polling_delay_seconds_(-1),
667 may_have_unfetched_changes_(false), 650 may_have_unfetched_changes_(false),
668 remote_change_processor_(NULL), 651 remote_change_processor_(NULL),
669 conflict_resolution_(kDefaultPolicy), 652 conflict_resolution_(kDefaultPolicy),
670 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 653 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
671 DCHECK(profile); 654 DCHECK(profile);
672 temporary_file_dir_ = base_dir.Append(kTempDirName); 655 temporary_file_dir_ = base_dir.Append(kTempDirName);
673 656
674 token_.reset(new TaskToken(AsWeakPtr())); 657 token_.reset(new TaskToken(AsWeakPtr()));
675 sync_client_ = sync_client.Pass(); 658 sync_client_ = sync_client.Pass();
676 metadata_store_ = metadata_store.Pass(); 659 metadata_store_ = metadata_store.Pass();
(...skipping 30 matching lines...) Expand all
707 690
708 if (token_->task_type() != TASK_TYPE_NONE) { 691 if (token_->task_type() != TASK_TYPE_NONE) {
709 DVLOG(2) << "NotifyTaskDone: " << token_->description() 692 DVLOG(2) << "NotifyTaskDone: " << token_->description()
710 << ": finished with status=" << status 693 << ": finished with status=" << status
711 << " (" << SyncStatusCodeToString(status) << ")" 694 << " (" << SyncStatusCodeToString(status) << ")"
712 << " " << token_->location().ToString(); 695 << " " << token_->location().ToString();
713 696
714 RemoteServiceState old_state = GetCurrentState(); 697 RemoteServiceState old_state = GetCurrentState();
715 UpdateServiceState(); 698 UpdateServiceState();
716 699
717 // Reset the polling delay. This will adjust the polling timer
718 // based on the current service state.
719 UpdatePollingDelay(polling_delay_seconds_);
720
721 // Notify remote sync service state if the state has been changed. 700 // Notify remote sync service state if the state has been changed.
722 if (!token_->description().empty() || old_state != GetCurrentState()) { 701 if (!token_->description().empty() || old_state != GetCurrentState()) {
723 FOR_EACH_OBSERVER( 702 FOR_EACH_OBSERVER(
724 Observer, service_observers_, 703 Observer, service_observers_,
725 OnRemoteServiceStateUpdated(GetCurrentState(), 704 OnRemoteServiceStateUpdated(GetCurrentState(),
726 token_->done_description())); 705 token_->done_description()));
727 } 706 }
728 } 707 }
729 708
730 token_->ResetTask(FROM_HERE); 709 token_->ResetTask(FROM_HERE);
731 if (!pending_tasks_.empty()) { 710 if (!pending_tasks_.empty()) {
732 base::Closure closure = pending_tasks_.front(); 711 base::Closure closure = pending_tasks_.front();
733 pending_tasks_.pop_front(); 712 pending_tasks_.pop_front();
734 closure.Run(); 713 closure.Run();
735 return; 714 return;
736 } 715 }
737 716
738 if (GetCurrentState() == REMOTE_SERVICE_DISABLED) 717 if (GetCurrentState() == REMOTE_SERVICE_DISABLED)
739 return; 718 return;
740 719
741 MaybeStartFetchChanges(); 720 MaybeStartFetchChanges();
742 721
743 SchedulePolling();
744
745 // Notify observer of the update of |pending_changes_|. 722 // Notify observer of the update of |pending_changes_|.
746 FOR_EACH_OBSERVER(Observer, service_observers_, 723 FOR_EACH_OBSERVER(Observer, service_observers_,
747 OnRemoteChangeQueueUpdated(pending_changes_.size())); 724 OnRemoteChangeQueueUpdated(pending_changes_.size()));
748 } 725 }
749 726
750 void DriveFileSyncService::UpdateServiceState() { 727 void DriveFileSyncService::UpdateServiceState() {
751 switch (last_operation_status_) { 728 switch (last_operation_status_) {
752 // Possible regular operation errors. 729 // Possible regular operation errors.
753 case SYNC_STATUS_OK: 730 case SYNC_STATUS_OK:
754 case SYNC_STATUS_FILE_BUSY: 731 case SYNC_STATUS_FILE_BUSY:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 817 }
841 818
842 if (!sync_root_resource_id().empty()) 819 if (!sync_root_resource_id().empty())
843 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id()); 820 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id());
844 821
845 NotifyTaskDone(status, token.Pass()); 822 NotifyTaskDone(status, token.Pass());
846 may_have_unfetched_changes_ = true; 823 may_have_unfetched_changes_ = true;
847 824
848 google_apis::DriveNotificationManager* drive_notification_manager = 825 google_apis::DriveNotificationManager* drive_notification_manager =
849 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); 826 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
850 DCHECK(drive_notification_manager); 827 if (drive_notification_manager)
851 drive_notification_manager->AddObserver(this); 828 drive_notification_manager->AddObserver(this);
852 } 829 }
853 830
854 void DriveFileSyncService::UpdateRegisteredOrigins() { 831 void DriveFileSyncService::UpdateRegisteredOrigins() {
855 ExtensionService* extension_service = 832 ExtensionService* extension_service =
856 extensions::ExtensionSystem::Get(profile_)->extension_service(); 833 extensions::ExtensionSystem::Get(profile_)->extension_service();
857 if (!extension_service) 834 if (!extension_service)
858 return; 835 return;
859 836
860 std::vector<GURL> origins; 837 std::vector<GURL> origins;
861 metadata_store_->GetAllOrigins(&origins); 838 metadata_store_->GetAllOrigins(&origins);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); 981 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp));
1005 return; 982 return;
1006 } 983 }
1007 984
1008 // Move |origin| to the incremental sync origin set if the origin has no file. 985 // Move |origin| to the incremental sync origin set if the origin has no file.
1009 if (metadata_store_->IsBatchSyncOrigin(origin) && 986 if (metadata_store_->IsBatchSyncOrigin(origin) &&
1010 !ContainsKey(origin_to_changes_map_, origin)) { 987 !ContainsKey(origin_to_changes_map_, origin)) {
1011 metadata_store_->MoveBatchSyncOriginToIncremental(origin); 988 metadata_store_->MoveBatchSyncOriginToIncremental(origin);
1012 } 989 }
1013 990
1014 CheckForUpdates(); 991 may_have_unfetched_changes_ = true;
992 MaybeStartFetchChanges();
1015 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); 993 NotifyTaskDone(SYNC_STATUS_OK, token.Pass());
1016 } 994 }
1017 995
1018 void DriveFileSyncService::DidChangeOriginOnMetadataStore( 996 void DriveFileSyncService::DidChangeOriginOnMetadataStore(
1019 scoped_ptr<TaskToken> token, 997 scoped_ptr<TaskToken> token,
1020 const SyncStatusCallback& callback, 998 const SyncStatusCallback& callback,
1021 SyncStatusCode status) { 999 SyncStatusCode status) {
1022 NotifyTaskDone(status, token.Pass()); 1000 NotifyTaskDone(status, token.Pass());
1023 callback.Run(status); 1001 callback.Run(status);
1024 } 1002 }
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 } 2055 }
2078 return; 2056 return;
2079 } 2057 }
2080 2058
2081 if (may_have_unfetched_changes_ && 2059 if (may_have_unfetched_changes_ &&
2082 !metadata_store_->incremental_sync_origins().empty()) { 2060 !metadata_store_->incremental_sync_origins().empty()) {
2083 FetchChangesForIncrementalSync(); 2061 FetchChangesForIncrementalSync();
2084 } 2062 }
2085 } 2063 }
2086 2064
2087 void DriveFileSyncService::CheckForUpdates() { 2065 void DriveFileSyncService::OnNotificationReceived() {
2088 // TODO(calvinlo): Try to eliminate may_have_unfetched_changes_ variable. 2066 // TODO(calvinlo): Try to eliminate may_have_unfetched_changes_ variable.
2089 may_have_unfetched_changes_ = true; 2067 may_have_unfetched_changes_ = true;
2090 MaybeStartFetchChanges(); 2068 MaybeStartFetchChanges();
2091 } 2069 }
2092 2070
2093 void DriveFileSyncService::FetchChangesForIncrementalSync() { 2071 void DriveFileSyncService::FetchChangesForIncrementalSync() {
2094 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, 2072 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE,
2095 "Fetching remote change list")); 2073 "Fetching remote change list"));
2096 DCHECK(token); 2074 DCHECK(token);
2097 DCHECK(may_have_unfetched_changes_); 2075 DCHECK(may_have_unfetched_changes_);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 metadata_store_->SetOriginRootDirectory(*itr, std::string()); 2145 metadata_store_->SetOriginRootDirectory(*itr, std::string());
2168 } 2146 }
2169 2147
2170 GURL next_feed; 2148 GURL next_feed;
2171 if (changes->GetNextFeedURL(&next_feed)) 2149 if (changes->GetNextFeedURL(&next_feed))
2172 may_have_unfetched_changes_ = true; 2150 may_have_unfetched_changes_ = true;
2173 2151
2174 if (!changes->entries().empty()) 2152 if (!changes->entries().empty())
2175 largest_fetched_changestamp_ = changes->entries().back()->changestamp(); 2153 largest_fetched_changestamp_ = changes->entries().back()->changestamp();
2176 2154
2177 if (has_new_changes) {
2178 UpdatePollingDelay(kMinimumPollingDelaySeconds);
2179 } else {
2180 // If the change_queue_ was not updated, update the polling delay to wait
2181 // longer.
2182 UpdatePollingDelay(static_cast<int64>(
2183 kDelayMultiplier * polling_delay_seconds_));
2184 }
2185
2186 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); 2155 NotifyTaskDone(SYNC_STATUS_OK, token.Pass());
2187 } 2156 }
2188 2157
2189 bool DriveFileSyncService::GetOriginForEntry( 2158 bool DriveFileSyncService::GetOriginForEntry(
2190 const google_apis::ResourceEntry& entry, 2159 const google_apis::ResourceEntry& entry,
2191 GURL* origin_out) { 2160 GURL* origin_out) {
2192 typedef ScopedVector<google_apis::Link>::const_iterator iterator; 2161 typedef ScopedVector<google_apis::Link>::const_iterator iterator;
2193 for (iterator itr = entry.links().begin(); 2162 for (iterator itr = entry.links().begin();
2194 itr != entry.links().end(); ++itr) { 2163 itr != entry.links().end(); ++itr) {
2195 if ((*itr)->type() != google_apis::Link::LINK_PARENT) 2164 if ((*itr)->type() != google_apis::Link::LINK_PARENT)
(...skipping 11 matching lines...) Expand all
2207 if ((*itr)->href().GetOrigin() != resource_link.GetOrigin() || 2176 if ((*itr)->href().GetOrigin() != resource_link.GetOrigin() ||
2208 (*itr)->href().path() != resource_link.path()) 2177 (*itr)->href().path() != resource_link.path())
2209 continue; 2178 continue;
2210 2179
2211 *origin_out = origin; 2180 *origin_out = origin;
2212 return true; 2181 return true;
2213 } 2182 }
2214 return false; 2183 return false;
2215 } 2184 }
2216 2185
2217 void DriveFileSyncService::SchedulePolling() {
2218 if (polling_timer_.IsRunning() ||
2219 polling_delay_seconds_ < 0 ||
2220 GetCurrentState() == REMOTE_SERVICE_DISABLED)
2221 return;
2222
2223 DVLOG(1) << "Polling scheduled"
2224 << " (delay:" << polling_delay_seconds_ << "s)";
2225
2226 polling_timer_.Start(
2227 FROM_HERE, base::TimeDelta::FromSeconds(polling_delay_seconds_),
2228 base::Bind(&DriveFileSyncService::OnPollingTimerFired, AsWeakPtr()));
2229 }
2230
2231 void DriveFileSyncService::OnPollingTimerFired() {
2232 may_have_unfetched_changes_ = true;
2233 MaybeStartFetchChanges();
2234 }
2235
2236 void DriveFileSyncService::UpdatePollingDelay(int64 new_delay_sec) {
2237 // polling_delay_seconds_ made negative to disable polling for testing.
2238 if (polling_delay_seconds_ < 0)
2239 return;
2240
2241 if (state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) {
2242 // If the service state is TEMPORARY_UNAVAILABLE, poll the service
2243 // with a modest duration (but more frequently than
2244 // kPollingDelaySecondsWithNotification) so that we have a mild chance
2245 // to recover the state.
2246 polling_delay_seconds_ = kMaximumPollingDelaySeconds;
2247 polling_timer_.Stop();
2248 return;
2249 }
2250
2251 int64 old_delay = polling_delay_seconds_;
2252
2253 // Push notifications off.
2254 polling_delay_seconds_ = std::min(new_delay_sec, kMaximumPollingDelaySeconds);
2255
2256 if (polling_delay_seconds_ < old_delay)
2257 polling_timer_.Stop();
2258 }
2259
2260 void DriveFileSyncService::NotifyObserversFileStatusChanged( 2186 void DriveFileSyncService::NotifyObserversFileStatusChanged(
2261 const FileSystemURL& url, 2187 const FileSystemURL& url,
2262 SyncFileStatus sync_status, 2188 SyncFileStatus sync_status,
2263 SyncAction action_taken, 2189 SyncAction action_taken,
2264 SyncDirection direction) { 2190 SyncDirection direction) {
2265 if (sync_status != SYNC_FILE_STATUS_SYNCED) { 2191 if (sync_status != SYNC_FILE_STATUS_SYNCED) {
2266 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); 2192 DCHECK_EQ(SYNC_ACTION_NONE, action_taken);
2267 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); 2193 DCHECK_EQ(SYNC_DIRECTION_NONE, direction);
2268 } 2194 }
2269 2195
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 pending_batch_sync_origins_.insert(origin); 2262 pending_batch_sync_origins_.insert(origin);
2337 } 2263 }
2338 callback.Run(status, resource_id); 2264 callback.Run(status, resource_id);
2339 } 2265 }
2340 2266
2341 std::string DriveFileSyncService::sync_root_resource_id() { 2267 std::string DriveFileSyncService::sync_root_resource_id() {
2342 return metadata_store_->sync_root_directory(); 2268 return metadata_store_->sync_root_directory();
2343 } 2269 }
2344 2270
2345 } // namespace sync_file_system 2271 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_service.h ('k') | chrome/browser/ui/webui/chromeos/drive_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698