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