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

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

Issue 2467213002: arc: Implement Read and GetFileSize for ARC content file system (Closed)
Patch Set: 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
(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 if (!intent_helper_instance) {
37 LOG(ERROR) << "Failed to get IntentHelperInstance.";
38 OnGetFileSize(callback, -1);
39 return;
40 }
41 intent_helper_instance->GetFileSize(arc_url.spec(),
42 base::Bind(&OnGetFileSize, callback));
43 }
44
45 void OnOpenFileToRead(
46 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback,
47 mojo::ScopedHandle handle) {
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
50 base::Bind(callback, base::Passed(&handle)));
51 }
52
53 void OpenFileToReadOnUIThread(
54 const GURL& arc_url,
55 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 auto* arc_bridge_service = arc::ArcBridgeService::Get();
58 if (!arc_bridge_service) {
59 LOG(ERROR) << "Failed to get ArcBridgeService.";
60 OnOpenFileToRead(callback, mojo::ScopedHandle());
61 return;
62 }
63 mojom::IntentHelperInstance* intent_helper_instance =
64 arc_bridge_service->intent_helper()->GetInstanceForMethod(
65 "OpenFileToRead");
66 if (!intent_helper_instance) {
67 LOG(ERROR) << "Failed to get IntentHelperInstance.";
68 OnOpenFileToRead(callback, mojo::ScopedHandle());
69 return;
70 }
71 intent_helper_instance->OpenFileToRead(
72 arc_url.spec(), base::Bind(&OnOpenFileToRead, callback));
73 }
74
75 } // namespace
76
77 void GetFileSizeOnIOThread(
78 const GURL& arc_url,
79 const mojom::IntentHelperInstance::GetFileSizeCallback& callback) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
81 content::BrowserThread::PostTask(
82 content::BrowserThread::UI, FROM_HERE,
83 base::Bind(&GetFileSizeOnUIThread, arc_url, callback));
84 }
85
86 void OpenFileToReadOnIOThread(
87 const GURL& arc_url,
88 const mojom::IntentHelperInstance::OpenFileToReadCallback& callback) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
90 content::BrowserThread::PostTask(
91 content::BrowserThread::UI, FROM_HERE,
92 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback));
93 }
94
95 } // namespace intent_helper_util
96
97 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/intent_helper_util.h ('k') | chrome/browser/ui/ash/chrome_shell_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698