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

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

Issue 10873005: Rename GDataDirectoryService to DriveResourceMetadata (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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { 430 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) {
431 // Should be created from the file browser extension API on UI thread. 431 // Should be created from the file browser extension API on UI thread.
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
433 } 433 }
434 434
435 void GDataFileSystem::Initialize() { 435 void GDataFileSystem::Initialize() {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
437 437
438 drive_service_->Initialize(profile_); 438 drive_service_->Initialize(profile_);
439 439
440 directory_service_.reset(new GDataDirectoryService); 440 resource_metadata_.reset(new DriveResourceMetadata);
441 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(), 441 feed_loader_.reset(new GDataWapiFeedLoader(resource_metadata_.get(),
442 drive_service_, 442 drive_service_,
443 webapps_registry_, 443 webapps_registry_,
444 cache_, 444 cache_,
445 blocking_task_runner_)); 445 blocking_task_runner_));
446 feed_loader_->AddObserver(this); 446 feed_loader_->AddObserver(this);
447 447
448 PrefService* pref_service = profile_->GetPrefs(); 448 PrefService* pref_service = profile_->GetPrefs();
449 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 449 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
450 450
451 InitializePreferenceObserver(); 451 InitializePreferenceObserver();
452 } 452 }
453 453
454 void GDataFileSystem::CheckForUpdates() { 454 void GDataFileSystem::CheckForUpdates() {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
456 ContentOrigin initial_origin = directory_service_->origin(); 456 ContentOrigin initial_origin = resource_metadata_->origin();
457 if (initial_origin == FROM_SERVER) { 457 if (initial_origin == FROM_SERVER) {
458 directory_service_->set_origin(REFRESHING); 458 resource_metadata_->set_origin(REFRESHING);
459 feed_loader_->ReloadFromServerIfNeeded( 459 feed_loader_->ReloadFromServerIfNeeded(
460 initial_origin, 460 initial_origin,
461 directory_service_->largest_changestamp(), 461 resource_metadata_->largest_changestamp(),
462 base::Bind(&GDataFileSystem::OnUpdateChecked, 462 base::Bind(&GDataFileSystem::OnUpdateChecked,
463 ui_weak_ptr_, 463 ui_weak_ptr_,
464 initial_origin)); 464 initial_origin));
465 } 465 }
466 } 466 }
467 467
468 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, 468 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin,
469 GDataFileError error) { 469 GDataFileError error) {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
471 471
472 if (error != GDATA_FILE_OK) 472 if (error != GDATA_FILE_OK)
473 directory_service_->set_origin(initial_origin); 473 resource_metadata_->set_origin(initial_origin);
474 } 474 }
475 475
476 GDataFileSystem::~GDataFileSystem() { 476 GDataFileSystem::~GDataFileSystem() {
477 // This should be called from UI thread, from GDataSystemService shutdown. 477 // This should be called from UI thread, from GDataSystemService shutdown.
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
479 479
480 feed_loader_->RemoveObserver(this); 480 feed_loader_->RemoveObserver(this);
481 481
482 // Cancel all the in-flight operations. 482 // Cancel all the in-flight operations.
483 // This asynchronously cancels the URL fetch operations. 483 // This asynchronously cancels the URL fetch operations.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 resource_id, 533 resource_id,
534 CreateRelayCallback(callback))); 534 CreateRelayCallback(callback)));
535 } 535 }
536 536
537 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread( 537 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread(
538 const std::string& resource_id, 538 const std::string& resource_id,
539 const GetEntryInfoWithFilePathCallback& callback) { 539 const GetEntryInfoWithFilePathCallback& callback) {
540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
541 DCHECK(!callback.is_null()); 541 DCHECK(!callback.is_null());
542 542
543 directory_service_->GetEntryByResourceIdAsync(resource_id, 543 resource_metadata_->GetEntryByResourceIdAsync(resource_id,
544 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread, 544 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread,
545 ui_weak_ptr_, 545 ui_weak_ptr_,
546 callback)); 546 callback));
547 } 547 }
548 548
549 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( 549 void GDataFileSystem::GetEntryInfoByEntryOnUIThread(
550 const GetEntryInfoWithFilePathCallback& callback, 550 const GetEntryInfoWithFilePathCallback& callback,
551 DriveEntry* entry) { 551 DriveEntry* entry) {
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
553 DCHECK(!callback.is_null()); 553 DCHECK(!callback.is_null());
554 554
555 if (entry) { 555 if (entry) {
556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); 556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto);
557 entry->ToProtoFull(entry_proto.get()); 557 entry->ToProtoFull(entry_proto.get());
558 CheckLocalModificationAndRun( 558 CheckLocalModificationAndRun(
559 entry_proto.Pass(), 559 entry_proto.Pass(),
560 base::Bind(&RunGetEntryInfoWithFilePathCallback, 560 base::Bind(&RunGetEntryInfoWithFilePathCallback,
561 callback, entry->GetFilePath())); 561 callback, entry->GetFilePath()));
562 } else { 562 } else {
563 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, 563 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
564 FilePath(), 564 FilePath(),
565 scoped_ptr<DriveEntryProto>()); 565 scoped_ptr<DriveEntryProto>());
566 } 566 }
567 } 567 }
568 568
569 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) { 569 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) {
570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
571 DCHECK(!callback.is_null()); 571 DCHECK(!callback.is_null());
572 572
573 if (directory_service_->origin() == INITIALIZING) { 573 if (resource_metadata_->origin() == INITIALIZING) {
574 // If root feed is not initialized but the initialization process has 574 // If root feed is not initialized but the initialization process has
575 // already started, add an observer to execute the remaining task after 575 // already started, add an observer to execute the remaining task after
576 // the end of the initialization. 576 // the end of the initialization.
577 AddObserver(new InitialLoadObserver(this, 577 AddObserver(new InitialLoadObserver(this,
578 base::Bind(callback, GDATA_FILE_OK))); 578 base::Bind(callback, GDATA_FILE_OK)));
579 return; 579 return;
580 } else if (directory_service_->origin() == UNINITIALIZED) { 580 } else if (resource_metadata_->origin() == UNINITIALIZED) {
581 // Load root feed from this disk cache. Upon completion, kick off server 581 // Load root feed from this disk cache. Upon completion, kick off server
582 // fetching. 582 // fetching.
583 directory_service_->set_origin(INITIALIZING); 583 resource_metadata_->set_origin(INITIALIZING);
584 feed_loader_->LoadFromCache( 584 feed_loader_->LoadFromCache(
585 true, // should_load_from_server 585 true, // should_load_from_server
586 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun, 586 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun,
587 ui_weak_ptr_, 587 ui_weak_ptr_,
588 callback)); 588 callback));
589 return; 589 return;
590 } 590 }
591 591
592 // The feed has already been loaded, so we have nothing to do, but post a 592 // The feed has already been loaded, so we have nothing to do, but post a
593 // task to the same thread, rather than calling it here, as 593 // task to the same thread, rather than calling it here, as
(...skipping 19 matching lines...) Expand all
613 } 613 }
614 614
615 void GDataFileSystem::TransferFileFromLocalToRemote( 615 void GDataFileSystem::TransferFileFromLocalToRemote(
616 const FilePath& local_src_file_path, 616 const FilePath& local_src_file_path,
617 const FilePath& remote_dest_file_path, 617 const FilePath& remote_dest_file_path,
618 const FileOperationCallback& callback) { 618 const FileOperationCallback& callback) {
619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
620 DCHECK(!callback.is_null()); 620 DCHECK(!callback.is_null());
621 621
622 // Make sure the destination directory exists. 622 // Make sure the destination directory exists.
623 directory_service_->GetEntryInfoByPath( 623 resource_metadata_->GetEntryInfoByPath(
624 remote_dest_file_path.DirName(), 624 remote_dest_file_path.DirName(),
625 base::Bind( 625 base::Bind(
626 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, 626 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo,
627 ui_weak_ptr_, 627 ui_weak_ptr_,
628 local_src_file_path, 628 local_src_file_path,
629 remote_dest_file_path, 629 remote_dest_file_path,
630 callback)); 630 callback));
631 } 631 }
632 632
633 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( 633 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 DCHECK(content_type); 733 DCHECK(content_type);
734 734
735 if (*error != GDATA_FILE_OK) { 735 if (*error != GDATA_FILE_OK) {
736 if (!params.callback.is_null()) 736 if (!params.callback.is_null())
737 params.callback.Run(*error); 737 params.callback.Run(*error);
738 738
739 return; 739 return;
740 } 740 }
741 741
742 // Make sure the destination directory exists. 742 // Make sure the destination directory exists.
743 directory_service_->GetEntryInfoByPath( 743 resource_metadata_->GetEntryInfoByPath(
744 params.remote_file_path.DirName(), 744 params.remote_file_path.DirName(),
745 base::Bind( 745 base::Bind(
746 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, 746 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo,
747 ui_weak_ptr_, 747 ui_weak_ptr_,
748 params, 748 params,
749 *file_size, 749 *file_size,
750 *content_type)); 750 *content_type));
751 } 751 }
752 752
753 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( 753 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 dest_file_path, 821 dest_file_path,
822 CreateRelayCallback(callback))); 822 CreateRelayCallback(callback)));
823 } 823 }
824 824
825 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, 825 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path,
826 const FilePath& dest_file_path, 826 const FilePath& dest_file_path,
827 const FileOperationCallback& callback) { 827 const FileOperationCallback& callback) {
828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
829 DCHECK(!callback.is_null()); 829 DCHECK(!callback.is_null());
830 830
831 directory_service_->GetEntryInfoPairByPaths( 831 resource_metadata_->GetEntryInfoPairByPaths(
832 src_file_path, 832 src_file_path,
833 dest_file_path.DirName(), 833 dest_file_path.DirName(),
834 base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair, 834 base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair,
835 ui_weak_ptr_, 835 ui_weak_ptr_,
836 dest_file_path, 836 dest_file_path,
837 callback)); 837 callback));
838 } 838 }
839 839
840 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( 840 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair(
841 const FilePath& dest_file_path, 841 const FilePath& dest_file_path,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
962 DCHECK(!callback.is_null()); 962 DCHECK(!callback.is_null());
963 963
964 // It is a no-op if the file is renamed to the same name. 964 // It is a no-op if the file is renamed to the same name.
965 if (file_path.BaseName().value() == new_name) { 965 if (file_path.BaseName().value() == new_name) {
966 callback.Run(GDATA_FILE_OK, file_path); 966 callback.Run(GDATA_FILE_OK, file_path);
967 return; 967 return;
968 } 968 }
969 969
970 // Get the edit URL of an entry at |file_path|. 970 // Get the edit URL of an entry at |file_path|.
971 directory_service_->GetEntryInfoByPath( 971 resource_metadata_->GetEntryInfoByPath(
972 file_path, 972 file_path,
973 base::Bind( 973 base::Bind(
974 &GDataFileSystem::RenameAfterGetEntryInfo, 974 &GDataFileSystem::RenameAfterGetEntryInfo,
975 ui_weak_ptr_, 975 ui_weak_ptr_,
976 file_path, 976 file_path,
977 new_name, 977 new_name,
978 callback)); 978 callback));
979 } 979 }
980 980
981 void GDataFileSystem::RenameAfterGetEntryInfo( 981 void GDataFileSystem::RenameAfterGetEntryInfo(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 dest_file_path, 1029 dest_file_path,
1030 CreateRelayCallback(callback))); 1030 CreateRelayCallback(callback)));
1031 } 1031 }
1032 1032
1033 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, 1033 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path,
1034 const FilePath& dest_file_path, 1034 const FilePath& dest_file_path,
1035 const FileOperationCallback& callback) { 1035 const FileOperationCallback& callback) {
1036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1037 DCHECK(!callback.is_null()); 1037 DCHECK(!callback.is_null());
1038 1038
1039 directory_service_->GetEntryInfoPairByPaths( 1039 resource_metadata_->GetEntryInfoPairByPaths(
1040 src_file_path, 1040 src_file_path,
1041 dest_file_path.DirName(), 1041 dest_file_path.DirName(),
1042 base::Bind(&GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair, 1042 base::Bind(&GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair,
1043 ui_weak_ptr_, 1043 ui_weak_ptr_,
1044 dest_file_path, 1044 dest_file_path,
1045 callback)); 1045 callback));
1046 } 1046 }
1047 1047
1048 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( 1048 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair(
1049 const FilePath& dest_file_path, 1049 const FilePath& dest_file_path,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 remove_file_from_directory_callback); 1105 remove_file_from_directory_callback);
1106 } 1106 }
1107 1107
1108 void GDataFileSystem::MoveEntryFromRootDirectory( 1108 void GDataFileSystem::MoveEntryFromRootDirectory(
1109 const FilePath& dir_path, 1109 const FilePath& dir_path,
1110 const FileOperationCallback& callback, 1110 const FileOperationCallback& callback,
1111 GDataFileError error, 1111 GDataFileError error,
1112 const FilePath& file_path) { 1112 const FilePath& file_path) {
1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1114 DCHECK(!callback.is_null()); 1114 DCHECK(!callback.is_null());
1115 DCHECK_EQ(kGDataRootDirectory, file_path.DirName().value()); 1115 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value());
1116 1116
1117 // Return if there is an error or |dir_path| is the root directory. 1117 // Return if there is an error or |dir_path| is the root directory.
1118 if (error != GDATA_FILE_OK || dir_path == FilePath(kGDataRootDirectory)) { 1118 if (error != GDATA_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) {
1119 callback.Run(error); 1119 callback.Run(error);
1120 return; 1120 return;
1121 } 1121 }
1122 1122
1123 directory_service_->GetEntryInfoPairByPaths( 1123 resource_metadata_->GetEntryInfoPairByPaths(
1124 file_path, 1124 file_path,
1125 dir_path, 1125 dir_path,
1126 base::Bind( 1126 base::Bind(
1127 &GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, 1127 &GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair,
1128 ui_weak_ptr_, 1128 ui_weak_ptr_,
1129 callback)); 1129 callback));
1130 } 1130 }
1131 1131
1132 void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( 1132 void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair(
1133 const FileOperationCallback& callback, 1133 const FileOperationCallback& callback,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 1166
1167 void GDataFileSystem::RemoveEntryFromNonRootDirectory( 1167 void GDataFileSystem::RemoveEntryFromNonRootDirectory(
1168 const FileMoveCallback& callback, 1168 const FileMoveCallback& callback,
1169 GDataFileError error, 1169 GDataFileError error,
1170 const FilePath& file_path) { 1170 const FilePath& file_path) {
1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1172 DCHECK(!callback.is_null()); 1172 DCHECK(!callback.is_null());
1173 1173
1174 const FilePath dir_path = file_path.DirName(); 1174 const FilePath dir_path = file_path.DirName();
1175 // Return if there is an error or |dir_path| is the root directory. 1175 // Return if there is an error or |dir_path| is the root directory.
1176 if (error != GDATA_FILE_OK || dir_path == FilePath(kGDataRootDirectory)) { 1176 if (error != GDATA_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) {
1177 callback.Run(error, file_path); 1177 callback.Run(error, file_path);
1178 return; 1178 return;
1179 } 1179 }
1180 1180
1181 directory_service_->GetEntryInfoPairByPaths( 1181 resource_metadata_->GetEntryInfoPairByPaths(
1182 file_path, 1182 file_path,
1183 dir_path, 1183 dir_path,
1184 base::Bind( 1184 base::Bind(
1185 &GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, 1185 &GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair,
1186 ui_weak_ptr_, 1186 ui_weak_ptr_,
1187 callback)); 1187 callback));
1188 } 1188 }
1189 1189
1190 void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( 1190 void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair(
1191 const FileMoveCallback& callback, 1191 const FileMoveCallback& callback,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 CreateRelayCallback(callback))); 1235 CreateRelayCallback(callback)));
1236 } 1236 }
1237 1237
1238 void GDataFileSystem::RemoveOnUIThread( 1238 void GDataFileSystem::RemoveOnUIThread(
1239 const FilePath& file_path, 1239 const FilePath& file_path,
1240 bool is_recursive, 1240 bool is_recursive,
1241 const FileOperationCallback& callback) { 1241 const FileOperationCallback& callback) {
1242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1243 1243
1244 // Get the edit URL of an entry at |file_path|. 1244 // Get the edit URL of an entry at |file_path|.
1245 directory_service_->GetEntryInfoByPath( 1245 resource_metadata_->GetEntryInfoByPath(
1246 file_path, 1246 file_path,
1247 base::Bind( 1247 base::Bind(
1248 &GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo, 1248 &GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo,
1249 ui_weak_ptr_, 1249 ui_weak_ptr_,
1250 file_path, 1250 file_path,
1251 is_recursive, 1251 is_recursive,
1252 callback)); 1252 callback));
1253 } 1253 }
1254 1254
1255 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo( 1255 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 } 1374 }
1375 1375
1376 void GDataFileSystem::CreateFileOnUIThread( 1376 void GDataFileSystem::CreateFileOnUIThread(
1377 const FilePath& file_path, 1377 const FilePath& file_path,
1378 bool is_exclusive, 1378 bool is_exclusive,
1379 const FileOperationCallback& callback) { 1379 const FileOperationCallback& callback) {
1380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1381 DCHECK(!callback.is_null()); 1381 DCHECK(!callback.is_null());
1382 1382
1383 // First, checks the existence of a file at |file_path|. 1383 // First, checks the existence of a file at |file_path|.
1384 directory_service_->GetEntryInfoByPath( 1384 resource_metadata_->GetEntryInfoByPath(
1385 file_path, 1385 file_path,
1386 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile, 1386 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile,
1387 ui_weak_ptr_, 1387 ui_weak_ptr_,
1388 file_path, 1388 file_path,
1389 is_exclusive, 1389 is_exclusive,
1390 callback)); 1390 callback));
1391 } 1391 }
1392 1392
1393 void GDataFileSystem::OnGetEntryInfoForCreateFile( 1393 void GDataFileSystem::OnGetEntryInfoForCreateFile(
1394 const FilePath& file_path, 1394 const FilePath& file_path,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 CreateRelayCallback(get_file_callback), 1442 CreateRelayCallback(get_file_callback),
1443 CreateRelayCallback(get_content_callback))); 1443 CreateRelayCallback(get_content_callback)));
1444 } 1444 }
1445 1445
1446 void GDataFileSystem::GetFileByPathOnUIThread( 1446 void GDataFileSystem::GetFileByPathOnUIThread(
1447 const FilePath& file_path, 1447 const FilePath& file_path,
1448 const GetFileCallback& get_file_callback, 1448 const GetFileCallback& get_file_callback,
1449 const GetContentCallback& get_content_callback) { 1449 const GetContentCallback& get_content_callback) {
1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1451 1451
1452 directory_service_->GetEntryInfoByPath( 1452 resource_metadata_->GetEntryInfoByPath(
1453 file_path, 1453 file_path,
1454 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath, 1454 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath,
1455 ui_weak_ptr_, 1455 ui_weak_ptr_,
1456 file_path, 1456 file_path,
1457 CreateRelayCallback(get_file_callback), 1457 CreateRelayCallback(get_file_callback),
1458 CreateRelayCallback(get_content_callback))); 1458 CreateRelayCallback(get_content_callback)));
1459 } 1459 }
1460 1460
1461 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath( 1461 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath(
1462 const FilePath& file_path, 1462 const FilePath& file_path,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 CreateRelayCallback(get_file_callback), 1567 CreateRelayCallback(get_file_callback),
1568 CreateRelayCallback(get_content_callback))); 1568 CreateRelayCallback(get_content_callback)));
1569 } 1569 }
1570 1570
1571 void GDataFileSystem::GetFileByResourceIdOnUIThread( 1571 void GDataFileSystem::GetFileByResourceIdOnUIThread(
1572 const std::string& resource_id, 1572 const std::string& resource_id,
1573 const GetFileCallback& get_file_callback, 1573 const GetFileCallback& get_file_callback,
1574 const GetContentCallback& get_content_callback) { 1574 const GetContentCallback& get_content_callback) {
1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1576 1576
1577 directory_service_->GetEntryByResourceIdAsync(resource_id, 1577 resource_metadata_->GetEntryByResourceIdAsync(resource_id,
1578 base::Bind(&GDataFileSystem::GetFileByEntryOnUIThread, 1578 base::Bind(&GDataFileSystem::GetFileByEntryOnUIThread,
1579 ui_weak_ptr_, 1579 ui_weak_ptr_,
1580 get_file_callback, 1580 get_file_callback,
1581 get_content_callback)); 1581 get_content_callback));
1582 } 1582 }
1583 1583
1584 void GDataFileSystem::GetFileByEntryOnUIThread( 1584 void GDataFileSystem::GetFileByEntryOnUIThread(
1585 const GetFileCallback& get_file_callback, 1585 const GetFileCallback& get_file_callback,
1586 const GetContentCallback& get_content_callback, 1586 const GetContentCallback& get_content_callback,
1587 DriveEntry* entry) { 1587 DriveEntry* entry) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 GDataErrorCode status, 1661 GDataErrorCode status,
1662 scoped_ptr<base::Value> data) { 1662 scoped_ptr<base::Value> data) {
1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1664 1664
1665 GDataFileError error = util::GDataToGDataFileError(status); 1665 GDataFileError error = util::GDataToGDataFileError(status);
1666 1666
1667 scoped_ptr<DriveEntry> fresh_entry; 1667 scoped_ptr<DriveEntry> fresh_entry;
1668 if (error == GDATA_FILE_OK) { 1668 if (error == GDATA_FILE_OK) {
1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
1670 if (doc_entry.get()) 1670 if (doc_entry.get())
1671 fresh_entry.reset(directory_service_->FromDocumentEntry(*doc_entry)); 1671 fresh_entry.reset(resource_metadata_->FromDocumentEntry(*doc_entry));
1672 if (!fresh_entry.get() || !fresh_entry->AsDriveFile()) { 1672 if (!fresh_entry.get() || !fresh_entry->AsDriveFile()) {
1673 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; 1673 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id;
1674 error = GDATA_FILE_ERROR_FAILED; 1674 error = GDATA_FILE_ERROR_FAILED;
1675 } 1675 }
1676 } 1676 }
1677 1677
1678 if (error != GDATA_FILE_OK) { 1678 if (error != GDATA_FILE_OK) {
1679 if (!params.get_file_callback.is_null()) { 1679 if (!params.get_file_callback.is_null()) {
1680 params.get_file_callback.Run(error, 1680 params.get_file_callback.Run(error,
1681 cache_file_path, 1681 cache_file_path,
1682 params.mime_type, 1682 params.mime_type,
1683 REGULAR_FILE); 1683 REGULAR_FILE);
1684 } 1684 }
1685 return; 1685 return;
1686 } 1686 }
1687 1687
1688 GURL content_url = fresh_entry->content_url(); 1688 GURL content_url = fresh_entry->content_url();
1689 int64 file_size = fresh_entry->file_info().size; 1689 int64 file_size = fresh_entry->file_info().size;
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 directory_service_->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(&GDataCache::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,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 const GetEntryInfoCallback& callback, 1769 const GetEntryInfoCallback& callback,
1770 GDataFileError error) { 1770 GDataFileError error) {
1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1772 DCHECK(!callback.is_null()); 1772 DCHECK(!callback.is_null());
1773 1773
1774 if (error != GDATA_FILE_OK) { 1774 if (error != GDATA_FILE_OK) {
1775 callback.Run(error, scoped_ptr<DriveEntryProto>()); 1775 callback.Run(error, scoped_ptr<DriveEntryProto>());
1776 return; 1776 return;
1777 } 1777 }
1778 1778
1779 directory_service_->GetEntryInfoByPath( 1779 resource_metadata_->GetEntryInfoByPath(
1780 file_path, 1780 file_path,
1781 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, 1781 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry,
1782 ui_weak_ptr_, 1782 ui_weak_ptr_,
1783 callback)); 1783 callback));
1784 } 1784 }
1785 1785
1786 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( 1786 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry(
1787 const GetEntryInfoCallback& callback, 1787 const GetEntryInfoCallback& callback,
1788 GDataFileError error, 1788 GDataFileError error,
1789 scoped_ptr<DriveEntryProto> entry_proto) { 1789 scoped_ptr<DriveEntryProto> entry_proto) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1834 DCHECK(!callback.is_null()); 1834 DCHECK(!callback.is_null());
1835 1835
1836 if (error != GDATA_FILE_OK) { 1836 if (error != GDATA_FILE_OK) {
1837 callback.Run(error, 1837 callback.Run(error,
1838 hide_hosted_docs_, 1838 hide_hosted_docs_,
1839 scoped_ptr<DriveEntryProtoVector>()); 1839 scoped_ptr<DriveEntryProtoVector>());
1840 return; 1840 return;
1841 } 1841 }
1842 1842
1843 directory_service_->ReadDirectoryByPath( 1843 resource_metadata_->ReadDirectoryByPath(
1844 file_path, 1844 file_path,
1845 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, 1845 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead,
1846 ui_weak_ptr_, 1846 ui_weak_ptr_,
1847 callback)); 1847 callback));
1848 } 1848 }
1849 1849
1850 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( 1850 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead(
1851 const ReadDirectoryWithSettingCallback& callback, 1851 const ReadDirectoryWithSettingCallback& callback,
1852 GDataFileError error, 1852 GDataFileError error,
1853 scoped_ptr<DriveEntryProtoVector> entries) { 1853 scoped_ptr<DriveEntryProtoVector> entries) {
(...skipping 18 matching lines...) Expand all
1872 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, 1872 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread,
1873 ui_weak_ptr_, 1873 ui_weak_ptr_,
1874 file_path)); 1874 file_path));
1875 } 1875 }
1876 1876
1877 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( 1877 void GDataFileSystem::RequestDirectoryRefreshOnUIThread(
1878 const FilePath& file_path) { 1878 const FilePath& file_path) {
1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1880 1880
1881 // Make sure the destination directory exists. 1881 // Make sure the destination directory exists.
1882 directory_service_->GetEntryInfoByPath( 1882 resource_metadata_->GetEntryInfoByPath(
1883 file_path, 1883 file_path,
1884 base::Bind( 1884 base::Bind(
1885 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, 1885 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo,
1886 ui_weak_ptr_, 1886 ui_weak_ptr_,
1887 file_path)); 1887 file_path));
1888 } 1888 }
1889 1889
1890 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( 1890 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo(
1891 const FilePath& file_path, 1891 const FilePath& file_path,
1892 GDataFileError error, 1892 GDataFileError error,
1893 scoped_ptr<DriveEntryProto> entry_proto) { 1893 scoped_ptr<DriveEntryProto> entry_proto) {
1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1895 1895
1896 if (error != GDATA_FILE_OK || 1896 if (error != GDATA_FILE_OK ||
1897 !entry_proto->file_info().is_directory()) { 1897 !entry_proto->file_info().is_directory()) {
1898 LOG(ERROR) << "Directory entry not found: " << file_path.value(); 1898 LOG(ERROR) << "Directory entry not found: " << file_path.value();
1899 return; 1899 return;
1900 } 1900 }
1901 1901
1902 feed_loader_->LoadDirectoryFromServer( 1902 feed_loader_->LoadDirectoryFromServer(
1903 directory_service_->origin(), 1903 resource_metadata_->origin(),
1904 entry_proto->resource_id(), 1904 entry_proto->resource_id(),
1905 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, 1905 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
1906 ui_weak_ptr_, 1906 ui_weak_ptr_,
1907 file_path)); 1907 file_path));
1908 } 1908 }
1909 1909
1910 void GDataFileSystem::OnRequestDirectoryRefresh( 1910 void GDataFileSystem::OnRequestDirectoryRefresh(
1911 const FilePath& directory_path, 1911 const FilePath& directory_path,
1912 GetDocumentsParams* params, 1912 GetDocumentsParams* params,
1913 GDataFileError error) { 1913 GDataFileError error) {
1914 DCHECK(params); 1914 DCHECK(params);
1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1916 1916
1917 if (error != GDATA_FILE_OK) { 1917 if (error != GDATA_FILE_OK) {
1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() 1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value()
1919 << ": " << error; 1919 << ": " << error;
1920 return; 1920 return;
1921 } 1921 }
1922 1922
1923 int64 unused_delta_feed_changestamp = 0; 1923 int64 unused_delta_feed_changestamp = 0;
1924 FeedToFileResourceMapUmaStats unused_uma_stats; 1924 FeedToFileResourceMapUmaStats unused_uma_stats;
1925 FileResourceIdMap file_map; 1925 FileResourceIdMap file_map;
1926 GDataWapiFeedProcessor feed_processor(directory_service_.get()); 1926 GDataWapiFeedProcessor feed_processor(resource_metadata_.get());
1927 error = feed_processor.FeedToFileResourceMap( 1927 error = feed_processor.FeedToFileResourceMap(
1928 *params->feed_list, 1928 *params->feed_list,
1929 &file_map, 1929 &file_map,
1930 &unused_delta_feed_changestamp, 1930 &unused_delta_feed_changestamp,
1931 &unused_uma_stats); 1931 &unused_uma_stats);
1932 if (error != GDATA_FILE_OK) { 1932 if (error != GDATA_FILE_OK) {
1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() 1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value()
1934 << ": " << error; 1934 << ": " << error;
1935 return; 1935 return;
1936 } 1936 }
1937 1937
1938 directory_service_->RefreshDirectory( 1938 resource_metadata_->RefreshDirectory(
1939 params->directory_resource_id, 1939 params->directory_resource_id,
1940 file_map, 1940 file_map,
1941 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, 1941 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback,
1942 ui_weak_ptr_)); 1942 ui_weak_ptr_));
1943 } 1943 }
1944 1944
1945 void GDataFileSystem::UpdateFileByResourceId( 1945 void GDataFileSystem::UpdateFileByResourceId(
1946 const std::string& resource_id, 1946 const std::string& resource_id,
1947 const FileOperationCallback& callback) { 1947 const FileOperationCallback& callback) {
1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1949 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1949 BrowserThread::CurrentlyOn(BrowserThread::IO));
1950 DCHECK(!callback.is_null()); 1950 DCHECK(!callback.is_null());
1951 1951
1952 RunTaskOnUIThread( 1952 RunTaskOnUIThread(
1953 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, 1953 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread,
1954 ui_weak_ptr_, 1954 ui_weak_ptr_,
1955 resource_id, 1955 resource_id,
1956 CreateRelayCallback(callback))); 1956 CreateRelayCallback(callback)));
1957 } 1957 }
1958 1958
1959 void GDataFileSystem::UpdateFileByResourceIdOnUIThread( 1959 void GDataFileSystem::UpdateFileByResourceIdOnUIThread(
1960 const std::string& resource_id, 1960 const std::string& resource_id,
1961 const FileOperationCallback& callback) { 1961 const FileOperationCallback& callback) {
1962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1963 DCHECK(!callback.is_null()); 1963 DCHECK(!callback.is_null());
1964 1964
1965 // TODO(satorux): GetEntryInfoByResourceId() is called twice for 1965 // TODO(satorux): GetEntryInfoByResourceId() is called twice for
1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873
1967 directory_service_->GetEntryInfoByResourceId( 1967 resource_metadata_->GetEntryInfoByResourceId(
1968 resource_id, 1968 resource_id,
1969 base::Bind(&GDataFileSystem::UpdateFileByEntryInfo, 1969 base::Bind(&GDataFileSystem::UpdateFileByEntryInfo,
1970 ui_weak_ptr_, 1970 ui_weak_ptr_,
1971 callback)); 1971 callback));
1972 } 1972 }
1973 1973
1974 void GDataFileSystem::UpdateFileByEntryInfo( 1974 void GDataFileSystem::UpdateFileByEntryInfo(
1975 const FileOperationCallback& callback, 1975 const FileOperationCallback& callback,
1976 GDataFileError error, 1976 GDataFileError error,
1977 const FilePath& /* dive_file_path */, 1977 const FilePath& /* dive_file_path */,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2042 DCHECK(!callback.is_null()); 2042 DCHECK(!callback.is_null());
2043 2043
2044 if (*error != GDATA_FILE_OK) { 2044 if (*error != GDATA_FILE_OK) {
2045 callback.Run(*error); 2045 callback.Run(*error);
2046 return; 2046 return;
2047 } 2047 }
2048 2048
2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for 2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for
2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873
2051 directory_service_->GetEntryInfoByResourceId( 2051 resource_metadata_->GetEntryInfoByResourceId(
2052 resource_id, 2052 resource_id,
2053 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, 2053 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry,
2054 ui_weak_ptr_, 2054 ui_weak_ptr_,
2055 callback, 2055 callback,
2056 *file_size, 2056 *file_size,
2057 cache_file_path)); 2057 cache_file_path));
2058 } 2058 }
2059 2059
2060 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( 2060 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry(
2061 const FileOperationCallback& callback, 2061 const FileOperationCallback& callback,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); 2258 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results);
2259 if (!callback.is_null()) 2259 if (!callback.is_null())
2260 callback.Run(error, next_feed, result_vec.Pass()); 2260 callback.Run(error, next_feed, result_vec.Pass());
2261 return; 2261 return;
2262 } 2262 }
2263 2263
2264 // Go through all entires generated by the feed and add them to the search 2264 // Go through all entires generated by the feed and add them to the search
2265 // result directory. 2265 // result directory.
2266 for (size_t i = 0; i < feed->entries().size(); ++i) { 2266 for (size_t i = 0; i < feed->entries().size(); ++i) {
2267 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]); 2267 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]);
2268 scoped_ptr<DriveEntry> entry(directory_service_->FromDocumentEntry(*doc)); 2268 scoped_ptr<DriveEntry> entry(resource_metadata_->FromDocumentEntry(*doc));
2269 2269
2270 if (!entry.get()) 2270 if (!entry.get())
2271 continue; 2271 continue;
2272 2272
2273 DCHECK_EQ(doc->resource_id(), entry->resource_id()); 2273 DCHECK_EQ(doc->resource_id(), entry->resource_id());
2274 DCHECK(!entry->is_deleted()); 2274 DCHECK(!entry->is_deleted());
2275 2275
2276 std::string entry_resource_id = entry->resource_id(); 2276 std::string entry_resource_id = entry->resource_id();
2277 2277
2278 // This will do nothing if the entry is not already present in file system. 2278 // This will do nothing if the entry is not already present in file system.
2279 if (entry->AsDriveFile()) { 2279 if (entry->AsDriveFile()) {
2280 scoped_ptr<DriveFile> entry_as_file(entry.release()->AsDriveFile()); 2280 scoped_ptr<DriveFile> entry_as_file(entry.release()->AsDriveFile());
2281 directory_service_->RefreshFile(entry_as_file.Pass()); 2281 resource_metadata_->RefreshFile(entry_as_file.Pass());
2282 // We shouldn't use entry object after this point. 2282 // We shouldn't use entry object after this point.
2283 DCHECK(!entry.get()); 2283 DCHECK(!entry.get());
2284 } 2284 }
2285 2285
2286 // We will need information about result entry to create info for callback. 2286 // We will need information about result entry to create info for callback.
2287 // We can't use |entry| anymore, so we have to refetch entry from file 2287 // We can't use |entry| anymore, so we have to refetch entry from file
2288 // system. Also, |entry| doesn't have file path set before |RefreshFile| 2288 // system. Also, |entry| doesn't have file path set before |RefreshFile|
2289 // call, so we can't get file path from there. 2289 // call, so we can't get file path from there.
2290 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, 2290 resource_metadata_->GetEntryByResourceIdAsync(entry_resource_id,
2291 base::Bind(&AddEntryToSearchResults, 2291 base::Bind(&AddEntryToSearchResults,
2292 results, 2292 results,
2293 callback, 2293 callback,
2294 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), 2294 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_),
2295 error, 2295 error,
2296 i+1 == feed->entries().size(), 2296 i+1 == feed->entries().size(),
2297 next_feed)); 2297 next_feed));
2298 } 2298 }
2299 } 2299 }
2300 2300
2301 void GDataFileSystem::Search(const std::string& search_query, 2301 void GDataFileSystem::Search(const std::string& search_query,
2302 const GURL& next_feed, 2302 const GURL& next_feed,
2303 const SearchCallback& callback) { 2303 const SearchCallback& callback) {
2304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2305 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2305 BrowserThread::CurrentlyOn(BrowserThread::IO));
2306 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, 2306 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread,
2307 ui_weak_ptr_, 2307 ui_weak_ptr_,
2308 search_query, 2308 search_query,
2309 next_feed, 2309 next_feed,
2310 CreateRelayCallback(callback))); 2310 CreateRelayCallback(callback)));
2311 } 2311 }
2312 2312
2313 void GDataFileSystem::SearchAsyncOnUIThread( 2313 void GDataFileSystem::SearchAsyncOnUIThread(
2314 const std::string& search_query, 2314 const std::string& search_query,
2315 const GURL& next_feed, 2315 const GURL& next_feed,
2316 const SearchCallback& callback) { 2316 const SearchCallback& callback) {
2317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2318 2318
2319 feed_loader_->SearchFromServer( 2319 feed_loader_->SearchFromServer(
2320 directory_service_->origin(), 2320 resource_metadata_->origin(),
2321 search_query, 2321 search_query,
2322 next_feed, 2322 next_feed,
2323 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); 2323 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback));
2324 } 2324 }
2325 2325
2326 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { 2326 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) {
2327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2328 2328
2329 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2329 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2330 OnDirectoryChanged(directory_path)); 2330 OnDirectoryChanged(directory_path));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 callback.Run(error); 2384 callback.Run(error);
2385 return; 2385 return;
2386 } 2386 }
2387 2387
2388 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 2388 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
2389 if (!doc_entry.get()) { 2389 if (!doc_entry.get()) {
2390 callback.Run(GDATA_FILE_ERROR_FAILED); 2390 callback.Run(GDATA_FILE_ERROR_FAILED);
2391 return; 2391 return;
2392 } 2392 }
2393 2393
2394 DriveEntry* entry = directory_service_->FromDocumentEntry(*doc_entry); 2394 DriveEntry* entry = resource_metadata_->FromDocumentEntry(*doc_entry);
2395 if (!entry) { 2395 if (!entry) {
2396 callback.Run(GDATA_FILE_ERROR_FAILED); 2396 callback.Run(GDATA_FILE_ERROR_FAILED);
2397 return; 2397 return;
2398 } 2398 }
2399 2399
2400 // |entry| was added in the root directory on the server, so we should 2400 // |entry| was added in the root directory on the server, so we should
2401 // first add it to |root_| to mirror the state and then move it to the 2401 // first add it to |root_| to mirror the state and then move it to the
2402 // destination directory by MoveEntryFromRootDirectory(). 2402 // destination directory by MoveEntryFromRootDirectory().
2403 directory_service_->AddEntryToDirectory( 2403 resource_metadata_->AddEntryToDirectory(
2404 directory_service_->root(), 2404 resource_metadata_->root(),
2405 entry, 2405 entry,
2406 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, 2406 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory,
2407 ui_weak_ptr_, 2407 ui_weak_ptr_,
2408 dir_path, 2408 dir_path,
2409 callback)); 2409 callback));
2410 } 2410 }
2411 2411
2412 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( 2412 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted(
2413 const FileOperationCallback& callback, 2413 const FileOperationCallback& callback,
2414 const FilePath& file_path, 2414 const FilePath& file_path,
2415 const FilePath& dir_path, 2415 const FilePath& dir_path,
2416 GDataErrorCode status, 2416 GDataErrorCode status,
2417 const GURL& document_url) { 2417 const GURL& document_url) {
2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2419 DCHECK(!callback.is_null()); 2419 DCHECK(!callback.is_null());
2420 2420
2421 GDataFileError error = util::GDataToGDataFileError(status); 2421 GDataFileError error = util::GDataToGDataFileError(status);
2422 if (error == GDATA_FILE_OK) { 2422 if (error == GDATA_FILE_OK) {
2423 DriveEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2423 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path);
2424 if (entry) { 2424 if (entry) {
2425 DCHECK_EQ(directory_service_->root(), entry->parent()); 2425 DCHECK_EQ(resource_metadata_->root(), entry->parent());
2426 directory_service_->MoveEntryToDirectory( 2426 resource_metadata_->MoveEntryToDirectory(
2427 dir_path, 2427 dir_path,
2428 entry, 2428 entry,
2429 base::Bind( 2429 base::Bind(
2430 &GDataFileSystem::NotifyAndRunFileOperationCallback, 2430 &GDataFileSystem::NotifyAndRunFileOperationCallback,
2431 ui_weak_ptr_, 2431 ui_weak_ptr_,
2432 callback)); 2432 callback));
2433 return; 2433 return;
2434 } else { 2434 } else {
2435 error = GDATA_FILE_ERROR_NOT_FOUND; 2435 error = GDATA_FILE_ERROR_NOT_FOUND;
2436 } 2436 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 const GURL& document_url) { 2570 const GURL& document_url) {
2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2572 2572
2573 const GDataFileError error = util::GDataToGDataFileError(status); 2573 const GDataFileError error = util::GDataToGDataFileError(status);
2574 if (error != GDATA_FILE_OK) { 2574 if (error != GDATA_FILE_OK) {
2575 if (!callback.is_null()) 2575 if (!callback.is_null())
2576 callback.Run(error, FilePath()); 2576 callback.Run(error, FilePath());
2577 return; 2577 return;
2578 } 2578 }
2579 2579
2580 DriveEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2580 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path);
2581 if (!entry) { 2581 if (!entry) {
2582 if (!callback.is_null()) 2582 if (!callback.is_null())
2583 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); 2583 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2584 return; 2584 return;
2585 } 2585 }
2586 2586
2587 DCHECK(entry->parent()); 2587 DCHECK(entry->parent());
2588 entry->set_title(new_name); 2588 entry->set_title(new_name);
2589 // After changing the title of the entry, call MoveEntryToDirectory() to 2589 // After changing the title of the entry, call MoveEntryToDirectory() to
2590 // remove the entry from its parent directory and then add it back in order to 2590 // remove the entry from its parent directory and then add it back in order to
2591 // go through the file name de-duplication. 2591 // go through the file name de-duplication.
2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been 2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been
2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to 2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to
2594 // remove the child based on the old file_name, and then re-adds the child by 2594 // remove the child based on the old file_name, and then re-adds the child by
2595 // first assigning the new title to file_name. http://crbug.com/30157 2595 // first assigning the new title to file_name. http://crbug.com/30157
2596 directory_service_->MoveEntryToDirectory( 2596 resource_metadata_->MoveEntryToDirectory(
2597 entry->parent()->GetFilePath(), 2597 entry->parent()->GetFilePath(),
2598 entry, 2598 entry,
2599 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, 2599 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2600 ui_weak_ptr_, 2600 ui_weak_ptr_,
2601 callback)); 2601 callback));
2602 } 2602 }
2603 2603
2604 void GDataFileSystem::MoveEntryToRootDirectoryLocally( 2604 void GDataFileSystem::MoveEntryToRootDirectoryLocally(
2605 const FileMoveCallback& callback, 2605 const FileMoveCallback& callback,
2606 const FilePath& file_path, 2606 const FilePath& file_path,
2607 const FilePath& dir_path, 2607 const FilePath& dir_path,
2608 GDataErrorCode status, 2608 GDataErrorCode status,
2609 const GURL& document_url) { 2609 const GURL& document_url) {
2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2611 DCHECK(!callback.is_null()); 2611 DCHECK(!callback.is_null());
2612 2612
2613 const GDataFileError error = util::GDataToGDataFileError(status); 2613 const GDataFileError error = util::GDataToGDataFileError(status);
2614 if (error != GDATA_FILE_OK) { 2614 if (error != GDATA_FILE_OK) {
2615 callback.Run(error, FilePath()); 2615 callback.Run(error, FilePath());
2616 return; 2616 return;
2617 } 2617 }
2618 2618
2619 DriveEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2619 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path);
2620 if (!entry) { 2620 if (!entry) {
2621 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); 2621 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2622 return; 2622 return;
2623 } 2623 }
2624 2624
2625 directory_service_->MoveEntryToDirectory( 2625 resource_metadata_->MoveEntryToDirectory(
2626 directory_service_->root()->GetFilePath(), 2626 resource_metadata_->root()->GetFilePath(),
2627 entry, 2627 entry,
2628 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, 2628 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2629 ui_weak_ptr_, 2629 ui_weak_ptr_,
2630 callback)); 2630 callback));
2631 } 2631 }
2632 2632
2633 void GDataFileSystem::NotifyAndRunFileMoveCallback( 2633 void GDataFileSystem::NotifyAndRunFileMoveCallback(
2634 const FileMoveCallback& callback, 2634 const FileMoveCallback& callback,
2635 GDataFileError error, 2635 GDataFileError error,
2636 const FilePath& moved_file_path) { 2636 const FilePath& moved_file_path) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 } 2680 }
2681 2681
2682 void GDataFileSystem::RemoveStaleEntryOnUpload( 2682 void GDataFileSystem::RemoveStaleEntryOnUpload(
2683 const std::string& resource_id, 2683 const std::string& resource_id,
2684 DriveDirectory* parent_dir, 2684 DriveDirectory* parent_dir,
2685 const FileMoveCallback& callback, 2685 const FileMoveCallback& callback,
2686 DriveEntry* existing_entry) { 2686 DriveEntry* existing_entry) {
2687 if (existing_entry && 2687 if (existing_entry &&
2688 // This should always match, but just in case. 2688 // This should always match, but just in case.
2689 existing_entry->parent() == parent_dir) { 2689 existing_entry->parent() == parent_dir) {
2690 directory_service_->RemoveEntryFromParent(existing_entry, callback); 2690 resource_metadata_->RemoveEntryFromParent(existing_entry, callback);
2691 } else { 2691 } else {
2692 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); 2692 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; 2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id;
2694 } 2694 }
2695 } 2695 }
2696 2696
2697 void GDataFileSystem::NotifyFileSystemMounted() { 2697 void GDataFileSystem::NotifyFileSystemMounted() {
2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2699 2699
2700 DVLOG(1) << "File System is mounted"; 2700 DVLOG(1) << "File System is mounted";
(...skipping 30 matching lines...) Expand all
2731 2731
2732 if (!entry_value) 2732 if (!entry_value)
2733 return GDATA_FILE_ERROR_FAILED; 2733 return GDATA_FILE_ERROR_FAILED;
2734 2734
2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); 2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value));
2736 2736
2737 if (!doc_entry.get()) 2737 if (!doc_entry.get())
2738 return GDATA_FILE_ERROR_FAILED; 2738 return GDATA_FILE_ERROR_FAILED;
2739 2739
2740 // Find parent directory element within the cached file system snapshot. 2740 // Find parent directory element within the cached file system snapshot.
2741 DriveEntry* entry = directory_service_->FindEntryByPathSync(directory_path); 2741 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(directory_path);
2742 if (!entry) 2742 if (!entry)
2743 return GDATA_FILE_ERROR_FAILED; 2743 return GDATA_FILE_ERROR_FAILED;
2744 2744
2745 // Check if parent is a directory since in theory since this is a callback 2745 // Check if parent is a directory since in theory since this is a callback
2746 // something could in the meantime have nuked the parent dir and created a 2746 // something could in the meantime have nuked the parent dir and created a
2747 // file with the exact same name. 2747 // file with the exact same name.
2748 DriveDirectory* parent_dir = entry->AsDriveDirectory(); 2748 DriveDirectory* parent_dir = entry->AsDriveDirectory();
2749 if (!parent_dir) 2749 if (!parent_dir)
2750 return GDATA_FILE_ERROR_FAILED; 2750 return GDATA_FILE_ERROR_FAILED;
2751 2751
2752 DriveEntry* new_entry = 2752 DriveEntry* new_entry =
2753 directory_service_->FromDocumentEntry(*doc_entry); 2753 resource_metadata_->FromDocumentEntry(*doc_entry);
2754 if (!new_entry) 2754 if (!new_entry)
2755 return GDATA_FILE_ERROR_FAILED; 2755 return GDATA_FILE_ERROR_FAILED;
2756 2756
2757 directory_service_->AddEntryToDirectory( 2757 resource_metadata_->AddEntryToDirectory(
2758 parent_dir, 2758 parent_dir,
2759 new_entry, 2759 new_entry,
2760 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, 2760 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2761 ui_weak_ptr_, 2761 ui_weak_ptr_,
2762 FileMoveCallback())); 2762 FileMoveCallback()));
2763 return GDATA_FILE_OK; 2763 return GDATA_FILE_OK;
2764 } 2764 }
2765 2765
2766 GDataFileSystem::FindMissingDirectoryResult 2766 GDataFileSystem::FindMissingDirectoryResult
2767 GDataFileSystem::FindFirstMissingParentDirectory( 2767 GDataFileSystem::FindFirstMissingParentDirectory(
2768 const FilePath& directory_path, 2768 const FilePath& directory_path,
2769 GURL* last_dir_content_url, 2769 GURL* last_dir_content_url,
2770 FilePath* first_missing_parent_path) { 2770 FilePath* first_missing_parent_path) {
2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2772 2772
2773 // Let's find which how deep is the existing directory structure and 2773 // Let's find which how deep is the existing directory structure and
2774 // get the first element that's missing. 2774 // get the first element that's missing.
2775 std::vector<FilePath::StringType> path_parts; 2775 std::vector<FilePath::StringType> path_parts;
2776 directory_path.GetComponents(&path_parts); 2776 directory_path.GetComponents(&path_parts);
2777 FilePath current_path; 2777 FilePath current_path;
2778 2778
2779 for (std::vector<FilePath::StringType>::const_iterator iter = 2779 for (std::vector<FilePath::StringType>::const_iterator iter =
2780 path_parts.begin(); 2780 path_parts.begin();
2781 iter != path_parts.end(); ++iter) { 2781 iter != path_parts.end(); ++iter) {
2782 current_path = current_path.Append(*iter); 2782 current_path = current_path.Append(*iter);
2783 DriveEntry* entry = directory_service_->FindEntryByPathSync(current_path); 2783 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(current_path);
2784 if (entry) { 2784 if (entry) {
2785 if (entry->file_info().is_directory) { 2785 if (entry->file_info().is_directory) {
2786 *last_dir_content_url = entry->content_url(); 2786 *last_dir_content_url = entry->content_url();
2787 } else { 2787 } else {
2788 // Huh, the segment found is a file not a directory? 2788 // Huh, the segment found is a file not a directory?
2789 return FOUND_INVALID; 2789 return FOUND_INVALID;
2790 } 2790 }
2791 } else { 2791 } else {
2792 *first_missing_parent_path = current_path; 2792 *first_missing_parent_path = current_path;
2793 return FOUND_MISSING; 2793 return FOUND_MISSING;
2794 } 2794 }
2795 } 2795 }
2796 return DIRECTORY_ALREADY_PRESENT; 2796 return DIRECTORY_ALREADY_PRESENT;
2797 } 2797 }
2798 2798
2799 GDataFileError GDataFileSystem::RemoveEntryLocally( 2799 GDataFileError GDataFileSystem::RemoveEntryLocally(
2800 const FilePath& file_path, std::string* resource_id) { 2800 const FilePath& file_path, std::string* resource_id) {
2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2802 2802
2803 resource_id->clear(); 2803 resource_id->clear();
2804 2804
2805 // Find directory element within the cached file system snapshot. 2805 // Find directory element within the cached file system snapshot.
2806 DriveEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2806 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path);
2807 2807
2808 if (!entry) 2808 if (!entry)
2809 return GDATA_FILE_ERROR_NOT_FOUND; 2809 return GDATA_FILE_ERROR_NOT_FOUND;
2810 2810
2811 // You can't remove root element. 2811 // You can't remove root element.
2812 if (!entry->parent()) 2812 if (!entry->parent())
2813 return GDATA_FILE_ERROR_ACCESS_DENIED; 2813 return GDATA_FILE_ERROR_ACCESS_DENIED;
2814 2814
2815 // If it's a file (only files have resource id), get its resource id so that 2815 // If it's a file (only files have resource id), get its resource id so that
2816 // we can remove it after releasing the auto lock. 2816 // we can remove it after releasing the auto lock.
2817 if (entry->AsDriveFile()) 2817 if (entry->AsDriveFile())
2818 *resource_id = entry->AsDriveFile()->resource_id(); 2818 *resource_id = entry->AsDriveFile()->resource_id();
2819 2819
2820 directory_service_->RemoveEntryFromParent( 2820 resource_metadata_->RemoveEntryFromParent(
2821 entry, 2821 entry,
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,
(...skipping 27 matching lines...) Expand all
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;
2866 } 2866 }
2867 2867
2868 DriveEntry* dir_entry = directory_service_->FindEntryByPathSync( 2868 DriveEntry* dir_entry = resource_metadata_->FindEntryByPathSync(
2869 virtual_dir_path); 2869 virtual_dir_path);
2870 if (!dir_entry) 2870 if (!dir_entry)
2871 return; 2871 return;
2872 2872
2873 DriveDirectory* parent_dir = dir_entry->AsDriveDirectory(); 2873 DriveDirectory* parent_dir = dir_entry->AsDriveDirectory();
2874 if (!parent_dir) 2874 if (!parent_dir)
2875 return; 2875 return;
2876 2876
2877 scoped_ptr<DriveEntry> new_entry( 2877 scoped_ptr<DriveEntry> new_entry(
2878 directory_service_->FromDocumentEntry(*entry)); 2878 resource_metadata_->FromDocumentEntry(*entry));
2879 if (!new_entry.get()) 2879 if (!new_entry.get())
2880 return; 2880 return;
2881 2881
2882 const std::string& resource_id = new_entry->resource_id(); 2882 const std::string& resource_id = new_entry->resource_id();
2883 AddUploadedFileParams* params = 2883 AddUploadedFileParams* params =
2884 new AddUploadedFileParams(upload_mode, 2884 new AddUploadedFileParams(upload_mode,
2885 parent_dir, 2885 parent_dir,
2886 new_entry.Pass(), 2886 new_entry.Pass(),
2887 file_content_path, 2887 file_content_path,
2888 cache_operation, 2888 cache_operation,
2889 callback_runner.Release()); 2889 callback_runner.Release());
2890 2890
2891 const FileMoveCallback file_move_callback = 2891 const FileMoveCallback file_move_callback =
2892 base::Bind(&GDataFileSystem::ContinueAddUploadedFile, 2892 base::Bind(&GDataFileSystem::ContinueAddUploadedFile,
2893 ui_weak_ptr_, params); 2893 ui_weak_ptr_, params);
2894 2894
2895 if (upload_mode == UPLOAD_EXISTING_FILE) { 2895 if (upload_mode == UPLOAD_EXISTING_FILE) {
2896 // Remove an existing entry, which should be present. 2896 // Remove an existing entry, which should be present.
2897 directory_service_->GetEntryByResourceIdAsync( 2897 resource_metadata_->GetEntryByResourceIdAsync(
2898 resource_id, 2898 resource_id,
2899 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, 2899 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload,
2900 ui_weak_ptr_, 2900 ui_weak_ptr_,
2901 resource_id, 2901 resource_id,
2902 parent_dir, 2902 parent_dir,
2903 file_move_callback)); 2903 file_move_callback));
2904 } else { 2904 } else {
2905 file_move_callback.Run(GDATA_FILE_OK, FilePath()); 2905 file_move_callback.Run(GDATA_FILE_OK, FilePath());
2906 } 2906 }
2907 } 2907 }
2908 2908
2909 void GDataFileSystem::ContinueAddUploadedFile( 2909 void GDataFileSystem::ContinueAddUploadedFile(
2910 AddUploadedFileParams* params, 2910 AddUploadedFileParams* params,
2911 GDataFileError error, 2911 GDataFileError error,
2912 const FilePath& file_path) { 2912 const FilePath& file_path) {
2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2914 DCHECK_EQ(GDATA_FILE_OK, error); 2914 DCHECK_EQ(GDATA_FILE_OK, error);
2915 DCHECK(params->new_entry.get()); 2915 DCHECK(params->new_entry.get());
2916 DriveFile* file = params->new_entry->AsDriveFile(); 2916 DriveFile* file = params->new_entry->AsDriveFile();
2917 DCHECK(file); 2917 DCHECK(file);
2918 2918
2919 params->resource_id = file->resource_id(); 2919 params->resource_id = file->resource_id();
2920 params->md5 = file->file_md5(); 2920 params->md5 = file->file_md5();
2921 directory_service_->AddEntryToDirectory( 2921 resource_metadata_->AddEntryToDirectory(
2922 params->parent_dir, 2922 params->parent_dir,
2923 params->new_entry.release(), 2923 params->new_entry.release(),
2924 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, 2924 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2925 ui_weak_ptr_, 2925 ui_weak_ptr_,
2926 base::Bind(&GDataFileSystem::AddUploadedFileToCache, 2926 base::Bind(&GDataFileSystem::AddUploadedFileToCache,
2927 ui_weak_ptr_, 2927 ui_weak_ptr_,
2928 base::Owned(params)))); 2928 base::Owned(params))));
2929 } 2929 }
2930 2930
2931 void GDataFileSystem::AddUploadedFileToCache( 2931 void GDataFileSystem::AddUploadedFileToCache(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 2979
2980 void GDataFileSystem::UpdateEntryDataOnUIThread( 2980 void GDataFileSystem::UpdateEntryDataOnUIThread(
2981 const std::string& resource_id, 2981 const std::string& resource_id,
2982 const std::string& md5, 2982 const std::string& md5,
2983 scoped_ptr<DocumentEntry> entry, 2983 scoped_ptr<DocumentEntry> entry,
2984 const FilePath& file_content_path, 2984 const FilePath& file_content_path,
2985 const base::Closure& callback) { 2985 const base::Closure& callback) {
2986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2987 2987
2988 scoped_ptr<DriveFile> new_entry( 2988 scoped_ptr<DriveFile> new_entry(
2989 directory_service_->FromDocumentEntry(*entry)->AsDriveFile()); 2989 resource_metadata_->FromDocumentEntry(*entry)->AsDriveFile());
2990 if (!new_entry.get()) { 2990 if (!new_entry.get()) {
2991 return; 2991 return;
2992 } 2992 }
2993 2993
2994 directory_service_->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 GDataCache::FILE_OPERATION_MOVE,
3001 base::Bind(&OnCacheUpdatedForAddUploadedFile, 3001 base::Bind(&OnCacheUpdatedForAddUploadedFile,
3002 callback)); 3002 callback));
3003 } 3003 }
3004 3004
(...skipping 15 matching lines...) Expand all
3020 } 3020 }
3021 } 3021 }
3022 3022
3023 void GDataFileSystem::SetHideHostedDocuments(bool hide) { 3023 void GDataFileSystem::SetHideHostedDocuments(bool hide) {
3024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3025 3025
3026 if (hide == hide_hosted_docs_) 3026 if (hide == hide_hosted_docs_)
3027 return; 3027 return;
3028 3028
3029 hide_hosted_docs_ = hide; 3029 hide_hosted_docs_ = hide;
3030 const FilePath root_path = directory_service_->root()->GetFilePath(); 3030 const FilePath root_path = resource_metadata_->root()->GetFilePath();
3031 3031
3032 // Kick off directory refresh when this setting changes. 3032 // Kick off directory refresh when this setting changes.
3033 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 3033 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
3034 OnDirectoryChanged(root_path)); 3034 OnDirectoryChanged(root_path));
3035 } 3035 }
3036 3036
3037 //============= GDataFileSystem: internal helper functions ===================== 3037 //============= GDataFileSystem: internal helper functions =====================
3038 3038
3039 void GDataFileSystem::InitializePreferenceObserver() { 3039 void GDataFileSystem::InitializePreferenceObserver() {
3040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 23 matching lines...) Expand all
3064 // Open->Open->modify->Close->modify->Close; the second modify may not be 3064 // Open->Open->modify->Close->modify->Close; the second modify may not be
3065 // synchronized to the server since it is already Closed on the cache). 3065 // synchronized to the server since it is already Closed on the cache).
3066 if (open_files_.find(file_path) != open_files_.end()) { 3066 if (open_files_.find(file_path) != open_files_.end()) {
3067 MessageLoop::current()->PostTask( 3067 MessageLoop::current()->PostTask(
3068 FROM_HERE, 3068 FROM_HERE,
3069 base::Bind(callback, GDATA_FILE_ERROR_IN_USE, FilePath())); 3069 base::Bind(callback, GDATA_FILE_ERROR_IN_USE, FilePath()));
3070 return; 3070 return;
3071 } 3071 }
3072 open_files_.insert(file_path); 3072 open_files_.insert(file_path);
3073 3073
3074 directory_service_->GetEntryInfoByPath( 3074 resource_metadata_->GetEntryInfoByPath(
3075 file_path, 3075 file_path,
3076 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile, 3076 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile,
3077 ui_weak_ptr_, 3077 ui_weak_ptr_,
3078 file_path, 3078 file_path,
3079 base::Bind(&GDataFileSystem::OnOpenFileFinished, 3079 base::Bind(&GDataFileSystem::OnOpenFileFinished,
3080 ui_weak_ptr_, 3080 ui_weak_ptr_,
3081 file_path, 3081 file_path,
3082 callback))); 3082 callback)));
3083 } 3083 }
3084 3084
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 3194
3195 if (open_files_.find(file_path) == open_files_.end()) { 3195 if (open_files_.find(file_path) == open_files_.end()) {
3196 // The file is not being opened. 3196 // The file is not being opened.
3197 MessageLoop::current()->PostTask( 3197 MessageLoop::current()->PostTask(
3198 FROM_HERE, 3198 FROM_HERE,
3199 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); 3199 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND));
3200 return; 3200 return;
3201 } 3201 }
3202 3202
3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. 3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|.
3204 directory_service_->GetEntryInfoByPath( 3204 resource_metadata_->GetEntryInfoByPath(
3205 file_path, 3205 file_path,
3206 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, 3206 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo,
3207 ui_weak_ptr_, 3207 ui_weak_ptr_,
3208 file_path, 3208 file_path,
3209 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize, 3209 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize,
3210 ui_weak_ptr_, 3210 ui_weak_ptr_,
3211 file_path, 3211 file_path,
3212 callback))); 3212 callback)));
3213 } 3213 }
3214 3214
(...skipping 152 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