OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.h
" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h
" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/optional.h" | 12 #include "base/optional.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "chrome/browser/chromeos/arc/arc_util.h" | 14 #include "chrome/browser/chromeos/arc/arc_util.h" |
15 #include "components/arc/arc_bridge_service.h" | 15 #include "components/arc/arc_bridge_service.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
21 namespace arc { | 21 namespace arc { |
22 | 22 |
23 namespace { | |
24 | |
25 // TODO(nya): Use typemaps. | |
26 ArcFileSystemOperationRunner::ChangeType FromMojoChangeType( | |
27 mojom::ChangeType type) { | |
28 switch (type) { | |
29 case mojom::ChangeType::CHANGED: | |
30 return ArcFileSystemOperationRunner::ChangeType::CHANGED; | |
31 case mojom::ChangeType::DELETED: | |
32 return ArcFileSystemOperationRunner::ChangeType::DELETED; | |
33 } | |
34 NOTREACHED(); | |
35 return ArcFileSystemOperationRunner::ChangeType::CHANGED; | |
36 } | |
37 | |
38 } // namespace | |
39 | |
40 // static | 23 // static |
41 const char ArcFileSystemOperationRunner::kArcServiceName[] = | 24 const char ArcFileSystemOperationRunner::kArcServiceName[] = |
42 "arc::ArcFileSystemOperationRunner"; | 25 "arc::ArcFileSystemOperationRunner"; |
43 | 26 |
44 // static | 27 // static |
45 std::unique_ptr<ArcFileSystemOperationRunner> | 28 std::unique_ptr<ArcFileSystemOperationRunner> |
46 ArcFileSystemOperationRunner::CreateForTesting( | 29 ArcFileSystemOperationRunner::CreateForTesting( |
47 ArcBridgeService* bridge_service) { | 30 ArcBridgeService* bridge_service) { |
48 // We can't use base::MakeUnique() here because we are calling a private | 31 // We can't use base::MakeUnique() here because we are calling a private |
49 // constructor. | 32 // constructor. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 arc_bridge_service()->file_system(), AddWatcher); | 221 arc_bridge_service()->file_system(), AddWatcher); |
239 if (!file_system_instance) { | 222 if (!file_system_instance) { |
240 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 223 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
241 base::Bind(callback, false)); | 224 base::Bind(callback, false)); |
242 return; | 225 return; |
243 } | 226 } |
244 file_system_instance->RemoveWatcher(watcher_id, callback); | 227 file_system_instance->RemoveWatcher(watcher_id, callback); |
245 } | 228 } |
246 | 229 |
247 void ArcFileSystemOperationRunner::OnDocumentChanged(int64_t watcher_id, | 230 void ArcFileSystemOperationRunner::OnDocumentChanged(int64_t watcher_id, |
248 mojom::ChangeType type) { | 231 ChangeType type) { |
249 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
250 auto iter = watcher_callbacks_.find(watcher_id); | 233 auto iter = watcher_callbacks_.find(watcher_id); |
251 if (iter == watcher_callbacks_.end()) { | 234 if (iter == watcher_callbacks_.end()) { |
252 // This may happen in a race condition with documents changes and | 235 // This may happen in a race condition with documents changes and |
253 // RemoveWatcher(). | 236 // RemoveWatcher(). |
254 return; | 237 return; |
255 } | 238 } |
256 WatcherCallback watcher_callback = iter->second; | 239 WatcherCallback watcher_callback = iter->second; |
257 watcher_callback.Run(FromMojoChangeType(type)); | 240 watcher_callback.Run(type); |
258 } | 241 } |
259 | 242 |
260 void ArcFileSystemOperationRunner::OnArcPlayStoreEnabledChanged(bool enabled) { | 243 void ArcFileSystemOperationRunner::OnArcPlayStoreEnabledChanged(bool enabled) { |
261 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 244 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
262 OnStateChanged(); | 245 OnStateChanged(); |
263 } | 246 } |
264 | 247 |
265 void ArcFileSystemOperationRunner::OnInstanceReady() { | 248 void ArcFileSystemOperationRunner::OnInstanceReady() { |
266 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 249 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
267 auto* file_system_instance = | 250 auto* file_system_instance = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 deferred_operations.swap(deferred_operations_); | 302 deferred_operations.swap(deferred_operations_); |
320 for (const base::Closure& operation : deferred_operations) { | 303 for (const base::Closure& operation : deferred_operations) { |
321 operation.Run(); | 304 operation.Run(); |
322 } | 305 } |
323 | 306 |
324 // No deferred operations should be left at this point. | 307 // No deferred operations should be left at this point. |
325 DCHECK(deferred_operations_.empty()); | 308 DCHECK(deferred_operations_.empty()); |
326 } | 309 } |
327 | 310 |
328 } // namespace arc | 311 } // namespace arc |
OLD | NEW |