| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/arc/fileapi/intent_helper_util.h" |
| 6 |
| 7 #include "components/arc/arc_bridge_service.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 |
| 10 namespace arc { |
| 11 |
| 12 namespace intent_helper_util { |
| 13 |
| 14 namespace { |
| 15 |
| 16 void OnGetFileSize( |
| 17 const mojom::IntentHelperInstance::GetFileSizeCallback& callback, |
| 18 int64_t size) { |
| 19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 20 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 21 base::Bind(callback, size)); |
| 22 } |
| 23 |
| 24 void GetFileSizeOnUIThread( |
| 25 const GURL& arc_url, |
| 26 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { |
| 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 28 auto* arc_bridge_service = arc::ArcBridgeService::Get(); |
| 29 if (!arc_bridge_service) { |
| 30 LOG(ERROR) << "Failed to get ArcBridgeService."; |
| 31 OnGetFileSize(callback, -1); |
| 32 return; |
| 33 } |
| 34 mojom::IntentHelperInstance* intent_helper_instance = |
| 35 arc_bridge_service->intent_helper()->GetInstanceForMethod("GetFileSize", |
| 36 15); |
| 37 if (!intent_helper_instance) { |
| 38 LOG(ERROR) << "Failed to get IntentHelperInstance."; |
| 39 OnGetFileSize(callback, -1); |
| 40 return; |
| 41 } |
| 42 intent_helper_instance->GetFileSize(arc_url.spec(), |
| 43 base::Bind(&OnGetFileSize, callback)); |
| 44 } |
| 45 |
| 46 void OnOpenFileToRead( |
| 47 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback, |
| 48 mojo::ScopedHandle handle) { |
| 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 50 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 51 base::Bind(callback, base::Passed(&handle))); |
| 52 } |
| 53 |
| 54 void OpenFileToReadOnUIThread( |
| 55 const GURL& arc_url, |
| 56 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { |
| 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 58 auto* arc_bridge_service = arc::ArcBridgeService::Get(); |
| 59 if (!arc_bridge_service) { |
| 60 LOG(ERROR) << "Failed to get ArcBridgeService."; |
| 61 OnOpenFileToRead(callback, mojo::ScopedHandle()); |
| 62 return; |
| 63 } |
| 64 mojom::IntentHelperInstance* intent_helper_instance = |
| 65 arc_bridge_service->intent_helper()->GetInstanceForMethod( |
| 66 "OpenFileToRead", 15); |
| 67 if (!intent_helper_instance) { |
| 68 LOG(ERROR) << "Failed to get IntentHelperInstance."; |
| 69 OnOpenFileToRead(callback, mojo::ScopedHandle()); |
| 70 return; |
| 71 } |
| 72 intent_helper_instance->OpenFileToRead( |
| 73 arc_url.spec(), base::Bind(&OnOpenFileToRead, callback)); |
| 74 } |
| 75 |
| 76 } // namespace |
| 77 |
| 78 void GetFileSizeOnIOThread( |
| 79 const GURL& arc_url, |
| 80 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { |
| 81 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 82 content::BrowserThread::PostTask( |
| 83 content::BrowserThread::UI, FROM_HERE, |
| 84 base::Bind(&GetFileSizeOnUIThread, arc_url, callback)); |
| 85 } |
| 86 |
| 87 void OpenFileToReadOnIOThread( |
| 88 const GURL& arc_url, |
| 89 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 91 content::BrowserThread::PostTask( |
| 92 content::BrowserThread::UI, FROM_HERE, |
| 93 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback)); |
| 94 } |
| 95 |
| 96 } // namespace intent_helper_util |
| 97 |
| 98 } // namespace arc |
| OLD | NEW |