OLD | NEW |
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/drive_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 19 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" | 20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
21 #include "chrome/browser/chromeos/gdata/drive_files.h" | 21 #include "chrome/browser/chromeos/gdata/drive_files.h" |
22 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" | 22 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" |
23 #include "chrome/browser/chromeos/gdata/drive_function_remove.h" | 23 #include "chrome/browser/chromeos/gdata/drive_function_remove.h" |
24 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 24 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
25 #include "chrome/browser/chromeos/gdata/drive_system_service.h" | 25 #include "chrome/browser/chromeos/gdata/drive_system_service.h" |
| 26 #include "chrome/browser/chromeos/gdata/drive_uploader.h" |
26 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 27 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | |
28 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
29 #include "chrome/browser/chromeos/gdata/task_util.h" | 29 #include "chrome/browser/chromeos/gdata/task_util.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
36 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
37 | 37 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 base::Closure callback; | 382 base::Closure callback; |
383 }; | 383 }; |
384 | 384 |
385 | 385 |
386 // DriveFileSystem class implementation. | 386 // DriveFileSystem class implementation. |
387 | 387 |
388 DriveFileSystem::DriveFileSystem( | 388 DriveFileSystem::DriveFileSystem( |
389 Profile* profile, | 389 Profile* profile, |
390 DriveCache* cache, | 390 DriveCache* cache, |
391 DriveServiceInterface* drive_service, | 391 DriveServiceInterface* drive_service, |
392 GDataUploaderInterface* uploader, | 392 DriveUploaderInterface* uploader, |
393 DriveWebAppsRegistryInterface* webapps_registry, | 393 DriveWebAppsRegistryInterface* webapps_registry, |
394 base::SequencedTaskRunner* blocking_task_runner) | 394 base::SequencedTaskRunner* blocking_task_runner) |
395 : profile_(profile), | 395 : profile_(profile), |
396 cache_(cache), | 396 cache_(cache), |
397 uploader_(uploader), | 397 uploader_(uploader), |
398 drive_service_(drive_service), | 398 drive_service_(drive_service), |
399 webapps_registry_(webapps_registry), | 399 webapps_registry_(webapps_registry), |
400 update_timer_(true /* retain_user_task */, true /* is_repeating */), | 400 update_timer_(true /* retain_user_task */, true /* is_repeating */), |
401 hide_hosted_docs_(false), | 401 hide_hosted_docs_(false), |
402 blocking_task_runner_(blocking_task_runner), | 402 blocking_task_runner_(blocking_task_runner), |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 base::Owned(file_size), | 699 base::Owned(file_size), |
700 base::Owned(content_type))); | 700 base::Owned(content_type))); |
701 } | 701 } |
702 | 702 |
703 void DriveFileSystem::StartFileUploadOnUIThread( | 703 void DriveFileSystem::StartFileUploadOnUIThread( |
704 const StartFileUploadParams& params, | 704 const StartFileUploadParams& params, |
705 DriveFileError* error, | 705 DriveFileError* error, |
706 int64* file_size, | 706 int64* file_size, |
707 std::string* content_type) { | 707 std::string* content_type) { |
708 // This method needs to run on the UI thread as required by | 708 // This method needs to run on the UI thread as required by |
709 // GDataUploader::UploadNewFile(). | 709 // DriveUploader::UploadNewFile(). |
710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
711 DCHECK(error); | 711 DCHECK(error); |
712 DCHECK(file_size); | 712 DCHECK(file_size); |
713 DCHECK(content_type); | 713 DCHECK(content_type); |
714 | 714 |
715 if (*error != DRIVE_FILE_OK) { | 715 if (*error != DRIVE_FILE_OK) { |
716 if (!params.callback.is_null()) | 716 if (!params.callback.is_null()) |
717 params.callback.Run(*error); | 717 params.callback.Run(*error); |
718 | 718 |
719 return; | 719 return; |
(...skipping 25 matching lines...) Expand all Loading... |
745 if (!params.callback.is_null()) | 745 if (!params.callback.is_null()) |
746 params.callback.Run(error); | 746 params.callback.Run(error); |
747 return; | 747 return; |
748 } | 748 } |
749 DCHECK(entry_proto.get()); | 749 DCHECK(entry_proto.get()); |
750 | 750 |
751 // Fill in values of UploadFileInfo. | 751 // Fill in values of UploadFileInfo. |
752 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); | 752 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); |
753 upload_file_info->file_path = params.local_file_path; | 753 upload_file_info->file_path = params.local_file_path; |
754 upload_file_info->file_size = file_size; | 754 upload_file_info->file_size = file_size; |
755 upload_file_info->gdata_path = params.remote_file_path; | 755 upload_file_info->drive_path = params.remote_file_path; |
756 // Use the file name as the title. | 756 // Use the file name as the title. |
757 upload_file_info->title = params.remote_file_path.BaseName().value(); | 757 upload_file_info->title = params.remote_file_path.BaseName().value(); |
758 upload_file_info->content_length = file_size; | 758 upload_file_info->content_length = file_size; |
759 upload_file_info->all_bytes_present = true; | 759 upload_file_info->all_bytes_present = true; |
760 upload_file_info->content_type = content_type; | 760 upload_file_info->content_type = content_type; |
761 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); | 761 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); |
762 | 762 |
763 upload_file_info->completion_callback = | 763 upload_file_info->completion_callback = |
764 base::Bind(&DriveFileSystem::OnTransferCompleted, | 764 base::Bind(&DriveFileSystem::OnTransferCompleted, |
765 ui_weak_ptr_, | 765 ui_weak_ptr_, |
766 params.callback); | 766 params.callback); |
767 | 767 |
768 uploader_->UploadNewFile(upload_file_info.Pass()); | 768 uploader_->UploadNewFile(upload_file_info.Pass()); |
769 } | 769 } |
770 | 770 |
771 void DriveFileSystem::OnTransferCompleted( | 771 void DriveFileSystem::OnTransferCompleted( |
772 const FileOperationCallback& callback, | 772 const FileOperationCallback& callback, |
773 DriveFileError error, | 773 DriveFileError error, |
774 scoped_ptr<UploadFileInfo> upload_file_info) { | 774 scoped_ptr<UploadFileInfo> upload_file_info) { |
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
776 DCHECK(upload_file_info.get()); | 776 DCHECK(upload_file_info.get()); |
777 | 777 |
778 if (error == DRIVE_FILE_OK && upload_file_info->entry.get()) { | 778 if (error == DRIVE_FILE_OK && upload_file_info->entry.get()) { |
779 AddUploadedFile(UPLOAD_NEW_FILE, | 779 AddUploadedFile(UPLOAD_NEW_FILE, |
780 upload_file_info->gdata_path.DirName(), | 780 upload_file_info->drive_path.DirName(), |
781 upload_file_info->entry.Pass(), | 781 upload_file_info->entry.Pass(), |
782 upload_file_info->file_path, | 782 upload_file_info->file_path, |
783 DriveCache::FILE_OPERATION_COPY, | 783 DriveCache::FILE_OPERATION_COPY, |
784 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 784 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
785 } else if (!callback.is_null()) { | 785 } else if (!callback.is_null()) { |
786 callback.Run(error); | 786 callback.Run(error); |
787 } | 787 } |
788 } | 788 } |
789 | 789 |
790 void DriveFileSystem::Copy(const FilePath& src_file_path, | 790 void DriveFileSystem::Copy(const FilePath& src_file_path, |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2046 DCHECK(upload_file_info.get()); | 2046 DCHECK(upload_file_info.get()); |
2047 | 2047 |
2048 if (error != DRIVE_FILE_OK) { | 2048 if (error != DRIVE_FILE_OK) { |
2049 if (!callback.is_null()) | 2049 if (!callback.is_null()) |
2050 callback.Run(error); | 2050 callback.Run(error); |
2051 return; | 2051 return; |
2052 } | 2052 } |
2053 | 2053 |
2054 AddUploadedFile(UPLOAD_EXISTING_FILE, | 2054 AddUploadedFile(UPLOAD_EXISTING_FILE, |
2055 upload_file_info->gdata_path.DirName(), | 2055 upload_file_info->drive_path.DirName(), |
2056 upload_file_info->entry.Pass(), | 2056 upload_file_info->entry.Pass(), |
2057 upload_file_info->file_path, | 2057 upload_file_info->file_path, |
2058 DriveCache::FILE_OPERATION_MOVE, | 2058 DriveCache::FILE_OPERATION_MOVE, |
2059 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 2059 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
2060 } | 2060 } |
2061 | 2061 |
2062 void DriveFileSystem::GetAvailableSpace( | 2062 void DriveFileSystem::GetAvailableSpace( |
2063 const GetAvailableSpaceCallback& callback) { | 2063 const GetAvailableSpaceCallback& callback) { |
2064 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2064 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2065 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2065 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3218 return; | 3218 return; |
3219 } | 3219 } |
3220 | 3220 |
3221 PlatformFileInfoProto entry_file_info; | 3221 PlatformFileInfoProto entry_file_info; |
3222 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3222 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3223 *entry_proto->mutable_file_info() = entry_file_info; | 3223 *entry_proto->mutable_file_info() = entry_file_info; |
3224 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3224 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3225 } | 3225 } |
3226 | 3226 |
3227 } // namespace gdata | 3227 } // namespace gdata |
OLD | NEW |