| 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/drive/file_system_proxy.h" | 5 #include "chrome/browser/chromeos/drive/file_system_proxy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 14 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_system_service.h" | 15 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 16 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 18 #include "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h" | 18 #include "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h" |
| 19 #include "chrome/browser/google_apis/task_util.h" | 19 #include "chrome/browser/google_apis/task_util.h" |
| 20 #include "chrome/browser/google_apis/time_util.h" | 20 #include "chrome/browser/google_apis/time_util.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "webkit/blob/file_stream_reader.h" | 22 #include "webkit/blob/file_stream_reader.h" |
| 23 #include "webkit/blob/shareable_file_reference.h" | 23 #include "webkit/blob/shareable_file_reference.h" |
| 24 #include "webkit/fileapi/file_system_types.h" | 24 #include "webkit/fileapi/file_system_types.h" |
| 25 #include "webkit/fileapi/file_system_url.h" | 25 #include "webkit/fileapi/file_system_url.h" |
| 26 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 27 | 27 |
| 28 using base::MessageLoopProxy; | 28 using base::MessageLoopProxy; |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 using fileapi::DirectoryEntry; |
| 30 using fileapi::FileSystemURL; | 31 using fileapi::FileSystemURL; |
| 31 using fileapi::FileSystemOperation; | 32 using fileapi::FileSystemOperation; |
| 32 using webkit_blob::ShareableFileReference; | 33 using webkit_blob::ShareableFileReference; |
| 33 | 34 |
| 34 namespace drive { | 35 namespace drive { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 typedef fileapi::RemoteFileSystemProxyInterface::OpenFileCallback | 39 typedef fileapi::RemoteFileSystemProxyInterface::OpenFileCallback |
| 39 OpenFileCallback; | 40 OpenFileCallback; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 base::PlatformFileError truncate_result, | 147 base::PlatformFileError truncate_result, |
| 147 FileError close_result) { | 148 FileError close_result) { |
| 148 // Reports the first error. | 149 // Reports the first error. |
| 149 callback.Run(truncate_result == base::PLATFORM_FILE_OK ? | 150 callback.Run(truncate_result == base::PLATFORM_FILE_OK ? |
| 150 FileErrorToPlatformError(close_result) : | 151 FileErrorToPlatformError(close_result) : |
| 151 truncate_result); | 152 truncate_result); |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace | 155 } // namespace |
| 155 | 156 |
| 156 base::FileUtilProxy::Entry ResourceEntryToFileUtilProxyEntry( | 157 DirectoryEntry ResourceEntryToDirectoryEntry( |
| 157 const ResourceEntry& resource_entry) { | 158 const ResourceEntry& resource_entry) { |
| 158 base::PlatformFileInfo file_info; | 159 base::PlatformFileInfo file_info; |
| 159 util::ConvertResourceEntryToPlatformFileInfo( | 160 util::ConvertResourceEntryToPlatformFileInfo( |
| 160 resource_entry.file_info(), &file_info); | 161 resource_entry.file_info(), &file_info); |
| 161 | 162 |
| 162 base::FileUtilProxy::Entry entry; | 163 DirectoryEntry entry; |
| 163 entry.name = resource_entry.base_name(); | 164 entry.name = resource_entry.base_name(); |
| 164 entry.is_directory = file_info.is_directory; | 165 entry.is_directory = file_info.is_directory; |
| 165 entry.size = file_info.size; | 166 entry.size = file_info.size; |
| 166 entry.last_modified_time = file_info.last_modified; | 167 entry.last_modified_time = file_info.last_modified; |
| 167 return entry; | 168 return entry; |
| 168 } | 169 } |
| 169 | 170 |
| 170 // FileSystemProxy class implementation. | 171 // FileSystemProxy class implementation. |
| 171 | 172 |
| 172 FileSystemProxy::FileSystemProxy( | 173 FileSystemProxy::FileSystemProxy( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 const FileSystemURL& file_url, | 263 const FileSystemURL& file_url, |
| 263 const FileSystemOperation::ReadDirectoryCallback& callback) { | 264 const FileSystemOperation::ReadDirectoryCallback& callback) { |
| 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 265 | 266 |
| 266 base::FilePath file_path; | 267 base::FilePath file_path; |
| 267 if (!ValidateUrl(file_url, &file_path)) { | 268 if (!ValidateUrl(file_url, &file_path)) { |
| 268 base::MessageLoopProxy::current()->PostTask( | 269 base::MessageLoopProxy::current()->PostTask( |
| 269 FROM_HERE, | 270 FROM_HERE, |
| 270 base::Bind(callback, | 271 base::Bind(callback, |
| 271 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 272 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 272 std::vector<base::FileUtilProxy::Entry>(), | 273 std::vector<DirectoryEntry>(), |
| 273 false)); | 274 false)); |
| 274 return; | 275 return; |
| 275 } | 276 } |
| 276 | 277 |
| 277 CallFileSystemMethodOnUIThread( | 278 CallFileSystemMethodOnUIThread( |
| 278 base::Bind(&FileSystemInterface::ReadDirectoryByPath, | 279 base::Bind(&FileSystemInterface::ReadDirectoryByPath, |
| 279 base::Unretained(file_system_), | 280 base::Unretained(file_system_), |
| 280 file_path, | 281 file_path, |
| 281 google_apis::CreateRelayCallback( | 282 google_apis::CreateRelayCallback( |
| 282 base::Bind(&FileSystemProxy::OnReadDirectory, | 283 base::Bind(&FileSystemProxy::OnReadDirectory, |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 void FileSystemProxy::OnReadDirectory( | 794 void FileSystemProxy::OnReadDirectory( |
| 794 const FileSystemOperation::ReadDirectoryCallback& | 795 const FileSystemOperation::ReadDirectoryCallback& |
| 795 callback, | 796 callback, |
| 796 FileError error, | 797 FileError error, |
| 797 bool hide_hosted_documents, | 798 bool hide_hosted_documents, |
| 798 scoped_ptr<ResourceEntryVector> resource_entries) { | 799 scoped_ptr<ResourceEntryVector> resource_entries) { |
| 799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 800 | 801 |
| 801 if (error != FILE_ERROR_OK) { | 802 if (error != FILE_ERROR_OK) { |
| 802 callback.Run(FileErrorToPlatformError(error), | 803 callback.Run(FileErrorToPlatformError(error), |
| 803 std::vector<base::FileUtilProxy::Entry>(), | 804 std::vector<DirectoryEntry>(), |
| 804 false); | 805 false); |
| 805 return; | 806 return; |
| 806 } | 807 } |
| 807 DCHECK(resource_entries.get()); | 808 DCHECK(resource_entries.get()); |
| 808 | 809 |
| 809 std::vector<base::FileUtilProxy::Entry> entries; | 810 std::vector<DirectoryEntry> entries; |
| 810 // Convert Drive files to something File API stack can understand. | 811 // Convert Drive files to something File API stack can understand. |
| 811 for (size_t i = 0; i < resource_entries->size(); ++i) { | 812 for (size_t i = 0; i < resource_entries->size(); ++i) { |
| 812 const ResourceEntry& resource_entry = (*resource_entries)[i]; | 813 const ResourceEntry& resource_entry = (*resource_entries)[i]; |
| 813 if (resource_entry.has_file_specific_info() && | 814 if (resource_entry.has_file_specific_info() && |
| 814 resource_entry.file_specific_info().is_hosted_document() && | 815 resource_entry.file_specific_info().is_hosted_document() && |
| 815 hide_hosted_documents) { | 816 hide_hosted_documents) { |
| 816 continue; | 817 continue; |
| 817 } | 818 } |
| 818 entries.push_back(ResourceEntryToFileUtilProxyEntry(resource_entry)); | 819 entries.push_back(ResourceEntryToDirectoryEntry(resource_entry)); |
| 819 } | 820 } |
| 820 | 821 |
| 821 callback.Run(base::PLATFORM_FILE_OK, entries, false); | 822 callback.Run(base::PLATFORM_FILE_OK, entries, false); |
| 822 } | 823 } |
| 823 | 824 |
| 824 void FileSystemProxy::OnCreateWritableSnapshotFile( | 825 void FileSystemProxy::OnCreateWritableSnapshotFile( |
| 825 const base::FilePath& virtual_path, | 826 const base::FilePath& virtual_path, |
| 826 const fileapi::WritableSnapshotFile& callback, | 827 const fileapi::WritableSnapshotFile& callback, |
| 827 FileError result, | 828 FileError result, |
| 828 const base::FilePath& local_path) { | 829 const base::FilePath& local_path) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 857 base::Bind(&EmitDebugLogForCloseFile, | 858 base::Bind(&EmitDebugLogForCloseFile, |
| 858 virtual_path)))); | 859 virtual_path)))); |
| 859 } | 860 } |
| 860 | 861 |
| 861 FileSystemInterface* FileSystemProxy::GetFileSystemOnUIThread() { | 862 FileSystemInterface* FileSystemProxy::GetFileSystemOnUIThread() { |
| 862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 863 return file_system_; | 864 return file_system_; |
| 864 } | 865 } |
| 865 | 866 |
| 866 } // namespace drive | 867 } // namespace drive |
| OLD | NEW |