| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" | 11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" |
| 12 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" | 12 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" |
| 13 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" | 13 #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
" | 14 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h
" |
| 15 #include "chrome/browser/drive/drive_api_util.h" | 15 #include "chrome/browser/drive/drive_api_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "webkit/browser/blob/file_stream_reader.h" | 17 #include "storage/browser/blob/file_stream_reader.h" |
| 18 #include "webkit/browser/fileapi/async_file_util.h" | 18 #include "storage/browser/fileapi/async_file_util.h" |
| 19 #include "webkit/browser/fileapi/file_system_context.h" | 19 #include "storage/browser/fileapi/file_system_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_url.h" | 20 #include "storage/browser/fileapi/file_system_url.h" |
| 21 | 21 |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 | 23 |
| 24 namespace drive { | 24 namespace drive { |
| 25 | 25 |
| 26 FileSystemBackendDelegate::FileSystemBackendDelegate() | 26 FileSystemBackendDelegate::FileSystemBackendDelegate() |
| 27 : async_file_util_(new internal::AsyncFileUtil) { | 27 : async_file_util_(new internal::AsyncFileUtil) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 FileSystemBackendDelegate::~FileSystemBackendDelegate() { | 30 FileSystemBackendDelegate::~FileSystemBackendDelegate() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 fileapi::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( | 33 storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( |
| 34 fileapi::FileSystemType type) { | 34 storage::FileSystemType type) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 36 DCHECK_EQ(fileapi::kFileSystemTypeDrive, type); | 36 DCHECK_EQ(storage::kFileSystemTypeDrive, type); |
| 37 return async_file_util_.get(); | 37 return async_file_util_.get(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 scoped_ptr<webkit_blob::FileStreamReader> | 40 scoped_ptr<storage::FileStreamReader> |
| 41 FileSystemBackendDelegate::CreateFileStreamReader( | 41 FileSystemBackendDelegate::CreateFileStreamReader( |
| 42 const fileapi::FileSystemURL& url, | 42 const storage::FileSystemURL& url, |
| 43 int64 offset, | 43 int64 offset, |
| 44 const base::Time& expected_modification_time, | 44 const base::Time& expected_modification_time, |
| 45 fileapi::FileSystemContext* context) { | 45 storage::FileSystemContext* context) { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 47 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type()); | 47 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); |
| 48 | 48 |
| 49 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 49 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
| 50 if (file_path.empty()) | 50 if (file_path.empty()) |
| 51 return scoped_ptr<webkit_blob::FileStreamReader>(); | 51 return scoped_ptr<storage::FileStreamReader>(); |
| 52 | 52 |
| 53 return scoped_ptr<webkit_blob::FileStreamReader>( | 53 return scoped_ptr<storage::FileStreamReader>( |
| 54 new internal::WebkitFileStreamReaderImpl( | 54 new internal::WebkitFileStreamReaderImpl( |
| 55 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), | 55 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
| 56 context->default_file_task_runner(), | 56 context->default_file_task_runner(), |
| 57 file_path, offset, expected_modification_time)); | 57 file_path, |
| 58 offset, |
| 59 expected_modification_time)); |
| 58 } | 60 } |
| 59 | 61 |
| 60 scoped_ptr<fileapi::FileStreamWriter> | 62 scoped_ptr<storage::FileStreamWriter> |
| 61 FileSystemBackendDelegate::CreateFileStreamWriter( | 63 FileSystemBackendDelegate::CreateFileStreamWriter( |
| 62 const fileapi::FileSystemURL& url, | 64 const storage::FileSystemURL& url, |
| 63 int64 offset, | 65 int64 offset, |
| 64 fileapi::FileSystemContext* context) { | 66 storage::FileSystemContext* context) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 66 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type()); | 68 DCHECK_EQ(storage::kFileSystemTypeDrive, url.type()); |
| 67 | 69 |
| 68 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 70 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
| 69 // Hosted documents don't support stream writer. | 71 // Hosted documents don't support stream writer. |
| 70 if (file_path.empty() || util::HasHostedDocumentExtension(file_path)) | 72 if (file_path.empty() || util::HasHostedDocumentExtension(file_path)) |
| 71 return scoped_ptr<fileapi::FileStreamWriter>(); | 73 return scoped_ptr<storage::FileStreamWriter>(); |
| 72 | 74 |
| 73 return scoped_ptr<fileapi::FileStreamWriter>( | 75 return scoped_ptr<storage::FileStreamWriter>( |
| 74 new internal::WebkitFileStreamWriterImpl( | 76 new internal::WebkitFileStreamWriterImpl( |
| 75 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), | 77 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
| 76 context->default_file_task_runner(),file_path, offset)); | 78 context->default_file_task_runner(), |
| 79 file_path, |
| 80 offset)); |
| 77 } | 81 } |
| 78 | 82 |
| 79 } // namespace drive | 83 } // namespace drive |
| OLD | NEW |