| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/arc/fileapi/arc_documents_provider_backend_del
egate.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_del
egate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_file_stream
_reader.h" |
| 12 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" |
| 10 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 11 #include "storage/browser/fileapi/file_stream_reader.h" | 14 #include "storage/browser/fileapi/file_stream_reader.h" |
| 12 #include "storage/browser/fileapi/file_stream_writer.h" | 15 #include "storage/browser/fileapi/file_stream_writer.h" |
| 13 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 14 | 17 |
| 15 using content::BrowserThread; | 18 using content::BrowserThread; |
| 16 | 19 |
| 17 namespace arc { | 20 namespace arc { |
| 18 | 21 |
| 19 ArcDocumentsProviderBackendDelegate::ArcDocumentsProviderBackendDelegate() | 22 ArcDocumentsProviderBackendDelegate::ArcDocumentsProviderBackendDelegate() |
| 20 : async_file_util_(&roots_) {} | 23 : async_file_util_(&roots_), weak_ptr_factory_(this) {} |
| 21 | 24 |
| 22 ArcDocumentsProviderBackendDelegate::~ArcDocumentsProviderBackendDelegate() { | 25 ArcDocumentsProviderBackendDelegate::~ArcDocumentsProviderBackendDelegate() { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 26 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 24 } | 27 } |
| 25 | 28 |
| 26 storage::AsyncFileUtil* ArcDocumentsProviderBackendDelegate::GetAsyncFileUtil( | 29 storage::AsyncFileUtil* ArcDocumentsProviderBackendDelegate::GetAsyncFileUtil( |
| 27 storage::FileSystemType type) { | 30 storage::FileSystemType type) { |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 29 return &async_file_util_; | 32 return &async_file_util_; |
| 30 } | 33 } |
| 31 | 34 |
| 32 std::unique_ptr<storage::FileStreamReader> | 35 std::unique_ptr<storage::FileStreamReader> |
| 33 ArcDocumentsProviderBackendDelegate::CreateFileStreamReader( | 36 ArcDocumentsProviderBackendDelegate::CreateFileStreamReader( |
| 34 const storage::FileSystemURL& url, | 37 const storage::FileSystemURL& url, |
| 35 int64_t offset, | 38 int64_t offset, |
| 36 int64_t max_bytes_to_read, | 39 int64_t max_bytes_to_read, |
| 37 const base::Time& expected_modification_time, | 40 const base::Time& expected_modification_time, |
| 38 storage::FileSystemContext* context) { | 41 storage::FileSystemContext* context) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 42 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 43 |
| 41 return nullptr; | 44 auto reader = base::MakeUnique<ArcDocumentsProviderFileStreamReader>(offset); |
| 45 |
| 46 base::FilePath path; |
| 47 ArcDocumentsProviderRoot* root = roots_.ParseAndLookup(url, &path); |
| 48 if (!root) { |
| 49 reader->SetContentUrl(GURL()); |
| 50 return std::move(reader); |
| 51 } |
| 52 |
| 53 root->ResolveToContentUrl( |
| 54 path, base::Bind(&ArcDocumentsProviderFileStreamReader::SetContentUrl, |
| 55 reader->GetWeakPtr())); |
| 56 return std::move(reader); |
| 42 } | 57 } |
| 43 | 58 |
| 44 std::unique_ptr<storage::FileStreamWriter> | 59 std::unique_ptr<storage::FileStreamWriter> |
| 45 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( | 60 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( |
| 46 const storage::FileSystemURL& url, | 61 const storage::FileSystemURL& url, |
| 47 int64_t offset, | 62 int64_t offset, |
| 48 storage::FileSystemContext* context) { | 63 storage::FileSystemContext* context) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 NOTREACHED(); // Read-only file system. | 65 NOTREACHED(); // Read-only file system. |
| 51 return nullptr; | 66 return nullptr; |
| 52 } | 67 } |
| 53 | 68 |
| 54 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( | 69 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( |
| 55 storage::FileSystemType type) { | 70 storage::FileSystemType type) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 57 NOTREACHED(); // Non-watchable file system. | 72 NOTREACHED(); // Non-watchable file system. |
| 58 return nullptr; | 73 return nullptr; |
| 59 } | 74 } |
| 60 | 75 |
| 61 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( | 76 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( |
| 62 const storage::FileSystemURL& url, | 77 const storage::FileSystemURL& url, |
| 63 const storage::URLCallback& callback) { | 78 const storage::URLCallback& callback) { |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 65 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 80 NOTREACHED(); // Never called by chromeos::FileSystemBackend. |
| 66 callback.Run(GURL()); | 81 callback.Run(GURL()); |
| 67 } | 82 } |
| 68 | 83 |
| 69 } // namespace arc | 84 } // namespace arc |
| OLD | NEW |