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/chromeos/drive/gdata_wapi_feed_loader.h" | 5 #include "chrome/browser/chromeos/drive/gdata_wapi_feed_loader.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( | 736 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
737 base::WeakPtr<GetDocumentsUiState> ui_state) { | 737 base::WeakPtr<GetDocumentsUiState> ui_state) { |
738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
739 | 739 |
740 if (!ui_state) { | 740 if (!ui_state) { |
741 // The ui state instance is already released, which means the fetching | 741 // The ui state instance is already released, which means the fetching |
742 // is done and we don't need to update any more. | 742 // is done and we don't need to update any more. |
743 return; | 743 return; |
744 } | 744 } |
745 | 745 |
746 base::TimeDelta elapsed_time = | 746 base::TimeDelta ui_elapsed_time = |
747 base::TimeTicks::Now() - ui_state->start_time; | 747 base::TimeTicks::Now() - ui_state->start_time; |
748 | 748 |
749 if (ui_state->num_showing_documents + kFetchUiUpdateStep <= | 749 if (ui_state->num_showing_documents + kFetchUiUpdateStep <= |
750 ui_state->num_fetched_documents) { | 750 ui_state->num_fetched_documents) { |
751 ui_state->num_showing_documents += kFetchUiUpdateStep; | 751 ui_state->num_showing_documents += kFetchUiUpdateStep; |
752 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, | 752 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, |
753 OnDocumentFeedFetched(ui_state->num_showing_documents)); | 753 OnDocumentFeedFetched(ui_state->num_showing_documents)); |
754 | 754 |
755 int num_remaining_ui_updates = | 755 int num_remaining_ui_updates = |
756 (ui_state->num_fetched_documents - ui_state->num_showing_documents) | 756 (ui_state->num_fetched_documents - ui_state->num_showing_documents) |
757 / kFetchUiUpdateStep; | 757 / kFetchUiUpdateStep; |
758 if (num_remaining_ui_updates > 0) { | 758 if (num_remaining_ui_updates > 0) { |
759 // Heuristically, we use fetched time duration to calculate the next | 759 // Heuristically, we use fetched time duration to calculate the next |
760 // UI update timing. | 760 // UI update timing. |
761 base::TimeDelta remaining_duration = | 761 base::TimeDelta remaining_duration = |
762 ui_state->feed_fetching_elapsed_time - elapsed_time; | 762 ui_state->feed_fetching_elapsed_time - ui_elapsed_time; |
763 base::TimeDelta interval = remaining_duration / num_remaining_ui_updates; | |
764 // If UI update is slow for some reason, the interval can be | |
765 // negative. This rarely happens but should be handled. | |
766 if (interval.InMilliseconds() < 0) | |
hidehiko
2012/10/17 08:39:49
10 instead of 0 may be better to keep the consiste
satorux1
2012/10/17 08:44:03
I guess "< 0" is clearer that we are dealing with
| |
767 interval = base::TimeDelta::FromMilliseconds(10); | |
768 | |
763 base::MessageLoopProxy::current()->PostDelayedTask( | 769 base::MessageLoopProxy::current()->PostDelayedTask( |
764 FROM_HERE, | 770 FROM_HERE, |
765 base::Bind(&GDataWapiFeedLoader::OnNotifyDocumentFeedFetched, | 771 base::Bind(&GDataWapiFeedLoader::OnNotifyDocumentFeedFetched, |
766 weak_ptr_factory_.GetWeakPtr(), | 772 weak_ptr_factory_.GetWeakPtr(), |
767 ui_state->weak_ptr_factory.GetWeakPtr()), | 773 ui_state->weak_ptr_factory.GetWeakPtr()), |
768 remaining_duration / num_remaining_ui_updates); | 774 interval); |
769 } | 775 } |
770 } | 776 } |
771 } | 777 } |
772 | 778 |
773 void GDataWapiFeedLoader::LoadFromCache( | 779 void GDataWapiFeedLoader::LoadFromCache( |
774 bool should_load_from_server, | 780 bool should_load_from_server, |
775 const FileOperationCallback& callback) { | 781 const FileOperationCallback& callback) { |
776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
777 | 783 |
778 LoadRootFeedParams* params = new LoadRootFeedParams(should_load_from_server, | 784 LoadRootFeedParams* params = new LoadRootFeedParams(should_load_from_server, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 dir_iter != changed_dirs.end(); ++dir_iter) { | 918 dir_iter != changed_dirs.end(); ++dir_iter) { |
913 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, | 919 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, |
914 OnDirectoryChanged(*dir_iter)); | 920 OnDirectoryChanged(*dir_iter)); |
915 } | 921 } |
916 } | 922 } |
917 | 923 |
918 return error; | 924 return error; |
919 } | 925 } |
920 | 926 |
921 } // namespace drive | 927 } // namespace drive |
OLD | NEW |