Chromium Code Reviews| 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 void OnGetFileSize(const GetFileSizeCallback& callback, int64_t size) { |
| 17 const mojom::IntentHelperInstance::GetFileSizeCallback& callback, | |
| 18 int64_t size) { | |
| 19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 17 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 20 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 18 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 21 base::Bind(callback, size)); | 19 base::Bind(callback, size)); |
| 22 } | 20 } |
| 23 | 21 |
| 24 void GetFileSizeOnUIThread( | 22 void GetFileSizeOnUIThread(const GURL& arc_url, |
| 25 const GURL& arc_url, | 23 const GetFileSizeCallback& callback) { |
| 26 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { | |
| 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 28 auto* arc_bridge_service = arc::ArcBridgeService::Get(); | 25 auto* arc_bridge_service = arc::ArcBridgeService::Get(); |
| 29 if (!arc_bridge_service) { | 26 if (!arc_bridge_service) { |
| 30 LOG(ERROR) << "Failed to get ArcBridgeService."; | 27 LOG(ERROR) << "Failed to get ArcBridgeService."; |
| 31 OnGetFileSize(callback, -1); | 28 OnGetFileSize(callback, -1); |
| 32 return; | 29 return; |
| 33 } | 30 } |
| 34 mojom::IntentHelperInstance* intent_helper_instance = | 31 mojom::IntentHelperInstance* intent_helper_instance = |
| 35 arc_bridge_service->intent_helper()->GetInstanceForMethod("GetFileSize", | 32 arc_bridge_service->intent_helper()->GetInstanceForMethod( |
| 36 15); | 33 "GetFileSizeDeprecated", 15); |
|
Yusuke Sato
2016/11/21 16:52:30
nit: not your fault, but can you name the constant
Yusuke Sato
2016/11/21 17:49:01
sorry, typo. I meant 'constexpr uint32_t kXXX'.
Shuhei Takahashi
2016/11/22 08:55:42
Done.
| |
| 37 if (!intent_helper_instance) { | 34 if (!intent_helper_instance) { |
| 38 LOG(ERROR) << "Failed to get IntentHelperInstance."; | 35 LOG(ERROR) << "Failed to get IntentHelperInstance."; |
| 39 OnGetFileSize(callback, -1); | 36 OnGetFileSize(callback, -1); |
| 40 return; | 37 return; |
| 41 } | 38 } |
| 42 intent_helper_instance->GetFileSize(arc_url.spec(), | 39 intent_helper_instance->GetFileSizeDeprecated( |
| 43 base::Bind(&OnGetFileSize, callback)); | 40 arc_url.spec(), base::Bind(&OnGetFileSize, callback)); |
| 44 } | 41 } |
| 45 | 42 |
| 46 void OnOpenFileToRead( | 43 void OnOpenFileToRead(const OpenFileToReadCallback& callback, |
| 47 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback, | 44 mojo::ScopedHandle handle) { |
| 48 mojo::ScopedHandle handle) { | |
| 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 50 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 46 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 51 base::Bind(callback, base::Passed(&handle))); | 47 base::Bind(callback, base::Passed(&handle))); |
| 52 } | 48 } |
| 53 | 49 |
| 54 void OpenFileToReadOnUIThread( | 50 void OpenFileToReadOnUIThread(const GURL& arc_url, |
| 55 const GURL& arc_url, | 51 const OpenFileToReadCallback& callback) { |
| 56 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { | |
| 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 58 auto* arc_bridge_service = arc::ArcBridgeService::Get(); | 53 auto* arc_bridge_service = arc::ArcBridgeService::Get(); |
| 59 if (!arc_bridge_service) { | 54 if (!arc_bridge_service) { |
| 60 LOG(ERROR) << "Failed to get ArcBridgeService."; | 55 LOG(ERROR) << "Failed to get ArcBridgeService."; |
| 61 OnOpenFileToRead(callback, mojo::ScopedHandle()); | 56 OnOpenFileToRead(callback, mojo::ScopedHandle()); |
| 62 return; | 57 return; |
| 63 } | 58 } |
| 64 mojom::IntentHelperInstance* intent_helper_instance = | 59 mojom::IntentHelperInstance* intent_helper_instance = |
| 65 arc_bridge_service->intent_helper()->GetInstanceForMethod( | 60 arc_bridge_service->intent_helper()->GetInstanceForMethod( |
| 66 "OpenFileToRead", 15); | 61 "OpenFileToReadDeprecated", 15); |
|
Yusuke Sato
2016/11/21 16:52:30
same
Shuhei Takahashi
2016/11/22 08:55:42
Done.
| |
| 67 if (!intent_helper_instance) { | 62 if (!intent_helper_instance) { |
| 68 LOG(ERROR) << "Failed to get IntentHelperInstance."; | 63 LOG(ERROR) << "Failed to get IntentHelperInstance."; |
| 69 OnOpenFileToRead(callback, mojo::ScopedHandle()); | 64 OnOpenFileToRead(callback, mojo::ScopedHandle()); |
| 70 return; | 65 return; |
| 71 } | 66 } |
| 72 intent_helper_instance->OpenFileToRead( | 67 intent_helper_instance->OpenFileToReadDeprecated( |
| 73 arc_url.spec(), base::Bind(&OnOpenFileToRead, callback)); | 68 arc_url.spec(), base::Bind(&OnOpenFileToRead, callback)); |
| 74 } | 69 } |
| 75 | 70 |
| 76 } // namespace | 71 } // namespace |
| 77 | 72 |
| 78 void GetFileSizeOnIOThread( | 73 void GetFileSizeOnIOThread(const GURL& arc_url, |
| 79 const GURL& arc_url, | 74 const GetFileSizeCallback& callback) { |
| 80 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { | |
| 81 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 82 content::BrowserThread::PostTask( | 76 content::BrowserThread::PostTask( |
| 83 content::BrowserThread::UI, FROM_HERE, | 77 content::BrowserThread::UI, FROM_HERE, |
| 84 base::Bind(&GetFileSizeOnUIThread, arc_url, callback)); | 78 base::Bind(&GetFileSizeOnUIThread, arc_url, callback)); |
| 85 } | 79 } |
| 86 | 80 |
| 87 void OpenFileToReadOnIOThread( | 81 void OpenFileToReadOnIOThread(const GURL& arc_url, |
| 88 const GURL& arc_url, | 82 const OpenFileToReadCallback& callback) { |
| 89 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { | |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 91 content::BrowserThread::PostTask( | 84 content::BrowserThread::PostTask( |
| 92 content::BrowserThread::UI, FROM_HERE, | 85 content::BrowserThread::UI, FROM_HERE, |
| 93 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback)); | 86 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback)); |
| 94 } | 87 } |
| 95 | 88 |
| 96 } // namespace intent_helper_util | 89 } // namespace intent_helper_util |
| 97 | 90 |
| 98 } // namespace arc | 91 } // namespace arc |
| OLD | NEW |