| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fileapi/file_system_backend_delegate.h" | 5 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" | 12 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" |
| 12 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" | 13 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" |
| 13 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" | 14 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" |
| 14 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h
" | 15 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h
" |
| 15 #include "components/drive/drive_api_util.h" | 16 #include "components/drive/drive_api_util.h" |
| 16 #include "components/drive/file_system_interface.h" | 17 #include "components/drive/file_system_interface.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "storage/browser/fileapi/async_file_util.h" | 19 #include "storage/browser/fileapi/async_file_util.h" |
| 19 #include "storage/browser/fileapi/file_stream_reader.h" | 20 #include "storage/browser/fileapi/file_stream_reader.h" |
| 20 #include "storage/browser/fileapi/file_system_context.h" | 21 #include "storage/browser/fileapi/file_system_context.h" |
| 21 #include "storage/browser/fileapi/file_system_url.h" | 22 #include "storage/browser/fileapi/file_system_url.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 | 25 |
| 25 namespace drive { | 26 namespace drive { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Called on the UI thread after GetRedirectURLForContentsOnUIThread. Obtains | 29 // Called on the UI thread after GetRedirectURLForContentsOnUIThread. Obtains |
| 29 // the browser URL from |entry|. |callback| will be called on the IO thread. | 30 // the browser URL from |entry|. |callback| will be called on the IO thread. |
| 30 void GetRedirectURLForContentsOnUIThreadWithResourceEntry( | 31 void GetRedirectURLForContentsOnUIThreadWithResourceEntry( |
| 31 const storage::URLCallback& callback, | 32 const storage::URLCallback& callback, |
| 32 FileError error, | 33 FileError error, |
| 33 scoped_ptr<ResourceEntry> entry) { | 34 std::unique_ptr<ResourceEntry> entry) { |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 35 GURL url; | 36 GURL url; |
| 36 if (error == FILE_ERROR_OK && entry->has_file_specific_info() && | 37 if (error == FILE_ERROR_OK && entry->has_file_specific_info() && |
| 37 entry->file_specific_info().is_hosted_document()) { | 38 entry->file_specific_info().is_hosted_document()) { |
| 38 url = GURL(entry->file_specific_info().alternate_url()); | 39 url = GURL(entry->file_specific_info().alternate_url()); |
| 39 } | 40 } |
| 40 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 41 BrowserThread::IO, FROM_HERE, base::Bind(callback, url)); | 42 BrowserThread::IO, FROM_HERE, base::Bind(callback, url)); |
| 42 } | 43 } |
| 43 | 44 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 FileSystemBackendDelegate::~FileSystemBackendDelegate() { | 78 FileSystemBackendDelegate::~FileSystemBackendDelegate() { |
| 78 } | 79 } |
| 79 | 80 |
| 80 storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( | 81 storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( |
| 81 storage::FileSystemType type) { | 82 storage::FileSystemType type) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 83 DCHECK_EQ(storage::kFileSystemTypeDrive, type); | 84 DCHECK_EQ(storage::kFileSystemTypeDrive, type); |
| 84 return async_file_util_.get(); | 85 return async_file_util_.get(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 scoped_ptr<storage::FileStreamReader> | 88 std::unique_ptr<storage::FileStreamReader> |
| 88 FileSystemBackendDelegate::CreateFileStreamReader( | 89 FileSystemBackendDelegate::CreateFileStreamReader( |
| 89 const storage::FileSystemURL& url, | 90 const storage::FileSystemURL& url, |
| 90 int64_t offset, | 91 int64_t offset, |
| 91 int64_t max_bytes_to_read, | 92 int64_t max_bytes_to_read, |
| 92 const base::Time& expected_modification_time, | 93 const base::Time& expected_modification_time, |
| 93 storage::FileSystemContext* context) { | 94 storage::FileSystemContext* context) { |
| 94 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 95 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); | 96 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); |
| 96 | 97 |
| 97 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 98 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
| 98 if (file_path.empty()) | 99 if (file_path.empty()) |
| 99 return scoped_ptr<storage::FileStreamReader>(); | 100 return std::unique_ptr<storage::FileStreamReader>(); |
| 100 | 101 |
| 101 return scoped_ptr<storage::FileStreamReader>( | 102 return std::unique_ptr<storage::FileStreamReader>( |
| 102 new internal::WebkitFileStreamReaderImpl( | 103 new internal::WebkitFileStreamReaderImpl( |
| 103 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), | 104 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
| 104 context->default_file_task_runner(), | 105 context->default_file_task_runner(), file_path, offset, |
| 105 file_path, | |
| 106 offset, | |
| 107 expected_modification_time)); | 106 expected_modification_time)); |
| 108 } | 107 } |
| 109 | 108 |
| 110 scoped_ptr<storage::FileStreamWriter> | 109 std::unique_ptr<storage::FileStreamWriter> |
| 111 FileSystemBackendDelegate::CreateFileStreamWriter( | 110 FileSystemBackendDelegate::CreateFileStreamWriter( |
| 112 const storage::FileSystemURL& url, | 111 const storage::FileSystemURL& url, |
| 113 int64_t offset, | 112 int64_t offset, |
| 114 storage::FileSystemContext* context) { | 113 storage::FileSystemContext* context) { |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 116 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); | 115 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); |
| 117 | 116 |
| 118 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 117 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
| 119 // Hosted documents don't support stream writer. | 118 // Hosted documents don't support stream writer. |
| 120 if (file_path.empty() || util::HasHostedDocumentExtension(file_path)) | 119 if (file_path.empty() || util::HasHostedDocumentExtension(file_path)) |
| 121 return scoped_ptr<storage::FileStreamWriter>(); | 120 return std::unique_ptr<storage::FileStreamWriter>(); |
| 122 | 121 |
| 123 return scoped_ptr<storage::FileStreamWriter>( | 122 return std::unique_ptr<storage::FileStreamWriter>( |
| 124 new internal::WebkitFileStreamWriterImpl( | 123 new internal::WebkitFileStreamWriterImpl( |
| 125 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), | 124 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
| 126 context->default_file_task_runner(), | 125 context->default_file_task_runner(), file_path, offset)); |
| 127 file_path, | |
| 128 offset)); | |
| 129 } | 126 } |
| 130 | 127 |
| 131 storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager( | 128 storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager( |
| 132 storage::FileSystemType type) { | 129 storage::FileSystemType type) { |
| 133 NOTIMPLEMENTED(); | 130 NOTIMPLEMENTED(); |
| 134 return NULL; | 131 return NULL; |
| 135 } | 132 } |
| 136 | 133 |
| 137 void FileSystemBackendDelegate::GetRedirectURLForContents( | 134 void FileSystemBackendDelegate::GetRedirectURLForContents( |
| 138 const storage::FileSystemURL& url, | 135 const storage::FileSystemURL& url, |
| 139 const storage::URLCallback& callback) { | 136 const storage::URLCallback& callback) { |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 137 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 141 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
| 142 BrowserThread::UI, | 139 BrowserThread::UI, |
| 143 FROM_HERE, | 140 FROM_HERE, |
| 144 base::Bind(&GetRedirectURLForContentsOnUIThread, url, callback)); | 141 base::Bind(&GetRedirectURLForContentsOnUIThread, url, callback)); |
| 145 } | 142 } |
| 146 | 143 |
| 147 } // namespace drive | 144 } // namespace drive |
| OLD | NEW |