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

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: . 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 int64 start_changestamp, 436 int64 start_changestamp,
437 int64 root_feed_changestamp, 437 int64 root_feed_changestamp,
438 bool should_fetch_multiple_feeds, 438 bool should_fetch_multiple_feeds,
439 const FilePath& search_file_path, 439 const FilePath& search_file_path,
440 const std::string& search_query, 440 const std::string& search_query,
441 const GURL& feed_to_load, 441 const GURL& feed_to_load,
442 const std::string& directory_resource_id, 442 const std::string& directory_resource_id,
443 const FindEntryCallback& entry_found_callback, 443 const FindEntryCallback& entry_found_callback,
444 const LoadDocumentFeedCallback& feed_load_callback) { 444 const LoadDocumentFeedCallback& feed_load_callback) {
445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
446 DVLOG(1) << "LoadFeedFromServer";
satorux1 2012/08/10 18:14:34 remove this?
kochi 2012/08/13 09:08:39 Done.
446 447
447 // |feed_list| will contain the list of all collected feed updates that 448 // |feed_list| will contain the list of all collected feed updates that
448 // we will receive through calls of DocumentsService::GetDocuments(). 449 // we will receive through calls of DocumentsService::GetDocuments().
449 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 450 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
450 new std::vector<DocumentFeed*>); 451 new std::vector<DocumentFeed*>);
451 const base::TimeTicks start_time = base::TimeTicks::Now(); 452 const base::TimeTicks start_time = base::TimeTicks::Now();
453
454 if (gdata::util::IsDriveV2ApiEnabled()) {
455 documents_service_->GetChangelist(
456 feed_to_load,
457 start_changestamp,
458 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
459 weak_ptr_factory_.GetWeakPtr(),
460 initial_origin,
461 feed_load_callback,
462 base::Owned(new GetDocumentsParams(
463 start_changestamp,
464 root_feed_changestamp,
465 feed_list.release(),
466 should_fetch_multiple_feeds,
467 search_file_path,
468 search_query,
469 directory_resource_id,
470 entry_found_callback,
471 NULL)),
472 start_time));
473 return;
474 }
475
452 documents_service_->GetDocuments( 476 documents_service_->GetDocuments(
453 feed_to_load, 477 feed_to_load,
454 start_changestamp, 478 start_changestamp,
455 search_query, 479 search_query,
456 directory_resource_id, 480 directory_resource_id,
457 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, 481 base::Bind(&GDataWapiFeedLoader::OnGetDocuments,
458 weak_ptr_factory_.GetWeakPtr(), 482 weak_ptr_factory_.GetWeakPtr(),
459 initial_origin, 483 initial_origin,
460 feed_load_callback, 484 feed_load_callback,
461 base::Owned(new GetDocumentsParams(start_changestamp, 485 base::Owned(new GetDocumentsParams(start_changestamp,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 FOR_EACH_OBSERVER(Observer, observers_, 642 FOR_EACH_OBSERVER(Observer, observers_,
619 OnDocumentFeedFetched(num_accumulated_entries)); 643 OnDocumentFeedFetched(num_accumulated_entries));
620 644
621 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", 645 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime",
622 base::TimeTicks::Now() - start_time); 646 base::TimeTicks::Now() - start_time);
623 647
624 if (!callback.is_null()) 648 if (!callback.is_null())
625 callback.Run(params, error); 649 callback.Run(params, error);
626 } 650 }
627 651
652 void GDataWapiFeedLoader::OnGetChangelist(
653 ContentOrigin initial_origin,
654 const LoadDocumentFeedCallback& callback,
655 GetDocumentsParams* params,
656 base::TimeTicks start_time,
657 GDataErrorCode status,
658 scoped_ptr<base::Value> data) {
659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
660
661 if (params->feed_list->empty()) {
662 UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime",
663 base::TimeTicks::Now() - start_time);
664 }
665
666 GDataFileError error = util::GDataToGDataFileError(status);
667 if (error == GDATA_FILE_OK &&
668 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) {
669 error = GDATA_FILE_ERROR_FAILED;
670 }
671
672 if (error != GDATA_FILE_OK) {
673 directory_service_->set_origin(initial_origin);
674
675 if (!callback.is_null())
676 callback.Run(params, error);
677
678 return;
679 }
680
681 GURL next_feed_url;
682 scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data));
683 if (!current_feed.get()) {
684 if (!callback.is_null()) {
685 callback.Run(params, GDATA_FILE_ERROR_FAILED);
686 }
687 return;
688 }
689 const bool has_next_feed = !current_feed->next_page_token().empty();
690
691 #ifndef NDEBUG
692 // Save initial root feed for analysis.
693 std::string file_name =
694 base::StringPrintf("DEBUG_changelist_%ld.json",
695 params->start_changestamp);
696 util::PostBlockingPoolSequencedTask(
697 FROM_HERE,
698 blocking_task_runner_,
699 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
700 cache_->GetCacheDirectoryPath(
701 GDataCache::CACHE_TYPE_META).Append(file_name),
702 base::Passed(&data)));
703 #endif
704
705 // Add the current feed to the list of collected feeds for this directory.
706 scoped_ptr<DocumentFeed> feed =
707 DocumentFeed::CreateFromChangeList(*current_feed);
708 //feed->largest_changestamp_ = params->root_feed_changestamp;
709 params->feed_list->push_back(feed.release());
710
711 // Compute and notify the number of entries fetched so far.
712 int num_accumulated_entries = 0;
713 for (size_t i = 0; i < params->feed_list->size(); ++i)
714 num_accumulated_entries += params->feed_list->at(i)->entries().size();
715
716 // Notify the observers that a document feed is fetched.
717 FOR_EACH_OBSERVER(Observer, observers_,
718 OnDocumentFeedFetched(num_accumulated_entries));
719
720 // Check if we need to collect more data to complete the directory list.
721 if (params->should_fetch_multiple_feeds && has_next_feed) {
722 // Kick of the remaining part of the feeds.
723 documents_service_->GetChangelist(
724 current_feed->next_link(),
725 params->start_changestamp,
726 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
727 weak_ptr_factory_.GetWeakPtr(),
728 initial_origin,
729 callback,
730 base::Owned(
731 new GetDocumentsParams(
732 params->start_changestamp,
733 params->root_feed_changestamp,
734 params->feed_list.release(),
735 params->should_fetch_multiple_feeds,
736 params->search_file_path,
737 params->search_query,
738 params->directory_resource_id,
739 params->callback,
740 NULL)),
741 start_time));
742 return;
743 }
744
745 UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime",
746 base::TimeTicks::Now() - start_time);
747
748 if (!callback.is_null())
749 callback.Run(params, error);
750 }
751
628 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( 752 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched(
629 base::WeakPtr<GetDocumentsUiState> ui_state) { 753 base::WeakPtr<GetDocumentsUiState> ui_state) {
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
631 755
632 if (!ui_state) { 756 if (!ui_state) {
633 // The ui state instance is already released, which means the fetching 757 // The ui state instance is already released, which means the fetching
634 // is done and we don't need to update any more. 758 // is done and we don't need to update any more.
635 return; 759 return;
636 } 760 }
637 761
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 dir_iter != changed_dirs.end(); ++dir_iter) { 930 dir_iter != changed_dirs.end(); ++dir_iter) {
807 FOR_EACH_OBSERVER(Observer, observers_, 931 FOR_EACH_OBSERVER(Observer, observers_,
808 OnDirectoryChanged(*dir_iter)); 932 OnDirectoryChanged(*dir_iter));
809 } 933 }
810 } 934 }
811 935
812 return error; 936 return error;
813 } 937 }
814 938
815 } // namespace gdata 939 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698