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

Side by Side Diff: chrome/browser/chromeos/drive/fileapi/fileapi_worker.cc

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 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/drive/fileapi/fileapi_worker.h" 5 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 callback.Run(base::File::FILE_OK, file_info, local_path, scope_out_policy); 134 callback.Run(base::File::FILE_OK, file_info, local_path, scope_out_policy);
135 } 135 }
136 136
137 // Runs |callback| with arguments converted from |error| and |local_path|. 137 // Runs |callback| with arguments converted from |error| and |local_path|.
138 void RunCreateWritableSnapshotFileCallback( 138 void RunCreateWritableSnapshotFileCallback(
139 const CreateWritableSnapshotFileCallback& callback, 139 const CreateWritableSnapshotFileCallback& callback,
140 FileError error, 140 FileError error,
141 const base::FilePath& local_path, 141 const base::FilePath& local_path,
142 const base::Closure& close_callback) { 142 const base::Closure& close_callback) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 143 DCHECK_CURRENTLY_ON(BrowserThread::UI);
144 callback.Run(FileErrorToBaseFileError(error), local_path, close_callback); 144 callback.Run(FileErrorToBaseFileError(error), local_path, close_callback);
145 } 145 }
146 146
147 // Runs |callback| with |file|. 147 // Runs |callback| with |file|.
148 void RunOpenFileCallback(const OpenFileCallback& callback, 148 void RunOpenFileCallback(const OpenFileCallback& callback,
149 const base::Closure& close_callback, 149 const base::Closure& close_callback,
150 base::File file) { 150 base::File file) {
151 callback.Run(file.Pass(), close_callback); 151 callback.Run(file.Pass(), close_callback);
152 } 152 }
153 153
154 base::File OpenFile(const base::FilePath& path, int flags) { 154 base::File OpenFile(const base::FilePath& path, int flags) {
155 return base::File(path, flags); 155 return base::File(path, flags);
156 } 156 }
157 157
158 // Part of OpenFile(). Called after FileSystem::OpenFile(). 158 // Part of OpenFile(). Called after FileSystem::OpenFile().
159 void OpenFileAfterFileSystemOpenFile(int file_flags, 159 void OpenFileAfterFileSystemOpenFile(int file_flags,
160 const OpenFileCallback& callback, 160 const OpenFileCallback& callback,
161 FileError error, 161 FileError error,
162 const base::FilePath& local_path, 162 const base::FilePath& local_path,
163 const base::Closure& close_callback) { 163 const base::Closure& close_callback) {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK_CURRENTLY_ON(BrowserThread::UI);
165 165
166 if (error != FILE_ERROR_OK) { 166 if (error != FILE_ERROR_OK) {
167 callback.Run(base::File(FileErrorToBaseFileError(error)), base::Closure()); 167 callback.Run(base::File(FileErrorToBaseFileError(error)), base::Closure());
168 return; 168 return;
169 } 169 }
170 170
171 // Here, the file should be at |local_path|, but there may be timing issue. 171 // Here, the file should be at |local_path|, but there may be timing issue.
172 // Because the file is managed by Drive file system, so, in order to avoid 172 // Because the file is managed by Drive file system, so, in order to avoid
173 // unexpected file creation, CREATE, OPEN_ALWAYS and CREATE_ALWAYS are 173 // unexpected file creation, CREATE, OPEN_ALWAYS and CREATE_ALWAYS are
174 // translated into OPEN or OPEN_TRUNCATED, here. Keep OPEN and OPEN_TRUNCATED 174 // translated into OPEN or OPEN_TRUNCATED, here. Keep OPEN and OPEN_TRUNCATED
(...skipping 12 matching lines...) Expand all
187 bool posted = base::PostTaskAndReplyWithResult( 187 bool posted = base::PostTaskAndReplyWithResult(
188 BrowserThread::GetBlockingPool(), FROM_HERE, 188 BrowserThread::GetBlockingPool(), FROM_HERE,
189 base::Bind(&OpenFile, local_path, file_flags), 189 base::Bind(&OpenFile, local_path, file_flags),
190 base::Bind(&RunOpenFileCallback, callback, close_callback)); 190 base::Bind(&RunOpenFileCallback, callback, close_callback));
191 DCHECK(posted); 191 DCHECK(posted);
192 } 192 }
193 193
194 } // namespace 194 } // namespace
195 195
196 FileSystemInterface* GetFileSystemFromUrl(const storage::FileSystemURL& url) { 196 FileSystemInterface* GetFileSystemFromUrl(const storage::FileSystemURL& url) {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK_CURRENTLY_ON(BrowserThread::UI);
198 198
199 Profile* profile = util::ExtractProfileFromPath(url.path()); 199 Profile* profile = util::ExtractProfileFromPath(url.path());
200 return profile ? util::GetFileSystemByProfile(profile) : NULL; 200 return profile ? util::GetFileSystemByProfile(profile) : NULL;
201 } 201 }
202 202
203 void RunFileSystemCallback( 203 void RunFileSystemCallback(
204 const FileSystemGetter& file_system_getter, 204 const FileSystemGetter& file_system_getter,
205 const base::Callback<void(FileSystemInterface*)>& callback, 205 const base::Callback<void(FileSystemInterface*)>& callback,
206 const base::Closure& on_error_callback) { 206 const base::Closure& on_error_callback) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 207 DCHECK_CURRENTLY_ON(BrowserThread::UI);
208 FileSystemInterface* file_system = file_system_getter.Run(); 208 FileSystemInterface* file_system = file_system_getter.Run();
209 209
210 if (!file_system) { 210 if (!file_system) {
211 if (!on_error_callback.is_null()) 211 if (!on_error_callback.is_null())
212 on_error_callback.Run(); 212 on_error_callback.Run();
213 return; 213 return;
214 } 214 }
215 215
216 callback.Run(file_system); 216 callback.Run(file_system);
217 } 217 }
218 218
219 void GetFileInfo(const base::FilePath& file_path, 219 void GetFileInfo(const base::FilePath& file_path,
220 const GetFileInfoCallback& callback, 220 const GetFileInfoCallback& callback,
221 FileSystemInterface* file_system) { 221 FileSystemInterface* file_system) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 222 DCHECK_CURRENTLY_ON(BrowserThread::UI);
223 file_system->GetResourceEntry( 223 file_system->GetResourceEntry(
224 file_path, 224 file_path,
225 base::Bind(&RunGetFileInfoCallback, callback)); 225 base::Bind(&RunGetFileInfoCallback, callback));
226 } 226 }
227 227
228 void Copy(const base::FilePath& src_file_path, 228 void Copy(const base::FilePath& src_file_path,
229 const base::FilePath& dest_file_path, 229 const base::FilePath& dest_file_path,
230 bool preserve_last_modified, 230 bool preserve_last_modified,
231 const StatusCallback& callback, 231 const StatusCallback& callback,
232 FileSystemInterface* file_system) { 232 FileSystemInterface* file_system) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 233 DCHECK_CURRENTLY_ON(BrowserThread::UI);
234 file_system->Copy(src_file_path, dest_file_path, preserve_last_modified, 234 file_system->Copy(src_file_path, dest_file_path, preserve_last_modified,
235 base::Bind(&RunStatusCallbackByFileError, callback)); 235 base::Bind(&RunStatusCallbackByFileError, callback));
236 } 236 }
237 237
238 void Move(const base::FilePath& src_file_path, 238 void Move(const base::FilePath& src_file_path,
239 const base::FilePath& dest_file_path, 239 const base::FilePath& dest_file_path,
240 const StatusCallback& callback, 240 const StatusCallback& callback,
241 FileSystemInterface* file_system) { 241 FileSystemInterface* file_system) {
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 242 DCHECK_CURRENTLY_ON(BrowserThread::UI);
243 file_system->Move(src_file_path, dest_file_path, 243 file_system->Move(src_file_path, dest_file_path,
244 base::Bind(&RunStatusCallbackByFileError, callback)); 244 base::Bind(&RunStatusCallbackByFileError, callback));
245 } 245 }
246 246
247 void CopyInForeignFile(const base::FilePath& src_foreign_file_path, 247 void CopyInForeignFile(const base::FilePath& src_foreign_file_path,
248 const base::FilePath& dest_file_path, 248 const base::FilePath& dest_file_path,
249 const StatusCallback& callback, 249 const StatusCallback& callback,
250 FileSystemInterface* file_system) { 250 FileSystemInterface* file_system) {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
252 file_system->TransferFileFromLocalToRemote( 252 file_system->TransferFileFromLocalToRemote(
253 src_foreign_file_path, dest_file_path, 253 src_foreign_file_path, dest_file_path,
254 base::Bind(&RunStatusCallbackByFileError, callback)); 254 base::Bind(&RunStatusCallbackByFileError, callback));
255 } 255 }
256 256
257 void ReadDirectory(const base::FilePath& file_path, 257 void ReadDirectory(const base::FilePath& file_path,
258 const ReadDirectoryCallback& callback, 258 const ReadDirectoryCallback& callback,
259 FileSystemInterface* file_system) { 259 FileSystemInterface* file_system) {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
261 file_system->ReadDirectory( 261 file_system->ReadDirectory(
262 file_path, 262 file_path,
263 base::Bind(&RunReadDirectoryCallbackWithEntries, callback), 263 base::Bind(&RunReadDirectoryCallbackWithEntries, callback),
264 base::Bind(&RunReadDirectoryCallbackOnCompletion, callback)); 264 base::Bind(&RunReadDirectoryCallbackOnCompletion, callback));
265 } 265 }
266 266
267 void Remove(const base::FilePath& file_path, 267 void Remove(const base::FilePath& file_path,
268 bool is_recursive, 268 bool is_recursive,
269 const StatusCallback& callback, 269 const StatusCallback& callback,
270 FileSystemInterface* file_system) { 270 FileSystemInterface* file_system) {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 271 DCHECK_CURRENTLY_ON(BrowserThread::UI);
272 file_system->Remove(file_path, is_recursive, 272 file_system->Remove(file_path, is_recursive,
273 base::Bind(&RunStatusCallbackByFileError, callback)); 273 base::Bind(&RunStatusCallbackByFileError, callback));
274 } 274 }
275 275
276 void CreateDirectory(const base::FilePath& file_path, 276 void CreateDirectory(const base::FilePath& file_path,
277 bool is_exclusive, 277 bool is_exclusive,
278 bool is_recursive, 278 bool is_recursive,
279 const StatusCallback& callback, 279 const StatusCallback& callback,
280 FileSystemInterface* file_system) { 280 FileSystemInterface* file_system) {
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
282 file_system->CreateDirectory( 282 file_system->CreateDirectory(
283 file_path, is_exclusive, is_recursive, 283 file_path, is_exclusive, is_recursive,
284 base::Bind(&RunStatusCallbackByFileError, callback)); 284 base::Bind(&RunStatusCallbackByFileError, callback));
285 } 285 }
286 286
287 void CreateFile(const base::FilePath& file_path, 287 void CreateFile(const base::FilePath& file_path,
288 bool is_exclusive, 288 bool is_exclusive,
289 const StatusCallback& callback, 289 const StatusCallback& callback,
290 FileSystemInterface* file_system) { 290 FileSystemInterface* file_system) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 DCHECK_CURRENTLY_ON(BrowserThread::UI);
292 file_system->CreateFile(file_path, is_exclusive, 292 file_system->CreateFile(file_path, is_exclusive,
293 std::string(), // no mime type; guess from file_path 293 std::string(), // no mime type; guess from file_path
294 base::Bind(&RunStatusCallbackByFileError, callback)); 294 base::Bind(&RunStatusCallbackByFileError, callback));
295 } 295 }
296 296
297 void Truncate(const base::FilePath& file_path, 297 void Truncate(const base::FilePath& file_path,
298 int64 length, 298 int64 length,
299 const StatusCallback& callback, 299 const StatusCallback& callback,
300 FileSystemInterface* file_system) { 300 FileSystemInterface* file_system) {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 301 DCHECK_CURRENTLY_ON(BrowserThread::UI);
302 file_system->TruncateFile( 302 file_system->TruncateFile(
303 file_path, length, 303 file_path, length,
304 base::Bind(&RunStatusCallbackByFileError, callback)); 304 base::Bind(&RunStatusCallbackByFileError, callback));
305 } 305 }
306 306
307 void CreateSnapshotFile(const base::FilePath& file_path, 307 void CreateSnapshotFile(const base::FilePath& file_path,
308 const CreateSnapshotFileCallback& callback, 308 const CreateSnapshotFileCallback& callback,
309 FileSystemInterface* file_system) { 309 FileSystemInterface* file_system) {
310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 310 DCHECK_CURRENTLY_ON(BrowserThread::UI);
311 file_system->GetFile(file_path, 311 file_system->GetFile(file_path,
312 base::Bind(&RunCreateSnapshotFileCallback, callback)); 312 base::Bind(&RunCreateSnapshotFileCallback, callback));
313 } 313 }
314 314
315 void CreateWritableSnapshotFile( 315 void CreateWritableSnapshotFile(
316 const base::FilePath& file_path, 316 const base::FilePath& file_path,
317 const CreateWritableSnapshotFileCallback& callback, 317 const CreateWritableSnapshotFileCallback& callback,
318 FileSystemInterface* file_system) { 318 FileSystemInterface* file_system) {
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 319 DCHECK_CURRENTLY_ON(BrowserThread::UI);
320 file_system->OpenFile( 320 file_system->OpenFile(
321 file_path, 321 file_path,
322 OPEN_FILE, 322 OPEN_FILE,
323 std::string(), // no mime type; we never create a new file here. 323 std::string(), // no mime type; we never create a new file here.
324 base::Bind(&RunCreateWritableSnapshotFileCallback, callback)); 324 base::Bind(&RunCreateWritableSnapshotFileCallback, callback));
325 } 325 }
326 326
327 void OpenFile(const base::FilePath& file_path, 327 void OpenFile(const base::FilePath& file_path,
328 int file_flags, 328 int file_flags,
329 const OpenFileCallback& callback, 329 const OpenFileCallback& callback,
330 FileSystemInterface* file_system) { 330 FileSystemInterface* file_system) {
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK_CURRENTLY_ON(BrowserThread::UI);
332 332
333 // Returns an error if any unsupported flag is found. 333 // Returns an error if any unsupported flag is found.
334 if (file_flags & ~(base::File::FLAG_OPEN | 334 if (file_flags & ~(base::File::FLAG_OPEN |
335 base::File::FLAG_CREATE | 335 base::File::FLAG_CREATE |
336 base::File::FLAG_OPEN_ALWAYS | 336 base::File::FLAG_OPEN_ALWAYS |
337 base::File::FLAG_CREATE_ALWAYS | 337 base::File::FLAG_CREATE_ALWAYS |
338 base::File::FLAG_OPEN_TRUNCATED | 338 base::File::FLAG_OPEN_TRUNCATED |
339 base::File::FLAG_READ | 339 base::File::FLAG_READ |
340 base::File::FLAG_WRITE | 340 base::File::FLAG_WRITE |
341 base::File::FLAG_WRITE_ATTRIBUTES | 341 base::File::FLAG_WRITE_ATTRIBUTES |
(...skipping 10 matching lines...) Expand all
352 file_path, GetOpenMode(file_flags), 352 file_path, GetOpenMode(file_flags),
353 std::string(), // no mime type; guess from file_path 353 std::string(), // no mime type; guess from file_path
354 base::Bind(&OpenFileAfterFileSystemOpenFile, file_flags, callback)); 354 base::Bind(&OpenFileAfterFileSystemOpenFile, file_flags, callback));
355 } 355 }
356 356
357 void TouchFile(const base::FilePath& file_path, 357 void TouchFile(const base::FilePath& file_path,
358 const base::Time& last_access_time, 358 const base::Time& last_access_time,
359 const base::Time& last_modified_time, 359 const base::Time& last_modified_time,
360 const StatusCallback& callback, 360 const StatusCallback& callback,
361 FileSystemInterface* file_system) { 361 FileSystemInterface* file_system) {
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
363 file_system->TouchFile(file_path, last_access_time, last_modified_time, 363 file_system->TouchFile(file_path, last_access_time, last_modified_time,
364 base::Bind(&RunStatusCallbackByFileError, callback)); 364 base::Bind(&RunStatusCallbackByFileError, callback));
365 365
366 } 366 }
367 367
368 } // namespace fileapi_internal 368 } // namespace fileapi_internal
369 } // namespace drive 369 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698