| 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_operation_runner_u
til.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_u
til.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h
" | |
| 11 #include "components/arc/arc_service_manager.h" | 10 #include "components/arc/arc_service_manager.h" |
| 12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 13 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 14 | 13 |
| 15 using content::BrowserThread; | 14 using content::BrowserThread; |
| 16 | 15 |
| 17 namespace arc { | 16 namespace arc { |
| 18 | 17 |
| 19 namespace file_system_operation_runner_util { | 18 namespace file_system_operation_runner_util { |
| 20 | 19 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); | 78 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 80 if (!runner) { | 79 if (!runner) { |
| 81 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " | 80 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " |
| 82 << "File system operations are dropped."; | 81 << "File system operations are dropped."; |
| 83 callback.Run(base::nullopt); | 82 callback.Run(base::nullopt); |
| 84 return; | 83 return; |
| 85 } | 84 } |
| 86 runner->GetChildDocuments(authority, parent_document_id, callback); | 85 runner->GetChildDocuments(authority, parent_document_id, callback); |
| 87 } | 86 } |
| 88 | 87 |
| 88 void AddWatcherOnUIThread(const std::string& authority, |
| 89 const std::string& document_id, |
| 90 const WatcherCallback& watcher_callback, |
| 91 const AddWatcherCallback& callback) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 auto* runner = |
| 94 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 95 if (!runner) { |
| 96 callback.Run(-1); |
| 97 return; |
| 98 } |
| 99 runner->AddWatcher(authority, document_id, watcher_callback, callback); |
| 100 } |
| 101 |
| 102 void RemoveWatcherOnUIThread(int64_t watcher_id, |
| 103 const RemoveWatcherCallback& callback) { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 105 auto* runner = |
| 106 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); |
| 107 if (!runner) { |
| 108 callback.Run(false); |
| 109 return; |
| 110 } |
| 111 runner->RemoveWatcher(watcher_id, callback); |
| 112 } |
| 113 |
| 89 } // namespace | 114 } // namespace |
| 90 | 115 |
| 91 void GetFileSizeOnIOThread(const GURL& url, | 116 void GetFileSizeOnIOThread(const GURL& url, |
| 92 const GetFileSizeCallback& callback) { | 117 const GetFileSizeCallback& callback) { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 118 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 94 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| 95 BrowserThread::UI, FROM_HERE, | 120 BrowserThread::UI, FROM_HERE, |
| 96 base::Bind(&GetFileSizeOnUIThread, url, | 121 base::Bind(&GetFileSizeOnUIThread, url, |
| 97 base::Bind(&PostToIOThread<int64_t>, callback))); | 122 base::Bind(&PostToIOThread<int64_t>, callback))); |
| 98 } | 123 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 122 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 123 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 124 BrowserThread::UI, FROM_HERE, | 149 BrowserThread::UI, FROM_HERE, |
| 125 base::Bind( | 150 base::Bind( |
| 126 &GetChildDocumentsOnUIThread, authority, parent_document_id, | 151 &GetChildDocumentsOnUIThread, authority, parent_document_id, |
| 127 base::Bind( | 152 base::Bind( |
| 128 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>, | 153 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>, |
| 129 callback))); | 154 callback))); |
| 130 } | 155 } |
| 131 | 156 |
| 157 void AddWatcherOnIOThread(const std::string& authority, |
| 158 const std::string& document_id, |
| 159 const WatcherCallback& watcher_callback, |
| 160 const AddWatcherCallback& callback) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 162 BrowserThread::PostTask( |
| 163 BrowserThread::UI, FROM_HERE, |
| 164 base::Bind( |
| 165 &AddWatcherOnUIThread, authority, document_id, |
| 166 base::Bind(&PostToIOThread<ArcFileSystemOperationRunner::ChangeType>, |
| 167 watcher_callback), |
| 168 base::Bind(&PostToIOThread<int64_t>, callback))); |
| 169 } |
| 170 |
| 171 void RemoveWatcherOnIOThread(int64_t watcher_id, |
| 172 const RemoveWatcherCallback& callback) { |
| 173 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 174 BrowserThread::PostTask( |
| 175 BrowserThread::UI, FROM_HERE, |
| 176 base::Bind(&RemoveWatcherOnUIThread, watcher_id, |
| 177 base::Bind(&PostToIOThread<bool>, callback))); |
| 178 } |
| 179 |
| 132 } // namespace file_system_operation_runner_util | 180 } // namespace file_system_operation_runner_util |
| 133 | 181 |
| 134 } // namespace arc | 182 } // namespace arc |
| OLD | NEW |