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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/download_operation.cc

Issue 59343002: drive: Simplify DownloadOperation by using ResourceEntry::local_id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/download_operation.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/file_system/download_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 cache_file_path); 121 cache_file_path);
122 } 122 }
123 123
124 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by 124 // Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
125 // the given file path. 125 // the given file path.
126 FileError CheckPreConditionForEnsureFileDownloadedByPath( 126 FileError CheckPreConditionForEnsureFileDownloadedByPath(
127 internal::ResourceMetadata* metadata, 127 internal::ResourceMetadata* metadata,
128 internal::FileCache* cache, 128 internal::FileCache* cache,
129 const base::FilePath& file_path, 129 const base::FilePath& file_path,
130 const base::FilePath& temporary_file_directory, 130 const base::FilePath& temporary_file_directory,
131 std::string* local_id,
132 base::FilePath* cache_file_path, 131 base::FilePath* cache_file_path,
133 ResourceEntry* entry) { 132 ResourceEntry* entry) {
134 FileError error = metadata->GetIdByPath(file_path, local_id); 133 std::string local_id;
134 FileError error = metadata->GetIdByPath(file_path, &local_id);
135 if (error != FILE_ERROR_OK) 135 if (error != FILE_ERROR_OK)
136 return error; 136 return error;
137 return CheckPreConditionForEnsureFileDownloaded( 137 return CheckPreConditionForEnsureFileDownloaded(
138 metadata, cache, temporary_file_directory, *local_id, entry, 138 metadata, cache, temporary_file_directory, local_id, entry,
139 cache_file_path); 139 cache_file_path);
140 } 140 }
141 141
142 // Creates a file with unique name in |dir| and stores the path to |temp_file|. 142 // Creates a file with unique name in |dir| and stores the path to |temp_file|.
143 // Additionally, sets the permission of the file to allow read access from 143 // Additionally, sets the permission of the file to allow read access from
144 // others and group member users (i.e, "-rw-r--r--"). 144 // others and group member users (i.e, "-rw-r--r--").
145 // We need this wrapper because Drive cache files may be read from other 145 // We need this wrapper because Drive cache files may be read from other
146 // processes (e.g., cros_disks for mounting zip files). 146 // processes (e.g., cros_disks for mounting zip files).
147 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir, 147 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir,
148 base::FilePath* temp_file) { 148 base::FilePath* temp_file) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 base::Unretained(cache_), 312 base::Unretained(cache_),
313 local_id, 313 local_id,
314 temporary_file_directory_, 314 temporary_file_directory_,
315 drive_file_path, 315 drive_file_path,
316 cache_file_path, 316 cache_file_path,
317 entry), 317 entry),
318 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, 318 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition,
319 weak_ptr_factory_.GetWeakPtr(), 319 weak_ptr_factory_.GetWeakPtr(),
320 base::Passed(&params), 320 base::Passed(&params),
321 context, 321 context,
322 base::Owned(new std::string(local_id)),
323 base::Owned(drive_file_path), 322 base::Owned(drive_file_path),
324 base::Owned(cache_file_path))); 323 base::Owned(cache_file_path)));
325 } 324 }
326 325
327 void DownloadOperation::EnsureFileDownloadedByPath( 326 void DownloadOperation::EnsureFileDownloadedByPath(
328 const base::FilePath& file_path, 327 const base::FilePath& file_path,
329 const ClientContext& context, 328 const ClientContext& context,
330 const GetFileContentInitializedCallback& initialized_callback, 329 const GetFileContentInitializedCallback& initialized_callback,
331 const google_apis::GetContentCallback& get_content_callback, 330 const google_apis::GetContentCallback& get_content_callback,
332 const GetFileCallback& completion_callback) { 331 const GetFileCallback& completion_callback) {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 DCHECK(!completion_callback.is_null()); 333 DCHECK(!completion_callback.is_null());
335 334
336 std::string* local_id = new std::string;
337 base::FilePath* drive_file_path = new base::FilePath(file_path); 335 base::FilePath* drive_file_path = new base::FilePath(file_path);
338 base::FilePath* cache_file_path = new base::FilePath; 336 base::FilePath* cache_file_path = new base::FilePath;
339 ResourceEntry* entry = new ResourceEntry; 337 ResourceEntry* entry = new ResourceEntry;
340 scoped_ptr<DownloadParams> params(new DownloadParams( 338 scoped_ptr<DownloadParams> params(new DownloadParams(
341 initialized_callback, get_content_callback, completion_callback, 339 initialized_callback, get_content_callback, completion_callback,
342 make_scoped_ptr(entry))); 340 make_scoped_ptr(entry)));
343 base::PostTaskAndReplyWithResult( 341 base::PostTaskAndReplyWithResult(
344 blocking_task_runner_.get(), 342 blocking_task_runner_.get(),
345 FROM_HERE, 343 FROM_HERE,
346 base::Bind(&CheckPreConditionForEnsureFileDownloadedByPath, 344 base::Bind(&CheckPreConditionForEnsureFileDownloadedByPath,
347 base::Unretained(metadata_), 345 base::Unretained(metadata_),
348 base::Unretained(cache_), 346 base::Unretained(cache_),
349 file_path, 347 file_path,
350 temporary_file_directory_, 348 temporary_file_directory_,
351 local_id,
352 cache_file_path, 349 cache_file_path,
353 entry), 350 entry),
354 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, 351 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition,
355 weak_ptr_factory_.GetWeakPtr(), 352 weak_ptr_factory_.GetWeakPtr(),
356 base::Passed(&params), 353 base::Passed(&params),
357 context, 354 context,
358 base::Owned(local_id),
359 base::Owned(drive_file_path), 355 base::Owned(drive_file_path),
360 base::Owned(cache_file_path))); 356 base::Owned(cache_file_path)));
361 } 357 }
362 358
363 void DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition( 359 void DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition(
364 scoped_ptr<DownloadParams> params, 360 scoped_ptr<DownloadParams> params,
365 const ClientContext& context, 361 const ClientContext& context,
366 std::string* local_id,
367 base::FilePath* drive_file_path, 362 base::FilePath* drive_file_path,
368 base::FilePath* cache_file_path, 363 base::FilePath* cache_file_path,
369 FileError error) { 364 FileError error) {
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
371 DCHECK(params); 366 DCHECK(params);
372 DCHECK(local_id);
373 DCHECK(drive_file_path); 367 DCHECK(drive_file_path);
374 DCHECK(cache_file_path); 368 DCHECK(cache_file_path);
375 369
376 if (error != FILE_ERROR_OK) { 370 if (error != FILE_ERROR_OK) {
377 // During precondition check, an error is found. 371 // During precondition check, an error is found.
378 params->OnError(error); 372 params->OnError(error);
379 return; 373 return;
380 } 374 }
381 375
382 if (!cache_file_path->empty()) { 376 if (!cache_file_path->empty()) {
(...skipping 16 matching lines...) Expand all
399 base::Bind(&PrepareForDownloadFile, 393 base::Bind(&PrepareForDownloadFile,
400 base::Unretained(cache_), 394 base::Unretained(cache_),
401 size, 395 size,
402 temporary_file_directory_, 396 temporary_file_directory_,
403 temp_download_file_path), 397 temp_download_file_path),
404 base::Bind( 398 base::Bind(
405 &DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile, 399 &DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile,
406 weak_ptr_factory_.GetWeakPtr(), 400 weak_ptr_factory_.GetWeakPtr(),
407 base::Passed(&params), 401 base::Passed(&params),
408 context, 402 context,
409 *local_id,
410 *drive_file_path, 403 *drive_file_path,
411 base::Owned(temp_download_file_path))); 404 base::Owned(temp_download_file_path)));
412 } 405 }
413 406
414 void DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile( 407 void DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile(
415 scoped_ptr<DownloadParams> params, 408 scoped_ptr<DownloadParams> params,
416 const ClientContext& context, 409 const ClientContext& context,
417 const std::string& local_id,
418 const base::FilePath& drive_file_path, 410 const base::FilePath& drive_file_path,
419 base::FilePath* temp_download_file_path, 411 base::FilePath* temp_download_file_path,
420 FileError error) { 412 FileError error) {
421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
422 DCHECK(params); 414 DCHECK(params);
423 DCHECK(temp_download_file_path); 415 DCHECK(temp_download_file_path);
424 416
425 if (error != FILE_ERROR_OK) { 417 if (error != FILE_ERROR_OK) {
426 params->OnError(error); 418 params->OnError(error);
427 return; 419 return;
428 } 420 }
429 421
430 DownloadParams* params_ptr = params.get(); 422 DownloadParams* params_ptr = params.get();
431 JobID id = scheduler_->DownloadFile( 423 JobID id = scheduler_->DownloadFile(
432 drive_file_path, 424 drive_file_path,
433 params_ptr->entry().file_info().size(), 425 params_ptr->entry().file_info().size(),
434 *temp_download_file_path, 426 *temp_download_file_path,
435 params_ptr->entry().resource_id(), 427 params_ptr->entry().resource_id(),
436 context, 428 context,
437 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterDownloadFile, 429 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterDownloadFile,
438 weak_ptr_factory_.GetWeakPtr(), 430 weak_ptr_factory_.GetWeakPtr(),
439 drive_file_path, 431 drive_file_path,
440 local_id,
441 base::Passed(&params)), 432 base::Passed(&params)),
442 params_ptr->get_content_callback()); 433 params_ptr->get_content_callback());
443 434
444 // Notify via |initialized_callback| if necessary. 435 // Notify via |initialized_callback| if necessary.
445 params_ptr->OnStartDownloading( 436 params_ptr->OnStartDownloading(
446 base::Bind(&DownloadOperation::CancelJob, 437 base::Bind(&DownloadOperation::CancelJob,
447 weak_ptr_factory_.GetWeakPtr(), id)); 438 weak_ptr_factory_.GetWeakPtr(), id));
448 } 439 }
449 440
450 void DownloadOperation::EnsureFileDownloadedAfterDownloadFile( 441 void DownloadOperation::EnsureFileDownloadedAfterDownloadFile(
451 const base::FilePath& drive_file_path, 442 const base::FilePath& drive_file_path,
452 const std::string& local_id,
453 scoped_ptr<DownloadParams> params, 443 scoped_ptr<DownloadParams> params,
454 google_apis::GDataErrorCode gdata_error, 444 google_apis::GDataErrorCode gdata_error,
455 const base::FilePath& downloaded_file_path) { 445 const base::FilePath& downloaded_file_path) {
456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
457 447
448 const std::string& local_id = params->entry().local_id();
458 const std::string& md5 = params->entry().file_specific_info().md5(); 449 const std::string& md5 = params->entry().file_specific_info().md5();
459 base::FilePath* cache_file_path = new base::FilePath; 450 base::FilePath* cache_file_path = new base::FilePath;
460 base::PostTaskAndReplyWithResult( 451 base::PostTaskAndReplyWithResult(
461 blocking_task_runner_.get(), 452 blocking_task_runner_.get(),
462 FROM_HERE, 453 FROM_HERE,
463 base::Bind(&UpdateLocalStateForDownloadFile, 454 base::Bind(&UpdateLocalStateForDownloadFile,
464 base::Unretained(cache_), 455 base::Unretained(cache_),
465 local_id, 456 local_id,
466 md5, 457 md5,
467 gdata_error, 458 gdata_error,
(...skipping 22 matching lines...) Expand all
490 observer_->OnDirectoryChangedByOperation(file_path.DirName()); 481 observer_->OnDirectoryChangedByOperation(file_path.DirName());
491 params->OnComplete(*cache_file_path); 482 params->OnComplete(*cache_file_path);
492 } 483 }
493 484
494 void DownloadOperation::CancelJob(JobID job_id) { 485 void DownloadOperation::CancelJob(JobID job_id) {
495 scheduler_->CancelJob(job_id); 486 scheduler_->CancelJob(job_id);
496 } 487 }
497 488
498 } // namespace file_system 489 } // namespace file_system
499 } // namespace drive 490 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/download_operation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698