| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_file_system/drive_backend_v1/api_util.h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/api_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 const std::string& directory_resource_id, | 454 const std::string& directory_resource_id, |
| 455 const ResourceListCallback& callback) { | 455 const ResourceListCallback& callback) { |
| 456 DCHECK(CalledOnValidThread()); | 456 DCHECK(CalledOnValidThread()); |
| 457 DCHECK(!title.empty()); | 457 DCHECK(!title.empty()); |
| 458 DVLOG(2) << "Searching resources in the directory [" << directory_resource_id | 458 DVLOG(2) << "Searching resources in the directory [" << directory_resource_id |
| 459 << "] with title [" << title << "]"; | 459 << "] with title [" << title << "]"; |
| 460 | 460 |
| 461 drive_service_->SearchByTitle( | 461 drive_service_->SearchByTitle( |
| 462 title, | 462 title, |
| 463 directory_resource_id, | 463 directory_resource_id, |
| 464 base::Bind(&APIUtil::DidGetResourceList, AsWeakPtr(), callback)); | 464 base::Bind(&APIUtil::DidGetFileList, AsWeakPtr(), callback)); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void APIUtil::ListFiles(const std::string& directory_resource_id, | 467 void APIUtil::ListFiles(const std::string& directory_resource_id, |
| 468 const ResourceListCallback& callback) { | 468 const ResourceListCallback& callback) { |
| 469 DCHECK(CalledOnValidThread()); | 469 DCHECK(CalledOnValidThread()); |
| 470 DVLOG(2) << "Listing resources in the directory [" << directory_resource_id | 470 DVLOG(2) << "Listing resources in the directory [" << directory_resource_id |
| 471 << "]"; | 471 << "]"; |
| 472 | 472 |
| 473 drive_service_->GetResourceListInDirectory(directory_resource_id, callback); | 473 drive_service_->GetFileListInDirectory( |
| 474 directory_resource_id, |
| 475 base::Bind(&APIUtil::DidGetFileList, AsWeakPtr(), callback)); |
| 474 } | 476 } |
| 475 | 477 |
| 476 void APIUtil::ListChanges(int64 start_changestamp, | 478 void APIUtil::ListChanges(int64 start_changestamp, |
| 477 const ResourceListCallback& callback) { | 479 const ResourceListCallback& callback) { |
| 478 DCHECK(CalledOnValidThread()); | 480 DCHECK(CalledOnValidThread()); |
| 479 DVLOG(2) << "Listing changes since: " << start_changestamp; | 481 DVLOG(2) << "Listing changes since: " << start_changestamp; |
| 480 | 482 |
| 481 drive_service_->GetChangeList( | 483 drive_service_->GetChangeList( |
| 482 start_changestamp, | 484 start_changestamp, |
| 483 base::Bind(&APIUtil::DidGetChangeList, AsWeakPtr(), callback)); | 485 base::Bind(&APIUtil::DidGetChangeList, AsWeakPtr(), callback)); |
| 484 } | 486 } |
| 485 | 487 |
| 486 void APIUtil::ContinueListing(const GURL& next_link, | 488 void APIUtil::ContinueListing(const GURL& next_link, |
| 487 const ResourceListCallback& callback) { | 489 const ResourceListCallback& callback) { |
| 488 DCHECK(CalledOnValidThread()); | 490 DCHECK(CalledOnValidThread()); |
| 489 DVLOG(2) << "Continue listing on feed: " << next_link.spec(); | 491 DVLOG(2) << "Continue listing on feed: " << next_link.spec(); |
| 490 | 492 |
| 491 drive_service_->GetRemainingFileList( | 493 drive_service_->GetRemainingFileList( |
| 492 next_link, | 494 next_link, |
| 493 base::Bind(&APIUtil::DidGetResourceList, AsWeakPtr(), callback)); | 495 base::Bind(&APIUtil::DidGetFileList, AsWeakPtr(), callback)); |
| 494 } | 496 } |
| 495 | 497 |
| 496 void APIUtil::DownloadFile(const std::string& resource_id, | 498 void APIUtil::DownloadFile(const std::string& resource_id, |
| 497 const std::string& local_file_md5, | 499 const std::string& local_file_md5, |
| 498 const DownloadFileCallback& callback) { | 500 const DownloadFileCallback& callback) { |
| 499 DCHECK(CalledOnValidThread()); | 501 DCHECK(CalledOnValidThread()); |
| 500 DCHECK(!temp_dir_path_.empty()); | 502 DCHECK(!temp_dir_path_.empty()); |
| 501 DVLOG(2) << "Downloading file [" << resource_id << "]"; | 503 DVLOG(2) << "Downloading file [" << resource_id << "]"; |
| 502 | 504 |
| 503 scoped_ptr<webkit_blob::ScopedFile> temp_file(new webkit_blob::ScopedFile); | 505 scoped_ptr<webkit_blob::ScopedFile> temp_file(new webkit_blob::ScopedFile); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnNetworkConnected()); | 670 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnNetworkConnected()); |
| 669 return; | 671 return; |
| 670 } | 672 } |
| 671 // We're now disconnected, reset the drive_uploader_ to force stop | 673 // We're now disconnected, reset the drive_uploader_ to force stop |
| 672 // uploading, otherwise the uploader may get stuck. | 674 // uploading, otherwise the uploader may get stuck. |
| 673 // TODO(kinuko): Check the uploader behavior if it's the expected behavior | 675 // TODO(kinuko): Check the uploader behavior if it's the expected behavior |
| 674 // (http://crbug.com/223818) | 676 // (http://crbug.com/223818) |
| 675 CancelAllUploads(google_apis::GDATA_NO_CONNECTION); | 677 CancelAllUploads(google_apis::GDATA_NO_CONNECTION); |
| 676 } | 678 } |
| 677 | 679 |
| 680 void APIUtil::DidGetFileList(const ResourceListCallback& callback, |
| 681 google_apis::GDataErrorCode error, |
| 682 scoped_ptr<google_apis::FileList> file_list) { |
| 683 DCHECK(CalledOnValidThread()); |
| 684 |
| 685 if (error != google_apis::HTTP_SUCCESS) { |
| 686 DVLOG(2) << "Error on listing files: " << error; |
| 687 callback.Run(error, scoped_ptr<google_apis::ResourceList>()); |
| 688 return; |
| 689 } |
| 690 |
| 691 DVLOG(2) << "Got file list"; |
| 692 DCHECK(file_list); |
| 693 callback.Run(error, drive::util::ConvertFileListToResourceList(*file_list)); |
| 694 } |
| 695 |
| 678 void APIUtil::DidGetChangeList( | 696 void APIUtil::DidGetChangeList( |
| 679 const ResourceListCallback& callback, | 697 const ResourceListCallback& callback, |
| 680 google_apis::GDataErrorCode error, | 698 google_apis::GDataErrorCode error, |
| 681 scoped_ptr<google_apis::ChangeList> change_list) { | 699 scoped_ptr<google_apis::ChangeList> change_list) { |
| 682 DCHECK(CalledOnValidThread()); | 700 DCHECK(CalledOnValidThread()); |
| 683 | 701 |
| 684 if (error != google_apis::HTTP_SUCCESS) { | 702 if (error != google_apis::HTTP_SUCCESS) { |
| 685 DVLOG(2) << "Error on listing changes: " << error; | 703 DVLOG(2) << "Error on listing changes: " << error; |
| 686 callback.Run(error, scoped_ptr<google_apis::ResourceList>()); | 704 callback.Run(error, scoped_ptr<google_apis::ResourceList>()); |
| 687 return; | 705 return; |
| 688 } | 706 } |
| 689 | 707 |
| 690 DVLOG(2) << "Got change list"; | 708 DVLOG(2) << "Got change list"; |
| 691 DCHECK(change_list); | 709 DCHECK(change_list); |
| 692 callback.Run(error, | 710 callback.Run(error, |
| 693 drive::util::ConvertChangeListToResourceList(*change_list)); | 711 drive::util::ConvertChangeListToResourceList(*change_list)); |
| 694 } | 712 } |
| 695 | 713 |
| 696 void APIUtil::DidGetResourceList( | |
| 697 const ResourceListCallback& callback, | |
| 698 google_apis::GDataErrorCode error, | |
| 699 scoped_ptr<google_apis::ResourceList> resource_list) { | |
| 700 DCHECK(CalledOnValidThread()); | |
| 701 | |
| 702 if (error != google_apis::HTTP_SUCCESS) { | |
| 703 DVLOG(2) << "Error on listing resource: " << error; | |
| 704 callback.Run(error, scoped_ptr<google_apis::ResourceList>()); | |
| 705 return; | |
| 706 } | |
| 707 | |
| 708 DVLOG(2) << "Got resource list"; | |
| 709 DCHECK(resource_list); | |
| 710 callback.Run(error, resource_list.Pass()); | |
| 711 } | |
| 712 | |
| 713 void APIUtil::DidGetResourceEntry( | 714 void APIUtil::DidGetResourceEntry( |
| 714 const ResourceEntryCallback& callback, | 715 const ResourceEntryCallback& callback, |
| 715 google_apis::GDataErrorCode error, | 716 google_apis::GDataErrorCode error, |
| 716 scoped_ptr<google_apis::ResourceEntry> entry) { | 717 scoped_ptr<google_apis::ResourceEntry> entry) { |
| 717 DCHECK(CalledOnValidThread()); | 718 DCHECK(CalledOnValidThread()); |
| 718 | 719 |
| 719 if (error != google_apis::HTTP_SUCCESS) { | 720 if (error != google_apis::HTTP_SUCCESS) { |
| 720 DVLOG(2) << "Error on getting resource entry:" << error; | 721 DVLOG(2) << "Error on getting resource entry:" << error; |
| 721 callback.Run(error, scoped_ptr<google_apis::ResourceEntry>()); | 722 callback.Run(error, scoped_ptr<google_apis::ResourceEntry>()); |
| 722 return; | 723 return; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } | 1142 } |
| 1142 | 1143 |
| 1143 std::string APIUtil::GetRootResourceId() const { | 1144 std::string APIUtil::GetRootResourceId() const { |
| 1144 if (IsDriveAPIDisabled()) | 1145 if (IsDriveAPIDisabled()) |
| 1145 return drive_service_->GetRootResourceId(); | 1146 return drive_service_->GetRootResourceId(); |
| 1146 return root_resource_id_; | 1147 return root_resource_id_; |
| 1147 } | 1148 } |
| 1148 | 1149 |
| 1149 } // namespace drive_backend | 1150 } // namespace drive_backend |
| 1150 } // namespace sync_file_system | 1151 } // namespace sync_file_system |
| OLD | NEW |