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

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

Issue 2736603002: mediaview: Support watchers in ArcFileSystemOperationRunner. (Closed)
Patch Set: Created 3 years, 9 months 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_file_system_operation_runner_util.h ('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_operation_runner_u til.h" 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_u til.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h "
11 #include "components/arc/arc_service_manager.h" 10 #include "components/arc/arc_service_manager.h"
12 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
13 #include "url/gurl.h" 12 #include "url/gurl.h"
14 13
15 using content::BrowserThread; 14 using content::BrowserThread;
16 15
17 namespace arc { 16 namespace arc {
18 17
19 namespace file_system_operation_runner_util { 18 namespace file_system_operation_runner_util {
20 19
21 namespace { 20 namespace {
22 21
23 template <typename T> 22 template <typename T>
24 void PostToIOThread(const base::Callback<void(T)>& callback, T result) { 23 void PostToIOThread(const base::Callback<void(T)>& callback, T result) {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI); 24 DCHECK_CURRENTLY_ON(BrowserThread::UI);
26 BrowserThread::PostTask( 25 BrowserThread::PostTask(
27 BrowserThread::IO, FROM_HERE, 26 BrowserThread::IO, FROM_HERE,
28 base::Bind(callback, base::Passed(std::move(result)))); 27 base::Bind(callback, base::Passed(std::move(result))));
29 } 28 }
30 29
31 void GetFileSizeOnUIThread(const GURL& url, 30 void GetFileSizeOnUIThread(const GURL& url,
32 const GetFileSizeCallback& callback) { 31 const GetFileSizeCallback& callback) {
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(BrowserThread::UI);
34 auto* runner = 33 auto* runner =
35 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); 34 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
36 if (!runner) { 35 if (!runner) {
37 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " 36 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
38 << "File system operations are dropped."; 37 << "File system operations are dropped.";
39 callback.Run(-1); 38 callback.Run(-1);
40 return; 39 return;
41 } 40 }
42 runner->GetFileSize(url, callback); 41 runner->GetFileSize(url, callback);
43 } 42 }
44 43
45 void OpenFileToReadOnUIThread(const GURL& url, 44 void OpenFileToReadOnUIThread(const GURL& url,
46 const OpenFileToReadCallback& callback) { 45 const OpenFileToReadCallback& callback) {
47 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
48 auto* runner = 47 auto* runner =
49 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); 48 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
50 if (!runner) { 49 if (!runner) {
51 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " 50 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
52 << "File system operations are dropped."; 51 << "File system operations are dropped.";
53 callback.Run(mojo::ScopedHandle()); 52 callback.Run(mojo::ScopedHandle());
54 return; 53 return;
55 } 54 }
56 runner->OpenFileToRead(url, callback); 55 runner->OpenFileToRead(url, callback);
57 } 56 }
58 57
59 void GetDocumentOnUIThread(const std::string& authority, 58 void GetDocumentOnUIThread(const std::string& authority,
60 const std::string& document_id, 59 const std::string& document_id,
61 const GetDocumentCallback& callback) { 60 const GetDocumentCallback& callback) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 auto* runner = 62 auto* runner =
64 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); 63 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
65 if (!runner) { 64 if (!runner) {
66 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " 65 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
67 << "File system operations are dropped."; 66 << "File system operations are dropped.";
68 callback.Run(mojom::DocumentPtr()); 67 callback.Run(mojom::DocumentPtr());
69 return; 68 return;
70 } 69 }
71 runner->GetDocument(authority, document_id, callback); 70 runner->GetDocument(authority, document_id, callback);
72 } 71 }
73 72
74 void GetChildDocumentsOnUIThread(const std::string& authority, 73 void GetChildDocumentsOnUIThread(const std::string& authority,
75 const std::string& parent_document_id, 74 const std::string& parent_document_id,
76 const GetChildDocumentsCallback& callback) { 75 const GetChildDocumentsCallback& callback) {
77 DCHECK_CURRENTLY_ON(BrowserThread::UI); 76 DCHECK_CURRENTLY_ON(BrowserThread::UI);
78 auto* runner = 77 auto* runner =
79 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); 78 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
80 if (!runner) { 79 if (!runner) {
81 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " 80 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
82 << "File system operations are dropped."; 81 << "File system operations are dropped.";
83 callback.Run(base::nullopt); 82 callback.Run(base::nullopt);
84 return; 83 return;
85 } 84 }
86 runner->GetChildDocuments(authority, parent_document_id, callback); 85 runner->GetChildDocuments(authority, parent_document_id, callback);
87 } 86 }
88 87
88 void AddWatcherOnUIThread(const std::string& authority,
89 const std::string& document_id,
90 const WatcherCallback& watcher_callback,
91 const AddWatcherCallback& callback) {
92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
93 auto* runner =
94 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
95 if (!runner) {
96 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
97 << "File system operations are dropped.";
98 callback.Run(-1);
99 return;
100 }
101 runner->AddWatcher(authority, document_id, watcher_callback, callback);
102 }
103
104 void RemoveWatcherOnUIThread(int64_t watcher_id,
105 const RemoveWatcherCallback& callback) {
106 DCHECK_CURRENTLY_ON(BrowserThread::UI);
107 auto* runner =
108 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
109 if (!runner) {
110 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
111 << "File system operations are dropped.";
112 callback.Run(false);
113 return;
114 }
115 runner->RemoveWatcher(watcher_id, callback);
116 }
117
118 void AddObserverOnUIThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 auto* runner =
121 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
122 if (!runner) {
123 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
124 << "File system operations are dropped.";
125 return;
126 }
127 runner->AddObserver(observer.get());
128 }
129
130 void RemoveObserverOnUIThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
132 auto* runner =
133 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
134 if (!runner) {
135 DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
136 << "File system operations are dropped.";
137 return;
138 }
139 runner->RemoveObserver(observer.get());
140 }
141
89 } // namespace 142 } // namespace
90 143
144 ObserverIOThreadWrapper::ObserverIOThreadWrapper(
145 ArcFileSystemOperationRunner::Observer* underlying_observer)
146 : underlying_observer_(underlying_observer) {}
147
148 ObserverIOThreadWrapper::~ObserverIOThreadWrapper() = default;
149
150 void ObserverIOThreadWrapper::Disable() {
151 DCHECK_CURRENTLY_ON(BrowserThread::IO);
152 disabled_ = true;
153 }
154
155 void ObserverIOThreadWrapper::OnWatchersCleared() {
156 DCHECK_CURRENTLY_ON(BrowserThread::UI);
157 BrowserThread::PostTask(
158 BrowserThread::IO, FROM_HERE,
159 base::Bind(&ObserverIOThreadWrapper::OnWatchersClearedOnIOThread, this));
160 }
161
162 void ObserverIOThreadWrapper::OnWatchersClearedOnIOThread() {
163 DCHECK_CURRENTLY_ON(BrowserThread::IO);
164 if (disabled_)
165 return;
166 underlying_observer_->OnWatchersCleared();
167 }
168
91 void GetFileSizeOnIOThread(const GURL& url, 169 void GetFileSizeOnIOThread(const GURL& url,
92 const GetFileSizeCallback& callback) { 170 const GetFileSizeCallback& callback) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); 171 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94 BrowserThread::PostTask( 172 BrowserThread::PostTask(
95 BrowserThread::UI, FROM_HERE, 173 BrowserThread::UI, FROM_HERE,
96 base::Bind(&GetFileSizeOnUIThread, url, 174 base::Bind(&GetFileSizeOnUIThread, url,
97 base::Bind(&PostToIOThread<int64_t>, callback))); 175 base::Bind(&PostToIOThread<int64_t>, callback)));
98 } 176 }
99 177
100 void OpenFileToReadOnIOThread(const GURL& url, 178 void OpenFileToReadOnIOThread(const GURL& url,
(...skipping 21 matching lines...) Expand all
122 DCHECK_CURRENTLY_ON(BrowserThread::IO); 200 DCHECK_CURRENTLY_ON(BrowserThread::IO);
123 BrowserThread::PostTask( 201 BrowserThread::PostTask(
124 BrowserThread::UI, FROM_HERE, 202 BrowserThread::UI, FROM_HERE,
125 base::Bind( 203 base::Bind(
126 &GetChildDocumentsOnUIThread, authority, parent_document_id, 204 &GetChildDocumentsOnUIThread, authority, parent_document_id,
127 base::Bind( 205 base::Bind(
128 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>, 206 &PostToIOThread<base::Optional<std::vector<mojom::DocumentPtr>>>,
129 callback))); 207 callback)));
130 } 208 }
131 209
210 void AddWatcherOnIOThread(const std::string& authority,
211 const std::string& document_id,
212 const WatcherCallback& watcher_callback,
213 const AddWatcherCallback& callback) {
214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
215 BrowserThread::PostTask(
216 BrowserThread::UI, FROM_HERE,
217 base::Bind(
218 &AddWatcherOnUIThread, authority, document_id,
219 base::Bind(&PostToIOThread<ArcFileSystemOperationRunner::ChangeType>,
220 watcher_callback),
221 base::Bind(&PostToIOThread<int64_t>, callback)));
222 }
223
224 void RemoveWatcherOnIOThread(int64_t watcher_id,
225 const RemoveWatcherCallback& callback) {
226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 BrowserThread::PostTask(
228 BrowserThread::UI, FROM_HERE,
229 base::Bind(&RemoveWatcherOnUIThread, watcher_id,
230 base::Bind(&PostToIOThread<bool>, callback)));
231 }
232
233 void AddObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
234 DCHECK_CURRENTLY_ON(BrowserThread::IO);
235 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
236 base::Bind(&AddObserverOnUIThread, observer));
237 }
238
239 void RemoveObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
240 DCHECK_CURRENTLY_ON(BrowserThread::IO);
241 // Disable the observer now to guarantee the underlying observer is never
242 // called after this function returns.
243 observer->Disable();
244 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
245 base::Bind(&RemoveObserverOnUIThread, observer));
246 }
247
132 } // namespace file_system_operation_runner_util 248 } // namespace file_system_operation_runner_util
133 249
134 } // namespace arc 250 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698