| 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_file_system_instance_util.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_u
til.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 #include <utility> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/optional.h" | |
| 12 #include "components/arc/arc_bridge_service.h" | |
| 13 #include "components/arc/arc_service_manager.h" | 7 #include "components/arc/arc_service_manager.h" |
| 8 #include "components/arc/file_system/arc_file_system_operation_runner.h" |
| 14 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 15 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 16 | 11 |
| 17 #define GET_FILE_SYSTEM_INSTANCE(method_name) \ | |
| 18 (arc::ArcServiceManager::Get() \ | |
| 19 ? ARC_GET_INSTANCE_FOR_METHOD(arc::ArcServiceManager::Get() \ | |
| 20 ->arc_bridge_service() \ | |
| 21 ->file_system(), \ | |
| 22 method_name) \ | |
| 23 : nullptr) | |
| 24 | |
| 25 using content::BrowserThread; | 12 using content::BrowserThread; |
| 26 | 13 |
| 27 namespace arc { | 14 namespace arc { |
| 28 | 15 |
| 29 namespace file_system_instance_util { | 16 namespace file_system_operation_runner_util { |
| 30 | 17 |
| 31 namespace { | 18 namespace { |
| 32 | 19 |
| 33 template <typename T> | 20 template <typename T> |
| 34 void PostToIOThread(const base::Callback<void(T)>& callback, T result) { | 21 void PostToIOThread(const base::Callback<void(T)>& callback, T result) { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 36 BrowserThread::PostTask( | 23 BrowserThread::PostTask( |
| 37 BrowserThread::IO, FROM_HERE, | 24 BrowserThread::IO, FROM_HERE, |
| 38 base::Bind(callback, base::Passed(std::move(result)))); | 25 base::Bind(callback, base::Passed(std::move(result)))); |
| 39 } | 26 } |
| 40 | 27 |
| 41 void GetFileSizeOnUIThread(const GURL& arc_url, | 28 void GetFileSizeOnUIThread(const GURL& url, |
| 42 const GetFileSizeCallback& callback) { | 29 const GetFileSizeCallback& callback) { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 44 auto* file_system_instance = GET_FILE_SYSTEM_INSTANCE(GetFileSize); | 31 auto* runner = |
| 45 if (!file_system_instance) { | 32 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 33 if (!runner) { |
| 46 callback.Run(-1); | 34 callback.Run(-1); |
| 47 return; | |
| 48 } | 35 } |
| 49 file_system_instance->GetFileSize(arc_url.spec(), callback); | 36 runner->GetFileSize(url, callback); |
| 50 } | 37 } |
| 51 | 38 |
| 52 void OpenFileToReadOnUIThread(const GURL& arc_url, | 39 void OpenFileToReadOnUIThread(const GURL& url, |
| 53 const OpenFileToReadCallback& callback) { | 40 const OpenFileToReadCallback& callback) { |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 55 auto* file_system_instance = GET_FILE_SYSTEM_INSTANCE(OpenFileToRead); | 42 auto* runner = |
| 56 if (!file_system_instance) { | 43 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 44 if (!runner) { |
| 57 callback.Run(mojo::ScopedHandle()); | 45 callback.Run(mojo::ScopedHandle()); |
| 58 return; | 46 return; |
| 59 } | 47 } |
| 60 file_system_instance->OpenFileToRead(arc_url.spec(), callback); | 48 runner->OpenFileToRead(url, callback); |
| 61 } | 49 } |
| 62 | 50 |
| 63 void GetDocumentOnUIThread(const std::string& authority, | 51 void GetDocumentOnUIThread(const std::string& authority, |
| 64 const std::string& document_id, | 52 const std::string& document_id, |
| 65 const GetDocumentCallback& callback) { | 53 const GetDocumentCallback& callback) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 67 auto* file_system_instance = GET_FILE_SYSTEM_INSTANCE(GetDocument); | 55 auto* runner = |
| 68 if (!file_system_instance) { | 56 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 57 if (!runner) { |
| 69 callback.Run(mojom::DocumentPtr()); | 58 callback.Run(mojom::DocumentPtr()); |
| 70 return; | 59 return; |
| 71 } | 60 } |
| 72 file_system_instance->GetDocument(authority, document_id, callback); | 61 runner->GetDocument(authority, document_id, callback); |
| 73 } | 62 } |
| 74 | 63 |
| 75 void GetChildDocumentsOnUIThread(const std::string& authority, | 64 void GetChildDocumentsOnUIThread(const std::string& authority, |
| 76 const std::string& parent_document_id, | 65 const std::string& parent_document_id, |
| 77 const GetChildDocumentsCallback& callback) { | 66 const GetChildDocumentsCallback& callback) { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 auto* file_system_instance = GET_FILE_SYSTEM_INSTANCE(GetChildDocuments); | 68 auto* runner = |
| 80 if (!file_system_instance) { | 69 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 70 if (!runner) { |
| 81 callback.Run(base::nullopt); | 71 callback.Run(base::nullopt); |
| 82 return; | 72 return; |
| 83 } | 73 } |
| 84 file_system_instance->GetChildDocuments(authority, parent_document_id, | 74 runner->GetChildDocuments(authority, parent_document_id, callback); |
| 85 callback); | |
| 86 } | 75 } |
| 87 | 76 |
| 88 } // namespace | 77 } // namespace |
| 89 | 78 |
| 90 void GetFileSizeOnIOThread(const GURL& arc_url, | 79 void GetFileSizeOnIOThread(const GURL& url, |
| 91 const GetFileSizeCallback& callback) { | 80 const GetFileSizeCallback& callback) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 93 BrowserThread::PostTask( | 82 BrowserThread::PostTask( |
| 94 BrowserThread::UI, FROM_HERE, | 83 BrowserThread::UI, FROM_HERE, |
| 95 base::Bind(&GetFileSizeOnUIThread, arc_url, | 84 base::Bind(&GetFileSizeOnUIThread, url, |
| 96 base::Bind(&PostToIOThread<int64_t>, callback))); | 85 base::Bind(&PostToIOThread<int64_t>, callback))); |
| 97 } | 86 } |
| 98 | 87 |
| 99 void OpenFileToReadOnIOThread(const GURL& arc_url, | 88 void OpenFileToReadOnIOThread(const GURL& url, |
| 100 const OpenFileToReadCallback& callback) { | 89 const OpenFileToReadCallback& callback) { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 102 BrowserThread::PostTask( | 91 BrowserThread::PostTask( |
| 103 BrowserThread::UI, FROM_HERE, | 92 BrowserThread::UI, FROM_HERE, |
| 104 base::Bind(&OpenFileToReadOnUIThread, arc_url, | 93 base::Bind(&OpenFileToReadOnUIThread, url, |
| 105 base::Bind(&PostToIOThread<mojo::ScopedHandle>, callback))); | 94 base::Bind(&PostToIOThread<mojo::ScopedHandle>, callback))); |
| 106 } | 95 } |
| 107 | 96 |
| 108 void GetDocumentOnIOThread(const std::string& authority, | 97 void GetDocumentOnIOThread(const std::string& authority, |
| 109 const std::string& document_id, | 98 const std::string& document_id, |
| 110 const GetDocumentCallback& callback) { | 99 const GetDocumentCallback& callback) { |
| 111 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 112 BrowserThread::PostTask( | 101 BrowserThread::PostTask( |
| 113 BrowserThread::UI, FROM_HERE, | 102 BrowserThread::UI, FROM_HERE, |
| 114 base::Bind(&GetDocumentOnUIThread, authority, document_id, | 103 base::Bind(&GetDocumentOnUIThread, authority, document_id, |
| 115 base::Bind(&PostToIOThread<mojom::DocumentPtr>, callback))); | 104 base::Bind(&PostToIOThread<mojom::DocumentPtr>, callback))); |
| 116 } | 105 } |
| 117 | 106 |
| 118 void GetChildDocumentsOnIOThread(const std::string& authority, | 107 void GetChildDocumentsOnIOThread(const std::string& authority, |
| 119 const std::string& parent_document_id, | 108 const std::string& parent_document_id, |
| 120 const GetChildDocumentsCallback& callback) { | 109 const GetChildDocumentsCallback& callback) { |
| 121 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 122 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
| 123 BrowserThread::UI, FROM_HERE, | 112 BrowserThread::UI, FROM_HERE, |
| 124 base::Bind( | 113 base::Bind( |
| 125 &GetChildDocumentsOnUIThread, authority, parent_document_id, | 114 &GetChildDocumentsOnUIThread, authority, parent_document_id, |
| 126 base::Bind( | 115 base::Bind( |
| 127 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>, | 116 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>, |
| 128 callback))); | 117 callback))); |
| 129 } | 118 } |
| 130 | 119 |
| 131 } // namespace file_system_instance_util | 120 } // namespace file_system_operation_runner_util |
| 132 | 121 |
| 133 } // namespace arc | 122 } // namespace arc |
| OLD | NEW |