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

Side by Side Diff: chrome/browser/chromeos/drive/gdata_wapi_feed_loader.cc

Issue 11192027: drive: Fix computation for showing the number of fetched files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish Created 8 years, 2 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
« no previous file with comments | « no previous file | 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/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
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, or very small. This rarely happens but should be handled.
766 const int kMinIntervalMs = 10;
767 if (interval.InMilliseconds() < kMinIntervalMs)
768 interval = base::TimeDelta::FromMilliseconds(kMinIntervalMs);
769
763 base::MessageLoopProxy::current()->PostDelayedTask( 770 base::MessageLoopProxy::current()->PostDelayedTask(
764 FROM_HERE, 771 FROM_HERE,
765 base::Bind(&GDataWapiFeedLoader::OnNotifyDocumentFeedFetched, 772 base::Bind(&GDataWapiFeedLoader::OnNotifyDocumentFeedFetched,
766 weak_ptr_factory_.GetWeakPtr(), 773 weak_ptr_factory_.GetWeakPtr(),
767 ui_state->weak_ptr_factory.GetWeakPtr()), 774 ui_state->weak_ptr_factory.GetWeakPtr()),
768 remaining_duration / num_remaining_ui_updates); 775 interval);
769 } 776 }
770 } 777 }
771 } 778 }
772 779
773 void GDataWapiFeedLoader::LoadFromCache( 780 void GDataWapiFeedLoader::LoadFromCache(
774 bool should_load_from_server, 781 bool should_load_from_server,
775 const FileOperationCallback& callback) { 782 const FileOperationCallback& callback) {
776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
777 784
778 LoadRootFeedParams* params = new LoadRootFeedParams(should_load_from_server, 785 LoadRootFeedParams* params = new LoadRootFeedParams(should_load_from_server,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 dir_iter != changed_dirs.end(); ++dir_iter) { 919 dir_iter != changed_dirs.end(); ++dir_iter) {
913 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, 920 FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_,
914 OnDirectoryChanged(*dir_iter)); 921 OnDirectoryChanged(*dir_iter));
915 } 922 }
916 } 923 }
917 924
918 return error; 925 return error;
919 } 926 }
920 927
921 } // namespace drive 928 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698