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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10877005: Rename GDataCache* to DriveCache* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 const FilePath remote_file_path; 381 const FilePath remote_file_path;
382 const FileOperationCallback callback; 382 const FileOperationCallback callback;
383 }; 383 };
384 384
385 // GDataFileSystem::AddUploadedFileParams implementation. 385 // GDataFileSystem::AddUploadedFileParams implementation.
386 struct GDataFileSystem::AddUploadedFileParams { 386 struct GDataFileSystem::AddUploadedFileParams {
387 AddUploadedFileParams(UploadMode upload_mode, 387 AddUploadedFileParams(UploadMode upload_mode,
388 DriveDirectory* parent_dir, 388 DriveDirectory* parent_dir,
389 scoped_ptr<DriveEntry> new_entry, 389 scoped_ptr<DriveEntry> new_entry,
390 const FilePath& file_content_path, 390 const FilePath& file_content_path,
391 GDataCache::FileOperationType cache_operation, 391 DriveCache::FileOperationType cache_operation,
392 const base::Closure& callback) 392 const base::Closure& callback)
393 : upload_mode(upload_mode), 393 : upload_mode(upload_mode),
394 parent_dir(parent_dir), 394 parent_dir(parent_dir),
395 new_entry(new_entry.Pass()), 395 new_entry(new_entry.Pass()),
396 file_content_path(file_content_path), 396 file_content_path(file_content_path),
397 cache_operation(cache_operation), 397 cache_operation(cache_operation),
398 callback(callback) { 398 callback(callback) {
399 } 399 }
400 400
401 UploadMode upload_mode; 401 UploadMode upload_mode;
402 DriveDirectory* parent_dir; 402 DriveDirectory* parent_dir;
403 scoped_ptr<DriveEntry> new_entry; 403 scoped_ptr<DriveEntry> new_entry;
404 FilePath file_content_path; 404 FilePath file_content_path;
405 GDataCache::FileOperationType cache_operation; 405 DriveCache::FileOperationType cache_operation;
406 base::Closure callback; 406 base::Closure callback;
407 std::string resource_id; 407 std::string resource_id;
408 std::string md5; 408 std::string md5;
409 }; 409 };
410 410
411 411
412 // GDataFileSystem class implementation. 412 // GDataFileSystem class implementation.
413 413
414 GDataFileSystem::GDataFileSystem( 414 GDataFileSystem::GDataFileSystem(
415 Profile* profile, 415 Profile* profile,
416 GDataCache* cache, 416 DriveCache* cache,
417 DriveServiceInterface* drive_service, 417 DriveServiceInterface* drive_service,
418 GDataUploaderInterface* uploader, 418 GDataUploaderInterface* uploader,
419 DriveWebAppsRegistryInterface* webapps_registry, 419 DriveWebAppsRegistryInterface* webapps_registry,
420 base::SequencedTaskRunner* blocking_task_runner) 420 base::SequencedTaskRunner* blocking_task_runner)
421 : profile_(profile), 421 : profile_(profile),
422 cache_(cache), 422 cache_(cache),
423 uploader_(uploader), 423 uploader_(uploader),
424 drive_service_(drive_service), 424 drive_service_(drive_service),
425 webapps_registry_(webapps_registry), 425 webapps_registry_(webapps_registry),
426 update_timer_(true /* retain_user_task */, true /* is_repeating */), 426 update_timer_(true /* retain_user_task */, true /* is_repeating */),
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 GDataFileError error, 794 GDataFileError error,
795 scoped_ptr<UploadFileInfo> upload_file_info) { 795 scoped_ptr<UploadFileInfo> upload_file_info) {
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
797 DCHECK(upload_file_info.get()); 797 DCHECK(upload_file_info.get());
798 798
799 if (error == GDATA_FILE_OK && upload_file_info->entry.get()) { 799 if (error == GDATA_FILE_OK && upload_file_info->entry.get()) {
800 AddUploadedFile(UPLOAD_NEW_FILE, 800 AddUploadedFile(UPLOAD_NEW_FILE,
801 upload_file_info->gdata_path.DirName(), 801 upload_file_info->gdata_path.DirName(),
802 upload_file_info->entry.Pass(), 802 upload_file_info->entry.Pass(),
803 upload_file_info->file_path, 803 upload_file_info->file_path,
804 GDataCache::FILE_OPERATION_COPY, 804 DriveCache::FILE_OPERATION_COPY,
805 base::Bind(&OnAddUploadFileCompleted, callback, error)); 805 base::Bind(&OnAddUploadFileCompleted, callback, error));
806 } else if (!callback.is_null()) { 806 } else if (!callback.is_null()) {
807 callback.Run(error); 807 callback.Run(error);
808 } 808 }
809 } 809 }
810 810
811 void GDataFileSystem::Copy(const FilePath& src_file_path, 811 void GDataFileSystem::Copy(const FilePath& src_file_path,
812 const FilePath& dest_file_path, 812 const FilePath& dest_file_path,
813 const FileOperationCallback& callback) { 813 const FileOperationCallback& callback) {
814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 GDataFileError* error = 1508 GDataFileError* error =
1509 new GDataFileError(GDATA_FILE_OK); 1509 new GDataFileError(GDATA_FILE_OK);
1510 FilePath* temp_file_path = new FilePath; 1510 FilePath* temp_file_path = new FilePath;
1511 std::string* mime_type = new std::string; 1511 std::string* mime_type = new std::string;
1512 DriveFileType* file_type = new DriveFileType(REGULAR_FILE); 1512 DriveFileType* file_type = new DriveFileType(REGULAR_FILE);
1513 util::PostBlockingPoolSequencedTaskAndReply( 1513 util::PostBlockingPoolSequencedTaskAndReply(
1514 FROM_HERE, 1514 FROM_HERE,
1515 blocking_task_runner_, 1515 blocking_task_runner_,
1516 base::Bind(&CreateDocumentJsonFileOnBlockingPool, 1516 base::Bind(&CreateDocumentJsonFileOnBlockingPool,
1517 cache_->GetCacheDirectoryPath( 1517 cache_->GetCacheDirectoryPath(
1518 GDataCache::CACHE_TYPE_TMP_DOCUMENTS), 1518 DriveCache::CACHE_TYPE_TMP_DOCUMENTS),
1519 GURL(entry_proto->file_specific_info().alternate_url()), 1519 GURL(entry_proto->file_specific_info().alternate_url()),
1520 entry_proto->resource_id(), 1520 entry_proto->resource_id(),
1521 error, 1521 error,
1522 temp_file_path, 1522 temp_file_path,
1523 mime_type, 1523 mime_type,
1524 file_type), 1524 file_type),
1525 base::Bind(&RunGetFileCallbackHelper, 1525 base::Bind(&RunGetFileCallbackHelper,
1526 get_file_callback, 1526 get_file_callback,
1527 base::Owned(error), 1527 base::Owned(error),
1528 base::Owned(temp_file_path), 1528 base::Owned(temp_file_path),
1529 base::Owned(mime_type), 1529 base::Owned(mime_type),
1530 base::Owned(file_type))); 1530 base::Owned(file_type)));
1531 return; 1531 return;
1532 } 1532 }
1533 1533
1534 // Returns absolute path of the file if it were cached or to be cached. 1534 // Returns absolute path of the file if it were cached or to be cached.
1535 FilePath local_tmp_path = cache_->GetCacheFilePath( 1535 FilePath local_tmp_path = cache_->GetCacheFilePath(
1536 entry_proto->resource_id(), 1536 entry_proto->resource_id(),
1537 entry_proto->file_specific_info().file_md5(), 1537 entry_proto->file_specific_info().file_md5(),
1538 GDataCache::CACHE_TYPE_TMP, 1538 DriveCache::CACHE_TYPE_TMP,
1539 GDataCache::CACHED_FILE_FROM_SERVER); 1539 DriveCache::CACHED_FILE_FROM_SERVER);
1540 cache_->GetFileOnUIThread( 1540 cache_->GetFileOnUIThread(
1541 entry_proto->resource_id(), 1541 entry_proto->resource_id(),
1542 entry_proto->file_specific_info().file_md5(), 1542 entry_proto->file_specific_info().file_md5(),
1543 base::Bind( 1543 base::Bind(
1544 &GDataFileSystem::OnGetFileFromCache, 1544 &GDataFileSystem::OnGetFileFromCache,
1545 ui_weak_ptr_, 1545 ui_weak_ptr_,
1546 GetFileFromCacheParams( 1546 GetFileFromCacheParams(
1547 file_path, 1547 file_path,
1548 local_tmp_path, 1548 local_tmp_path,
1549 GURL(entry_proto->content_url()), 1549 GURL(entry_proto->content_url()),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 1690
1691 DCHECK_EQ(params.resource_id, fresh_entry->resource_id()); 1691 DCHECK_EQ(params.resource_id, fresh_entry->resource_id());
1692 scoped_ptr<DriveFile> fresh_entry_as_file( 1692 scoped_ptr<DriveFile> fresh_entry_as_file(
1693 fresh_entry.release()->AsDriveFile()); 1693 fresh_entry.release()->AsDriveFile());
1694 resource_metadata_->RefreshFile(fresh_entry_as_file.Pass()); 1694 resource_metadata_->RefreshFile(fresh_entry_as_file.Pass());
1695 1695
1696 bool* has_enough_space = new bool(false); 1696 bool* has_enough_space = new bool(false);
1697 util::PostBlockingPoolSequencedTaskAndReply( 1697 util::PostBlockingPoolSequencedTaskAndReply(
1698 FROM_HERE, 1698 FROM_HERE,
1699 blocking_task_runner_, 1699 blocking_task_runner_,
1700 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor, 1700 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor,
1701 base::Unretained(cache_), 1701 base::Unretained(cache_),
1702 file_size, 1702 file_size,
1703 has_enough_space), 1703 has_enough_space),
1704 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace, 1704 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace,
1705 ui_weak_ptr_, 1705 ui_weak_ptr_,
1706 params, 1706 params,
1707 content_url, 1707 content_url,
1708 cache_file_path, 1708 cache_file_path,
1709 base::Owned(has_enough_space))); 1709 base::Owned(has_enough_space)));
1710 } 1710 }
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 if (error != GDATA_FILE_OK) { 2099 if (error != GDATA_FILE_OK) {
2100 if (!callback.is_null()) 2100 if (!callback.is_null())
2101 callback.Run(error); 2101 callback.Run(error);
2102 return; 2102 return;
2103 } 2103 }
2104 2104
2105 AddUploadedFile(UPLOAD_EXISTING_FILE, 2105 AddUploadedFile(UPLOAD_EXISTING_FILE,
2106 upload_file_info->gdata_path.DirName(), 2106 upload_file_info->gdata_path.DirName(),
2107 upload_file_info->entry.Pass(), 2107 upload_file_info->entry.Pass(),
2108 upload_file_info->file_path, 2108 upload_file_info->file_path,
2109 GDataCache::FILE_OPERATION_MOVE, 2109 DriveCache::FILE_OPERATION_MOVE,
2110 base::Bind(&OnAddUploadFileCompleted, callback, error)); 2110 base::Bind(&OnAddUploadFileCompleted, callback, error));
2111 } 2111 }
2112 2112
2113 void GDataFileSystem::GetAvailableSpace( 2113 void GDataFileSystem::GetAvailableSpace(
2114 const GetAvailableSpaceCallback& callback) { 2114 const GetAvailableSpaceCallback& callback) {
2115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2116 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2116 BrowserThread::CurrentlyOn(BrowserThread::IO));
2117 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, 2117 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread,
2118 ui_weak_ptr_, 2118 ui_weak_ptr_,
2119 CreateRelayCallback(callback))); 2119 CreateRelayCallback(callback)));
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 // - There was an in-flight download operation and it used up space 2480 // - There was an in-flight download operation and it used up space
2481 // - The disk became full for some user actions we cannot control 2481 // - The disk became full for some user actions we cannot control
2482 // (ex. the user might have downloaded a large file from a regular web site) 2482 // (ex. the user might have downloaded a large file from a regular web site)
2483 // 2483 //
2484 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, 2484 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE,
2485 // and try to free up space, even if the file was downloaded successfully. 2485 // and try to free up space, even if the file was downloaded successfully.
2486 bool* has_enough_space = new bool(false); 2486 bool* has_enough_space = new bool(false);
2487 util::PostBlockingPoolSequencedTaskAndReply( 2487 util::PostBlockingPoolSequencedTaskAndReply(
2488 FROM_HERE, 2488 FROM_HERE,
2489 blocking_task_runner_, 2489 blocking_task_runner_,
2490 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor, 2490 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor,
2491 base::Unretained(cache_), 2491 base::Unretained(cache_),
2492 0, 2492 0,
2493 has_enough_space), 2493 has_enough_space),
2494 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, 2494 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked,
2495 ui_weak_ptr_, 2495 ui_weak_ptr_,
2496 params, 2496 params,
2497 status, 2497 status,
2498 content_url, 2498 content_url,
2499 downloaded_file_path, 2499 downloaded_file_path,
2500 base::Owned(has_enough_space))); 2500 base::Owned(has_enough_space)));
(...skipping 23 matching lines...) Expand all
2524 2524
2525 // Make sure that downloaded file is properly stored in cache. We don't have 2525 // Make sure that downloaded file is properly stored in cache. We don't have
2526 // to wait for this operation to finish since the user can already use the 2526 // to wait for this operation to finish since the user can already use the
2527 // downloaded file. 2527 // downloaded file.
2528 if (error == GDATA_FILE_OK) { 2528 if (error == GDATA_FILE_OK) {
2529 if (*has_enough_space) { 2529 if (*has_enough_space) {
2530 cache_->StoreOnUIThread( 2530 cache_->StoreOnUIThread(
2531 params.resource_id, 2531 params.resource_id,
2532 params.md5, 2532 params.md5,
2533 downloaded_file_path, 2533 downloaded_file_path,
2534 GDataCache::FILE_OPERATION_MOVE, 2534 DriveCache::FILE_OPERATION_MOVE,
2535 base::Bind(&GDataFileSystem::OnDownloadStoredToCache, 2535 base::Bind(&GDataFileSystem::OnDownloadStoredToCache,
2536 ui_weak_ptr_)); 2536 ui_weak_ptr_));
2537 } else { 2537 } else {
2538 // If we don't have enough space, remove the downloaded file, and 2538 // If we don't have enough space, remove the downloaded file, and
2539 // report "no space" error. 2539 // report "no space" error.
2540 util::PostBlockingPoolSequencedTask( 2540 util::PostBlockingPoolSequencedTask(
2541 FROM_HERE, 2541 FROM_HERE,
2542 blocking_task_runner_, 2542 blocking_task_runner_,
2543 base::Bind(base::IgnoreResult(&file_util::Delete), 2543 base::Bind(base::IgnoreResult(&file_util::Delete),
2544 downloaded_file_path, 2544 downloaded_file_path,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, 2822 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback,
2823 ui_weak_ptr_)); 2823 ui_weak_ptr_));
2824 return GDATA_FILE_OK; 2824 return GDATA_FILE_OK;
2825 } 2825 }
2826 2826
2827 void GDataFileSystem::AddUploadedFile( 2827 void GDataFileSystem::AddUploadedFile(
2828 UploadMode upload_mode, 2828 UploadMode upload_mode,
2829 const FilePath& virtual_dir_path, 2829 const FilePath& virtual_dir_path,
2830 scoped_ptr<DocumentEntry> entry, 2830 scoped_ptr<DocumentEntry> entry,
2831 const FilePath& file_content_path, 2831 const FilePath& file_content_path,
2832 GDataCache::FileOperationType cache_operation, 2832 DriveCache::FileOperationType cache_operation,
2833 const base::Closure& callback) { 2833 const base::Closure& callback) {
2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2835 2835
2836 // Post a task to the same thread, rather than calling it here, as 2836 // Post a task to the same thread, rather than calling it here, as
2837 // AddUploadedFile() is asynchronous. 2837 // AddUploadedFile() is asynchronous.
2838 base::MessageLoopProxy::current()->PostTask( 2838 base::MessageLoopProxy::current()->PostTask(
2839 FROM_HERE, 2839 FROM_HERE,
2840 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, 2840 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread,
2841 ui_weak_ptr_, 2841 ui_weak_ptr_,
2842 upload_mode, 2842 upload_mode,
2843 virtual_dir_path, 2843 virtual_dir_path,
2844 base::Passed(&entry), 2844 base::Passed(&entry),
2845 file_content_path, 2845 file_content_path,
2846 cache_operation, 2846 cache_operation,
2847 callback)); 2847 callback));
2848 } 2848 }
2849 2849
2850 void GDataFileSystem::AddUploadedFileOnUIThread( 2850 void GDataFileSystem::AddUploadedFileOnUIThread(
2851 UploadMode upload_mode, 2851 UploadMode upload_mode,
2852 const FilePath& virtual_dir_path, 2852 const FilePath& virtual_dir_path,
2853 scoped_ptr<DocumentEntry> entry, 2853 scoped_ptr<DocumentEntry> entry,
2854 const FilePath& file_content_path, 2854 const FilePath& file_content_path,
2855 GDataCache::FileOperationType cache_operation, 2855 DriveCache::FileOperationType cache_operation,
2856 const base::Closure& callback) { 2856 const base::Closure& callback) {
2857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2858 2858
2859 // ScopedClosureRunner ensures that the specified callback is always invoked 2859 // ScopedClosureRunner ensures that the specified callback is always invoked
2860 // upon return or passed on. 2860 // upon return or passed on.
2861 base::ScopedClosureRunner callback_runner(callback); 2861 base::ScopedClosureRunner callback_runner(callback);
2862 2862
2863 if (!entry.get()) { 2863 if (!entry.get()) {
2864 NOTREACHED(); 2864 NOTREACHED();
2865 return; 2865 return;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 if (!new_entry.get()) { 2990 if (!new_entry.get()) {
2991 return; 2991 return;
2992 } 2992 }
2993 2993
2994 resource_metadata_->RefreshFile(new_entry.Pass()); 2994 resource_metadata_->RefreshFile(new_entry.Pass());
2995 2995
2996 // Add the file to the cache if we have uploaded a new file. 2996 // Add the file to the cache if we have uploaded a new file.
2997 cache_->StoreOnUIThread(resource_id, 2997 cache_->StoreOnUIThread(resource_id,
2998 md5, 2998 md5,
2999 file_content_path, 2999 file_content_path,
3000 GDataCache::FILE_OPERATION_MOVE, 3000 DriveCache::FILE_OPERATION_MOVE,
3001 base::Bind(&OnCacheUpdatedForAddUploadedFile, 3001 base::Bind(&OnCacheUpdatedForAddUploadedFile,
3002 callback)); 3002 callback));
3003 } 3003 }
3004 3004
3005 3005
3006 void GDataFileSystem::Observe(int type, 3006 void GDataFileSystem::Observe(int type,
3007 const content::NotificationSource& source, 3007 const content::NotificationSource& source,
3008 const content::NotificationDetails& details) { 3008 const content::NotificationDetails& details) {
3009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3010 3010
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
3367 return; 3367 return;
3368 } 3368 }
3369 3369
3370 PlatformFileInfoProto entry_file_info; 3370 PlatformFileInfoProto entry_file_info;
3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3372 *entry_proto->mutable_file_info() = entry_file_info; 3372 *entry_proto->mutable_file_info() = entry_file_info;
3373 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3373 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3374 } 3374 }
3375 3375
3376 } // namespace gdata 3376 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698