Chromium Code Reviews| 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_content_file_system_url_util.h " | |
| 12 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_file_stream _reader.h" | |
| 13 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" | |
| 10 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 11 #include "storage/browser/fileapi/file_stream_reader.h" | 15 #include "storage/browser/fileapi/file_stream_reader.h" |
| 12 #include "storage/browser/fileapi/file_stream_writer.h" | 16 #include "storage/browser/fileapi/file_stream_writer.h" |
| 13 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 14 | 18 |
| 15 using content::BrowserThread; | 19 using content::BrowserThread; |
| 16 | 20 |
| 17 namespace arc { | 21 namespace arc { |
| 18 | 22 |
| 19 ArcDocumentsProviderBackendDelegate::ArcDocumentsProviderBackendDelegate() | 23 ArcDocumentsProviderBackendDelegate::ArcDocumentsProviderBackendDelegate() |
| 20 : async_file_util_(&roots_) {} | 24 : async_file_util_(&roots_), weak_ptr_factory_(this) {} |
| 21 | 25 |
| 22 ArcDocumentsProviderBackendDelegate::~ArcDocumentsProviderBackendDelegate() { | 26 ArcDocumentsProviderBackendDelegate::~ArcDocumentsProviderBackendDelegate() { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 27 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 24 } | 28 } |
| 25 | 29 |
| 26 storage::AsyncFileUtil* ArcDocumentsProviderBackendDelegate::GetAsyncFileUtil( | 30 storage::AsyncFileUtil* ArcDocumentsProviderBackendDelegate::GetAsyncFileUtil( |
| 27 storage::FileSystemType type) { | 31 storage::FileSystemType type) { |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 29 return &async_file_util_; | 33 return &async_file_util_; |
| 30 } | 34 } |
| 31 | 35 |
| 32 std::unique_ptr<storage::FileStreamReader> | 36 std::unique_ptr<storage::FileStreamReader> |
| 33 ArcDocumentsProviderBackendDelegate::CreateFileStreamReader( | 37 ArcDocumentsProviderBackendDelegate::CreateFileStreamReader( |
| 34 const storage::FileSystemURL& url, | 38 const storage::FileSystemURL& url, |
| 35 int64_t offset, | 39 int64_t offset, |
| 36 int64_t max_bytes_to_read, | 40 int64_t max_bytes_to_read, |
| 37 const base::Time& expected_modification_time, | 41 const base::Time& expected_modification_time, |
| 38 storage::FileSystemContext* context) { | 42 storage::FileSystemContext* context) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 44 |
| 41 return nullptr; | 45 auto reader = base::MakeUnique<ArcDocumentsProviderFileStreamReader>(offset); |
| 46 | |
| 47 base::FilePath path; | |
| 48 ArcDocumentsProviderRoot* root = roots_.ParseAndLookup(url, &path); | |
| 49 if (!root) { | |
| 50 reader->SetContentUrl(GURL()); | |
| 51 return std::move(reader); | |
| 52 } | |
| 53 | |
| 54 root->ResolveToContentUrl( | |
| 55 path, base::Bind(&ArcDocumentsProviderFileStreamReader::SetContentUrl, | |
| 56 reader->GetWeakPtr())); | |
| 57 return std::move(reader); | |
| 42 } | 58 } |
| 43 | 59 |
| 44 std::unique_ptr<storage::FileStreamWriter> | 60 std::unique_ptr<storage::FileStreamWriter> |
| 45 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( | 61 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( |
| 46 const storage::FileSystemURL& url, | 62 const storage::FileSystemURL& url, |
| 47 int64_t offset, | 63 int64_t offset, |
| 48 storage::FileSystemContext* context) { | 64 storage::FileSystemContext* context) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 NOTREACHED(); // Read-only file system. | 66 NOTREACHED(); // Read-only file system. |
| 51 return nullptr; | 67 return nullptr; |
| 52 } | 68 } |
| 53 | 69 |
| 54 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( | 70 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( |
| 55 storage::FileSystemType type) { | 71 storage::FileSystemType type) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 72 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 57 NOTREACHED(); // Non-watchable file system. | 73 NOTREACHED(); // Non-watchable file system. |
| 58 return nullptr; | 74 return nullptr; |
| 59 } | 75 } |
| 60 | 76 |
| 61 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( | 77 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( |
|
hashimoto
2016/12/22 06:20:01
qq: When is this method used, and when is the File
Shuhei Takahashi
2017/01/05 08:45:40
I realized this function is never called by chrome
| |
| 62 const storage::FileSystemURL& url, | 78 const storage::FileSystemURL& url, |
| 63 const storage::URLCallback& callback) { | 79 const storage::URLCallback& callback) { |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 65 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 81 |
| 66 callback.Run(GURL()); | 82 base::FilePath path; |
| 83 ArcDocumentsProviderRoot* root = roots_.ParseAndLookup(url, &path); | |
| 84 if (!root) { | |
| 85 callback.Run(GURL()); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 root->ResolveToContentUrl( | |
| 90 path, base::Bind(&ArcDocumentsProviderBackendDelegate:: | |
| 91 GetRedirectURLForContentsWithContentUrl, | |
| 92 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 93 } | |
| 94 | |
| 95 void ArcDocumentsProviderBackendDelegate:: | |
| 96 GetRedirectURLForContentsWithContentUrl( | |
|
hashimoto
2016/12/22 06:20:01
nit: "GetRedirectURLFor..." sounds like this metho
Shuhei Takahashi
2017/01/05 08:45:40
Removed the unused function.
| |
| 97 const storage::URLCallback& callback, | |
| 98 const GURL& content_url) { | |
| 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 100 callback.Run(ArcUrlToExternalFileUrl(content_url)); | |
| 67 } | 101 } |
| 68 | 102 |
| 69 } // namespace arc | 103 } // namespace arc |
| OLD | NEW |