Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.cc

Issue 2511973003: Use ArcFileSystemInstance to access files on ARC. (Closed)
Patch Set: Fix unit_tests build, and rename file_system_util. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/arc_file_system_instance_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 file_system_instance_util {
13 13
14 namespace { 14 namespace {
15 15
16 void OnGetFileSize( 16 void OnGetFileSize(
17 const mojom::IntentHelperInstance::GetFileSizeCallback& callback, 17 const mojom::FileSystemInstance::GetFileSizeCallback& callback,
18 int64_t size) { 18 int64_t size) {
19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
20 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, 20 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
21 base::Bind(callback, size)); 21 base::Bind(callback, size));
22 } 22 }
23 23
24 void GetFileSizeOnUIThread( 24 void GetFileSizeOnUIThread(
25 const GURL& arc_url, 25 const GURL& arc_url,
26 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { 26 const mojom::FileSystemInstance::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::FileSystemInstance* file_system_instance =
35 arc_bridge_service->intent_helper()->GetInstanceForMethod("GetFileSize", 35 arc_bridge_service->file_system()->GetInstanceForMethod("GetFileSize", 1);
36 15); 36 if (!file_system_instance) {
37 if (!intent_helper_instance) { 37 LOG(ERROR) << "Failed to get FileSystemInstance.";
38 LOG(ERROR) << "Failed to get IntentHelperInstance.";
39 OnGetFileSize(callback, -1); 38 OnGetFileSize(callback, -1);
40 return; 39 return;
41 } 40 }
42 intent_helper_instance->GetFileSize(arc_url.spec(), 41 file_system_instance->GetFileSize(arc_url.spec(),
43 base::Bind(&OnGetFileSize, callback)); 42 base::Bind(&OnGetFileSize, callback));
44 } 43 }
45 44
46 void OnOpenFileToRead( 45 void OnOpenFileToRead(
47 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback, 46 const mojom::FileSystemInstance::OpenFileToReadCallback& callback,
48 mojo::ScopedHandle handle) { 47 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(
55 const GURL& arc_url, 54 const GURL& arc_url,
56 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { 55 const mojom::FileSystemInstance::OpenFileToReadCallback& callback) {
57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
58 auto* arc_bridge_service = arc::ArcBridgeService::Get(); 57 auto* arc_bridge_service = arc::ArcBridgeService::Get();
59 if (!arc_bridge_service) { 58 if (!arc_bridge_service) {
60 LOG(ERROR) << "Failed to get ArcBridgeService."; 59 LOG(ERROR) << "Failed to get ArcBridgeService.";
61 OnOpenFileToRead(callback, mojo::ScopedHandle()); 60 OnOpenFileToRead(callback, mojo::ScopedHandle());
62 return; 61 return;
63 } 62 }
64 mojom::IntentHelperInstance* intent_helper_instance = 63 mojom::FileSystemInstance* file_system_instance =
65 arc_bridge_service->intent_helper()->GetInstanceForMethod( 64 arc_bridge_service->file_system()->GetInstanceForMethod("OpenFileToRead",
66 "OpenFileToRead", 15); 65 1);
67 if (!intent_helper_instance) { 66 if (!file_system_instance) {
68 LOG(ERROR) << "Failed to get IntentHelperInstance."; 67 LOG(ERROR) << "Failed to get FileSystemInstance.";
69 OnOpenFileToRead(callback, mojo::ScopedHandle()); 68 OnOpenFileToRead(callback, mojo::ScopedHandle());
70 return; 69 return;
71 } 70 }
72 intent_helper_instance->OpenFileToRead( 71 file_system_instance->OpenFileToRead(arc_url.spec(),
73 arc_url.spec(), base::Bind(&OnOpenFileToRead, callback)); 72 base::Bind(&OnOpenFileToRead, callback));
74 } 73 }
75 74
76 } // namespace 75 } // namespace
77 76
78 void GetFileSizeOnIOThread( 77 void GetFileSizeOnIOThread(
79 const GURL& arc_url, 78 const GURL& arc_url,
80 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) { 79 const mojom::FileSystemInstance::GetFileSizeCallback& callback) {
81 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
82 content::BrowserThread::PostTask( 81 content::BrowserThread::PostTask(
83 content::BrowserThread::UI, FROM_HERE, 82 content::BrowserThread::UI, FROM_HERE,
84 base::Bind(&GetFileSizeOnUIThread, arc_url, callback)); 83 base::Bind(&GetFileSizeOnUIThread, arc_url, callback));
85 } 84 }
86 85
87 void OpenFileToReadOnIOThread( 86 void OpenFileToReadOnIOThread(
88 const GURL& arc_url, 87 const GURL& arc_url,
89 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) { 88 const mojom::FileSystemInstance::OpenFileToReadCallback& callback) {
90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
91 content::BrowserThread::PostTask( 90 content::BrowserThread::PostTask(
92 content::BrowserThread::UI, FROM_HERE, 91 content::BrowserThread::UI, FROM_HERE,
93 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback)); 92 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback));
94 } 93 }
95 94
96 } // namespace intent_helper_util 95 } // namespace file_system_instance_util
97 96
98 } // namespace arc 97 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698