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

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

Issue 10837201: Pass parsed ChangeList to GDataFileSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split drive_api_parser.* part. Created 8 years, 4 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/chromeos/gdata/gdata_wapi_feed_loader.h" 5 #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 const std::string& directory_resource_id, 457 const std::string& directory_resource_id,
458 const FindEntryCallback& entry_found_callback, 458 const FindEntryCallback& entry_found_callback,
459 const LoadDocumentFeedCallback& feed_load_callback) { 459 const LoadDocumentFeedCallback& feed_load_callback) {
460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
461 461
462 // |feed_list| will contain the list of all collected feed updates that 462 // |feed_list| will contain the list of all collected feed updates that
463 // we will receive through calls of DocumentsService::GetDocuments(). 463 // we will receive through calls of DocumentsService::GetDocuments().
464 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 464 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
465 new std::vector<DocumentFeed*>); 465 new std::vector<DocumentFeed*>);
466 const base::TimeTicks start_time = base::TimeTicks::Now(); 466 const base::TimeTicks start_time = base::TimeTicks::Now();
467
468 if (gdata::util::IsDriveV2ApiEnabled()) {
469 documents_service_->GetChangelist(
470 feed_to_load,
471 start_changestamp,
472 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
473 weak_ptr_factory_.GetWeakPtr(),
474 initial_origin,
475 feed_load_callback,
476 base::Owned(new GetDocumentsParams(
477 start_changestamp,
478 root_feed_changestamp,
479 feed_list.release(),
480 should_fetch_multiple_feeds,
481 search_file_path,
482 search_query,
483 directory_resource_id,
484 entry_found_callback,
485 NULL)),
486 start_time));
487 return;
488 }
489
467 documents_service_->GetDocuments( 490 documents_service_->GetDocuments(
468 feed_to_load, 491 feed_to_load,
469 start_changestamp, 492 start_changestamp,
470 search_query, 493 search_query,
471 directory_resource_id, 494 directory_resource_id,
472 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, 495 base::Bind(&GDataWapiFeedLoader::OnGetDocuments,
473 weak_ptr_factory_.GetWeakPtr(), 496 weak_ptr_factory_.GetWeakPtr(),
474 initial_origin, 497 initial_origin,
475 feed_load_callback, 498 feed_load_callback,
476 base::Owned(new GetDocumentsParams(start_changestamp, 499 base::Owned(new GetDocumentsParams(start_changestamp,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 FOR_EACH_OBSERVER(Observer, observers_, 656 FOR_EACH_OBSERVER(Observer, observers_,
634 OnDocumentFeedFetched(num_accumulated_entries)); 657 OnDocumentFeedFetched(num_accumulated_entries));
635 658
636 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", 659 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime",
637 base::TimeTicks::Now() - start_time); 660 base::TimeTicks::Now() - start_time);
638 661
639 if (!callback.is_null()) 662 if (!callback.is_null())
640 callback.Run(params, error); 663 callback.Run(params, error);
641 } 664 }
642 665
666 void GDataWapiFeedLoader::OnGetChangelist(
667 ContentOrigin initial_origin,
668 const LoadDocumentFeedCallback& callback,
669 GetDocumentsParams* params,
670 base::TimeTicks start_time,
671 GDataErrorCode status,
672 scoped_ptr<base::Value> data) {
673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
674
675 if (params->feed_list->empty()) {
676 UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime",
677 base::TimeTicks::Now() - start_time);
678 }
679
680 GDataFileError error = util::GDataToGDataFileError(status);
681 if (error == GDATA_FILE_OK &&
682 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) {
683 error = GDATA_FILE_ERROR_FAILED;
684 }
685
686 if (error != GDATA_FILE_OK) {
687 directory_service_->set_origin(initial_origin);
688
689 if (!callback.is_null())
690 callback.Run(params, error);
691
692 return;
693 }
694
695 GURL next_feed_url;
696 scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data));
697 if (!current_feed.get()) {
698 if (!callback.is_null()) {
699 callback.Run(params, GDATA_FILE_ERROR_FAILED);
700 }
701 return;
702 }
703 const bool has_next_feed = !current_feed->next_page_token().empty();
704
705 #ifndef NDEBUG
706 // Save initial root feed for analysis.
707 std::string file_name =
708 base::StringPrintf("DEBUG_changelist_%" PRId64 ".json",
709 params->start_changestamp);
710 util::PostBlockingPoolSequencedTask(
711 FROM_HERE,
712 blocking_task_runner_,
713 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
714 cache_->GetCacheDirectoryPath(
715 GDataCache::CACHE_TYPE_META).Append(file_name),
716 base::Passed(&data)));
717 #endif
718
719 // Add the current feed to the list of collected feeds for this directory.
720 scoped_ptr<DocumentFeed> feed =
721 DocumentFeed::CreateFromChangeList(*current_feed);
722 params->feed_list->push_back(feed.release());
723
724 // Compute and notify the number of entries fetched so far.
725 int num_accumulated_entries = 0;
726 for (size_t i = 0; i < params->feed_list->size(); ++i)
727 num_accumulated_entries += params->feed_list->at(i)->entries().size();
728
729 // Notify the observers that a document feed is fetched.
730 FOR_EACH_OBSERVER(Observer, observers_,
731 OnDocumentFeedFetched(num_accumulated_entries));
732
733 // Check if we need to collect more data to complete the directory list.
734 if (params->should_fetch_multiple_feeds && has_next_feed) {
735 // Kick of the remaining part of the feeds.
736 documents_service_->GetChangelist(
737 current_feed->next_link(),
738 params->start_changestamp,
739 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
740 weak_ptr_factory_.GetWeakPtr(),
741 initial_origin,
742 callback,
743 base::Owned(
744 new GetDocumentsParams(
745 params->start_changestamp,
746 params->root_feed_changestamp,
747 params->feed_list.release(),
748 params->should_fetch_multiple_feeds,
749 params->search_file_path,
750 params->search_query,
751 params->directory_resource_id,
752 params->callback,
753 NULL)),
754 start_time));
755 return;
756 }
757
758 UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime",
759 base::TimeTicks::Now() - start_time);
760
761 if (!callback.is_null())
762 callback.Run(params, error);
763 }
satorux1 2012/08/13 17:05:43 In OnGetDocuments, OnNotifyDocumentFeedFetched() i
kochi 2012/08/14 02:09:19 Done.
764
643 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( 765 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched(
644 base::WeakPtr<GetDocumentsUiState> ui_state) { 766 base::WeakPtr<GetDocumentsUiState> ui_state) {
645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
646 768
647 if (!ui_state) { 769 if (!ui_state) {
648 // The ui state instance is already released, which means the fetching 770 // The ui state instance is already released, which means the fetching
649 // is done and we don't need to update any more. 771 // is done and we don't need to update any more.
650 return; 772 return;
651 } 773 }
652 774
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 dir_iter != changed_dirs.end(); ++dir_iter) { 943 dir_iter != changed_dirs.end(); ++dir_iter) {
822 FOR_EACH_OBSERVER(Observer, observers_, 944 FOR_EACH_OBSERVER(Observer, observers_,
823 OnDirectoryChanged(*dir_iter)); 945 OnDirectoryChanged(*dir_iter));
824 } 946 }
825 } 947 }
826 948
827 return error; 949 return error;
828 } 950 }
829 951
830 } // namespace gdata 952 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h ('k') | chrome/browser/chromeos/gdata/gdata_wapi_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698