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

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

Issue 2715493002: mediaview: Support watchers in ArcFileSystemOperationRunner. (Closed)
Patch Set: Moved ObserverIOThreadWrapper to arc::file_system_operation_runner_util namespace. 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
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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>(); 78 ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
80 if (!runner) { 79 if (!runner) {
81 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " 80 LOG(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 LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
dcheng 2017/03/03 09:31:14 DLOG(ERROR) for all the other LOG(ERROR) introduce
Shuhei Takahashi 2017/03/03 10:11:58 Sure, done.
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 LOG(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 LOG(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 LOG(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,
dcheng 2017/03/03 09:31:14 Btw... does ObserverListThreadSafe help with this
Shuhei Takahashi 2017/03/03 10:11:58 I tried ObserverListThreadSafe actually, but I sti
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

Powered by Google App Engine
This is Rietveld 408576698