OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/fileapi/provider_async_fi
le_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 parser.file_system()->DeleteEntry(parser.file_path(), recursive, callback); | 122 parser.file_system()->DeleteEntry(parser.file_path(), recursive, callback); |
123 } | 123 } |
124 | 124 |
125 // Routes the response of DeleteEntry back to the IO thread. | 125 // Routes the response of DeleteEntry back to the IO thread. |
126 void OnDeleteEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, | 126 void OnDeleteEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, |
127 base::File::Error result) { | 127 base::File::Error result) { |
128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
129 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 129 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
130 } | 130 } |
131 | 131 |
| 132 // Executes CreateFile on the UI thread. |
| 133 void CreateFileOnUIThread( |
| 134 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 135 const fileapi::FileSystemURL& url, |
| 136 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 137 util::FileSystemURLParser parser(url); |
| 138 if (!parser.Parse()) { |
| 139 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 140 return; |
| 141 } |
| 142 |
| 143 parser.file_system()->CreateFile(parser.file_path(), callback); |
| 144 } |
| 145 |
| 146 // Routes the response of CreateFile to a callback of EnsureFileExists() on the |
| 147 // IO thread. |
| 148 void OnCreateFileForEnsureFileExists( |
| 149 const fileapi::AsyncFileUtil::EnsureFileExistsCallback& callback, |
| 150 base::File::Error result) { |
| 151 const bool created = result == base::File::FILE_OK; |
| 152 |
| 153 // If the file already existed, then return success anyway, since it is not |
| 154 // an error. |
| 155 const base::File::Error error = |
| 156 result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result; |
| 157 |
| 158 BrowserThread::PostTask( |
| 159 BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created)); |
| 160 } |
| 161 |
132 } // namespace | 162 } // namespace |
133 | 163 |
134 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 164 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
135 | 165 |
136 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 166 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
137 | 167 |
138 void ProviderAsyncFileUtil::CreateOrOpen( | 168 void ProviderAsyncFileUtil::CreateOrOpen( |
139 scoped_ptr<fileapi::FileSystemOperationContext> context, | 169 scoped_ptr<fileapi::FileSystemOperationContext> context, |
140 const fileapi::FileSystemURL& url, | 170 const fileapi::FileSystemURL& url, |
141 int file_flags, | 171 int file_flags, |
(...skipping 11 matching lines...) Expand all Loading... |
153 NOTIMPLEMENTED(); | 183 NOTIMPLEMENTED(); |
154 callback.Run(base::File(base::File::FILE_ERROR_INVALID_OPERATION), | 184 callback.Run(base::File(base::File::FILE_ERROR_INVALID_OPERATION), |
155 base::Closure()); | 185 base::Closure()); |
156 } | 186 } |
157 | 187 |
158 void ProviderAsyncFileUtil::EnsureFileExists( | 188 void ProviderAsyncFileUtil::EnsureFileExists( |
159 scoped_ptr<fileapi::FileSystemOperationContext> context, | 189 scoped_ptr<fileapi::FileSystemOperationContext> context, |
160 const fileapi::FileSystemURL& url, | 190 const fileapi::FileSystemURL& url, |
161 const EnsureFileExistsCallback& callback) { | 191 const EnsureFileExistsCallback& callback) { |
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 192 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
163 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED, false /* created */); | 193 BrowserThread::PostTask( |
| 194 BrowserThread::UI, |
| 195 FROM_HERE, |
| 196 base::Bind(&CreateFileOnUIThread, |
| 197 base::Passed(&context), |
| 198 url, |
| 199 base::Bind(&OnCreateFileForEnsureFileExists, callback))); |
164 } | 200 } |
165 | 201 |
166 void ProviderAsyncFileUtil::CreateDirectory( | 202 void ProviderAsyncFileUtil::CreateDirectory( |
167 scoped_ptr<fileapi::FileSystemOperationContext> context, | 203 scoped_ptr<fileapi::FileSystemOperationContext> context, |
168 const fileapi::FileSystemURL& url, | 204 const fileapi::FileSystemURL& url, |
169 bool exclusive, | 205 bool exclusive, |
170 bool recursive, | 206 bool recursive, |
171 const StatusCallback& callback) { | 207 const StatusCallback& callback) { |
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
173 BrowserThread::PostTask(BrowserThread::UI, | 209 BrowserThread::PostTask(BrowserThread::UI, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 NOTIMPLEMENTED(); | 341 NOTIMPLEMENTED(); |
306 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 342 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
307 base::File::Info(), | 343 base::File::Info(), |
308 base::FilePath(), | 344 base::FilePath(), |
309 scoped_refptr<webkit_blob::ShareableFileReference>()); | 345 scoped_refptr<webkit_blob::ShareableFileReference>()); |
310 } | 346 } |
311 | 347 |
312 } // namespace internal | 348 } // namespace internal |
313 } // namespace file_system_provider | 349 } // namespace file_system_provider |
314 } // namespace chromeos | 350 } // namespace chromeos |
OLD | NEW |