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

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

Issue 23258006: drive: Move RefreshDirectory from ResourceMetadata to ChangeListLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix Created 7 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/drive/change_list_loader.h" 5 #include "chrome/browser/chromeos/drive/change_list_loader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 DCHECK(!callback.is_null()); 549 DCHECK(!callback.is_null());
550 DCHECK_EQ(directory_fetch_info.resource_id(), 550 DCHECK_EQ(directory_fetch_info.resource_id(),
551 util::kDriveGrandRootSpecialResourceId); 551 util::kDriveGrandRootSpecialResourceId);
552 552
553 FileError error = GDataToFileError(status); 553 FileError error = GDataToFileError(status);
554 if (error != FILE_ERROR_OK) { 554 if (error != FILE_ERROR_OK) {
555 callback.Run(error); 555 callback.Run(error);
556 return; 556 return;
557 } 557 }
558 558
559 // Build entry map for grand root directory, since the special static 559 // Grand root will be changed.
560 // directory "drive/other" is always created during the initialization of 560 base::FilePath* changed_directory_path =
561 // ResourceMetadata, here we only need to create a dynamic directory 561 new base::FilePath(util::GetDriveGrandRootPath());
562 // "drive/root" from its resource ID. 562 // Add "My Drive".
563 ResourceEntryMap grand_root_entry_map;
564 const std::string& root_resource_id = about_resource->root_folder_id(); 563 const std::string& root_resource_id = about_resource->root_folder_id();
565 grand_root_entry_map[root_resource_id] = 564 base::PostTaskAndReplyWithResult(
566 util::CreateMyDriveRootEntry(root_resource_id); 565 blocking_task_runner_,
567 resource_metadata_->RefreshDirectoryOnUIThread( 566 FROM_HERE,
568 directory_fetch_info, 567 base::Bind(&ResourceMetadata::AddEntry,
569 grand_root_entry_map, 568 base::Unretained(resource_metadata_),
569 util::CreateMyDriveRootEntry(root_resource_id)),
570 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh, 570 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh,
571 weak_ptr_factory_.GetWeakPtr(), 571 weak_ptr_factory_.GetWeakPtr(),
572 directory_fetch_info, 572 directory_fetch_info,
573 callback)); 573 callback,
574 base::Owned(changed_directory_path)));
574 } 575 }
575 576
576 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad( 577 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad(
577 const DirectoryFetchInfo& directory_fetch_info, 578 const DirectoryFetchInfo& directory_fetch_info,
578 const FileOperationCallback& callback, 579 const FileOperationCallback& callback,
579 ScopedVector<ChangeList> change_lists, 580 ScopedVector<ChangeList> change_lists,
580 FileError error) { 581 FileError error) {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
582 DCHECK(!callback.is_null()); 583 DCHECK(!callback.is_null());
583 DCHECK(!directory_fetch_info.empty()); 584 DCHECK(!directory_fetch_info.empty());
584 585
585 if (error != FILE_ERROR_OK) { 586 if (error != FILE_ERROR_OK) {
586 LOG(ERROR) << "Failed to load directory: " 587 LOG(ERROR) << "Failed to load directory: "
587 << directory_fetch_info.resource_id() 588 << directory_fetch_info.resource_id()
588 << ": " << FileErrorToString(error); 589 << ": " << FileErrorToString(error);
589 callback.Run(error); 590 callback.Run(error);
590 return; 591 return;
591 } 592 }
592 593
593 ChangeListProcessor::ResourceEntryMap entry_map; 594 ChangeListProcessor::ResourceEntryMap entry_map;
594 ChangeListProcessor::ConvertToMap(change_lists.Pass(), &entry_map, NULL); 595 ChangeListProcessor::ConvertToMap(change_lists.Pass(), &entry_map, NULL);
595 resource_metadata_->RefreshDirectoryOnUIThread( 596 base::FilePath* directory_path = new base::FilePath;
596 directory_fetch_info, 597 base::PostTaskAndReplyWithResult(
597 entry_map, 598 blocking_task_runner_,
599 FROM_HERE,
600 base::Bind(&ChangeListProcessor::RefreshDirectory,
601 resource_metadata_,
602 directory_fetch_info,
603 entry_map,
604 directory_path),
598 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh, 605 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh,
599 weak_ptr_factory_.GetWeakPtr(), 606 weak_ptr_factory_.GetWeakPtr(),
600 directory_fetch_info, 607 directory_fetch_info,
601 callback)); 608 callback,
609 base::Owned(directory_path)));
602 } 610 }
603 611
604 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh( 612 void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh(
605 const DirectoryFetchInfo& directory_fetch_info, 613 const DirectoryFetchInfo& directory_fetch_info,
606 const FileOperationCallback& callback, 614 const FileOperationCallback& callback,
607 FileError error, 615 const base::FilePath* directory_path,
608 const base::FilePath& directory_path) { 616 FileError error) {
609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
610 DCHECK(!callback.is_null()); 618 DCHECK(!callback.is_null());
611 619
612 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString(); 620 DVLOG(1) << "Directory loaded: " << directory_fetch_info.ToString();
613 callback.Run(error); 621 callback.Run(error);
614 // Also notify the observers. 622 // Also notify the observers.
615 if (error == FILE_ERROR_OK) { 623 if (error == FILE_ERROR_OK) {
616 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, 624 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_,
617 OnDirectoryChanged(directory_path)); 625 OnDirectoryChanged(*directory_path));
618 } 626 }
619 } 627 }
620 628
621 void ChangeListLoader::UpdateFromChangeList( 629 void ChangeListLoader::UpdateFromChangeList(
622 scoped_ptr<google_apis::AboutResource> about_resource, 630 scoped_ptr<google_apis::AboutResource> about_resource,
623 ScopedVector<ChangeList> change_lists, 631 ScopedVector<ChangeList> change_lists,
624 bool is_delta_update, 632 bool is_delta_update,
625 const base::Closure& callback) { 633 const base::Closure& callback) {
626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
627 DCHECK(!callback.is_null()); 635 DCHECK(!callback.is_null());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, 680 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_,
673 OnDirectoryChanged(*dir_iter)); 681 OnDirectoryChanged(*dir_iter));
674 } 682 }
675 } 683 }
676 684
677 callback.Run(); 685 callback.Run();
678 } 686 }
679 687
680 } // namespace internal 688 } // namespace internal
681 } // namespace drive 689 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader.h ('k') | chrome/browser/chromeos/drive/change_list_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698