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

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

Issue 2552223002: Remove explicit singletonness of ArcBridgeService part 2. (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_content_file_system_file_stream_reader_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/arc_file_system_instance_util.h" 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h"
6 6
7 #include <string>
8
7 #include "components/arc/arc_bridge_service.h" 9 #include "components/arc/arc_bridge_service.h"
10 #include "components/arc/arc_service_manager.h"
8 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
9 #include "url/gurl.h" 12 #include "url/gurl.h"
10 13
11 namespace arc { 14 namespace arc {
12 15
13 namespace file_system_instance_util { 16 namespace file_system_instance_util {
14 17
15 namespace { 18 namespace {
16 19
17 constexpr uint32_t kGetFileSizeVersion = 1; 20 constexpr uint32_t kGetFileSizeVersion = 1;
18 constexpr uint32_t kOpenFileToReadVersion = 1; 21 constexpr uint32_t kOpenFileToReadVersion = 1;
19 22
23 // Returns FileSystemInstance for the given |min_version|, if found.
24 // Otherwise, nullptr.
25 mojom::FileSystemInstance* GetFileSystemInstance(
26 const std::string& method_name_for_logging,
27 uint32_t min_version) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
29 auto* arc_service_manager = arc::ArcServiceManager::Get();
30 if (!arc_service_manager) {
31 LOG(ERROR) << "Failed to get ArcServiceManager.";
32 return nullptr;
33 }
34 mojom::FileSystemInstance* file_system =
35 arc_service_manager->arc_bridge_service()
36 ->file_system()
37 ->GetInstanceForMethod(method_name_for_logging, min_version);
38 LOG_IF(ERROR, !file_system) << "Failed to get FileSystemInstance.";
Luis Héctor Chávez 2016/12/06 18:44:49 GetInstanceForMethod already logs on failure. Remo
hidehiko 2016/12/06 18:59:50 Oh, right! Done.
39 return file_system;
40 }
41
20 void OnGetFileSize(const GetFileSizeCallback& callback, int64_t size) { 42 void OnGetFileSize(const GetFileSizeCallback& callback, int64_t size) {
21 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
22 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, 44 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
23 base::Bind(callback, size)); 45 base::Bind(callback, size));
24 } 46 }
25 47
26 void GetFileSizeOnUIThread(const GURL& arc_url, 48 void GetFileSizeOnUIThread(const GURL& arc_url,
27 const GetFileSizeCallback& callback) { 49 const GetFileSizeCallback& callback) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
29 auto* arc_bridge_service = arc::ArcBridgeService::Get(); 51 auto* file_system_instance =
30 if (!arc_bridge_service) { 52 GetFileSystemInstance("GetFileSize", kGetFileSizeVersion);
31 LOG(ERROR) << "Failed to get ArcBridgeService."; 53 if (!file_system_instance) {
32 OnGetFileSize(callback, -1); 54 OnGetFileSize(callback, -1);
33 return; 55 return;
34 } 56 }
35 mojom::FileSystemInstance* file_system_instance =
36 arc_bridge_service->file_system()->GetInstanceForMethod(
37 "GetFileSize", kGetFileSizeVersion);
38 if (!file_system_instance) {
39 LOG(ERROR) << "Failed to get FileSystemInstance.";
Luis Héctor Chávez 2016/12/06 18:44:49 Ah I see where the log came from.
40 OnGetFileSize(callback, -1);
41 return;
42 }
43 file_system_instance->GetFileSize(arc_url.spec(), 57 file_system_instance->GetFileSize(arc_url.spec(),
44 base::Bind(&OnGetFileSize, callback)); 58 base::Bind(&OnGetFileSize, callback));
45 } 59 }
46 60
47 void OnOpenFileToRead(const OpenFileToReadCallback& callback, 61 void OnOpenFileToRead(const OpenFileToReadCallback& callback,
48 mojo::ScopedHandle handle) { 62 mojo::ScopedHandle handle) {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, 64 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
51 base::Bind(callback, base::Passed(&handle))); 65 base::Bind(callback, base::Passed(&handle)));
52 } 66 }
53 67
54 void OpenFileToReadOnUIThread(const GURL& arc_url, 68 void OpenFileToReadOnUIThread(const GURL& arc_url,
55 const OpenFileToReadCallback& callback) { 69 const OpenFileToReadCallback& callback) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 auto* arc_bridge_service = arc::ArcBridgeService::Get(); 71 auto* file_system_instance =
58 if (!arc_bridge_service) { 72 GetFileSystemInstance("OpenFileToRead", kOpenFileToReadVersion);
59 LOG(ERROR) << "Failed to get ArcBridgeService."; 73 if (!file_system_instance) {
60 OnOpenFileToRead(callback, mojo::ScopedHandle()); 74 OnOpenFileToRead(callback, mojo::ScopedHandle());
61 return; 75 return;
62 } 76 }
63 mojom::FileSystemInstance* file_system_instance =
64 arc_bridge_service->file_system()->GetInstanceForMethod(
65 "OpenFileToRead", kOpenFileToReadVersion);
66 if (!file_system_instance) {
67 LOG(ERROR) << "Failed to get FileSystemInstance.";
68 OnOpenFileToRead(callback, mojo::ScopedHandle());
69 return;
70 }
71 file_system_instance->OpenFileToRead(arc_url.spec(), 77 file_system_instance->OpenFileToRead(arc_url.spec(),
72 base::Bind(&OnOpenFileToRead, callback)); 78 base::Bind(&OnOpenFileToRead, callback));
73 } 79 }
74 80
75 } // namespace 81 } // namespace
76 82
77 void GetFileSizeOnIOThread(const GURL& arc_url, 83 void GetFileSizeOnIOThread(const GURL& arc_url,
78 const GetFileSizeCallback& callback) { 84 const GetFileSizeCallback& callback) {
79 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
80 content::BrowserThread::PostTask( 86 content::BrowserThread::PostTask(
81 content::BrowserThread::UI, FROM_HERE, 87 content::BrowserThread::UI, FROM_HERE,
82 base::Bind(&GetFileSizeOnUIThread, arc_url, callback)); 88 base::Bind(&GetFileSizeOnUIThread, arc_url, callback));
83 } 89 }
84 90
85 void OpenFileToReadOnIOThread(const GURL& arc_url, 91 void OpenFileToReadOnIOThread(const GURL& arc_url,
86 const OpenFileToReadCallback& callback) { 92 const OpenFileToReadCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 93 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
88 content::BrowserThread::PostTask( 94 content::BrowserThread::PostTask(
89 content::BrowserThread::UI, FROM_HERE, 95 content::BrowserThread::UI, FROM_HERE,
90 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback)); 96 base::Bind(&OpenFileToReadOnUIThread, arc_url, callback));
91 } 97 }
92 98
93 } // namespace file_system_instance_util 99 } // namespace file_system_instance_util
94 100
95 } // namespace arc 101 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_content_file_system_file_stream_reader_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698