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

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

Powered by Google App Engine
This is Rietveld 408576698