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 std::unique_ptr<ArcDocumentsProviderFileStreamReader> reader = |
|
hidehiko
2016/12/18 14:29:18
Optional: I'd recommend to use "auto", because of
Shuhei Takahashi
2016/12/19 03:05:56
Sure, changed to use auto.
| |
| 46 base::MakeUnique<ArcDocumentsProviderFileStreamReader>(offset); | |
| 47 | |
| 48 base::FilePath path; | |
| 49 ArcDocumentsProviderRoot* root = roots_.ParseAndLookup(url, &path); | |
| 50 if (!root) { | |
| 51 reader->SetContentUrl(GURL()); | |
| 52 return std::move(reader); | |
|
Luis Héctor Chávez
2016/12/17 00:05:26
Huh, why did the pessimizing move warning not trig
Shuhei Takahashi
2016/12/17 00:23:09
I'm not sure why, but returning std::unique_ptr<De
hidehiko
2016/12/18 14:29:18
IIUC, it's C++11 spec about copy elision.
cf) htt
Shuhei Takahashi
2016/12/19 03:05:55
I know that spec but I was wondering why gcc 5.x a
| |
| 53 } | |
| 54 | |
| 55 root->ResolveToContentUrl( | |
| 56 path, base::Bind(&ArcDocumentsProviderFileStreamReader::SetContentUrl, | |
| 57 reader->GetWeakPtr())); | |
| 58 return std::move(reader); | |
| 42 } | 59 } |
| 43 | 60 |
| 44 std::unique_ptr<storage::FileStreamWriter> | 61 std::unique_ptr<storage::FileStreamWriter> |
| 45 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( | 62 ArcDocumentsProviderBackendDelegate::CreateFileStreamWriter( |
| 46 const storage::FileSystemURL& url, | 63 const storage::FileSystemURL& url, |
| 47 int64_t offset, | 64 int64_t offset, |
| 48 storage::FileSystemContext* context) { | 65 storage::FileSystemContext* context) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 NOTREACHED(); // Read-only file system. | 67 NOTREACHED(); // Read-only file system. |
| 51 return nullptr; | 68 return nullptr; |
| 52 } | 69 } |
| 53 | 70 |
| 54 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( | 71 storage::WatcherManager* ArcDocumentsProviderBackendDelegate::GetWatcherManager( |
| 55 storage::FileSystemType type) { | 72 storage::FileSystemType type) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 57 NOTREACHED(); // Non-watchable file system. | 74 NOTREACHED(); // Non-watchable file system. |
| 58 return nullptr; | 75 return nullptr; |
| 59 } | 76 } |
| 60 | 77 |
| 61 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( | 78 void ArcDocumentsProviderBackendDelegate::GetRedirectURLForContents( |
| 62 const storage::FileSystemURL& url, | 79 const storage::FileSystemURL& url, |
| 63 const storage::URLCallback& callback) { | 80 const storage::URLCallback& callback) { |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 65 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 82 |
| 66 callback.Run(GURL()); | 83 base::FilePath path; |
| 84 ArcDocumentsProviderRoot* root = roots_.ParseAndLookup(url, &path); | |
| 85 if (!root) { | |
| 86 callback.Run(GURL()); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 root->ResolveToContentUrl( | |
| 91 path, base::Bind(&ArcDocumentsProviderBackendDelegate:: | |
| 92 GetRedirectURLForContentsWithContentUrl, | |
| 93 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 94 } | |
| 95 | |
| 96 void ArcDocumentsProviderBackendDelegate:: | |
| 97 GetRedirectURLForContentsWithContentUrl( | |
| 98 const storage::URLCallback& callback, | |
| 99 const GURL& content_url) { | |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 101 callback.Run(ArcUrlToExternalFileUrl(content_url)); | |
| 67 } | 102 } |
| 68 | 103 |
| 69 } // namespace arc | 104 } // namespace arc |
| OLD | NEW |