OLD | NEW |
---|---|
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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 const GetEntryInfoWithFilePathCallback& callback, | 551 const GetEntryInfoWithFilePathCallback& callback, |
552 const FilePath& path, | 552 const FilePath& path, |
553 GDataFileError error, | 553 GDataFileError error, |
554 scoped_ptr<GDataEntryProto> entry_proto) { | 554 scoped_ptr<GDataEntryProto> entry_proto) { |
555 if (!callback.is_null()) | 555 if (!callback.is_null()) |
556 callback.Run(error, path, entry_proto.Pass()); | 556 callback.Run(error, path, entry_proto.Pass()); |
557 } | 557 } |
558 | 558 |
559 } // namespace | 559 } // namespace |
560 | 560 |
561 // GDataFileSystem::GetDocumentsParams struct implementation. | 561 GDataWapiFeedLoader::GDataWapiFeedLoader( |
562 struct GDataFileSystem::GetDocumentsParams { | 562 GDataDirectoryService* directory_service, |
563 DocumentsServiceInterface* documents_service, | |
564 DriveWebAppsRegistryInterface* webapps_registry, | |
565 GDataCache* cache, | |
566 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | |
567 : directory_service_(directory_service), | |
568 documents_service_(documents_service), | |
569 webapps_registry_(webapps_registry), | |
570 cache_(cache), | |
571 blocking_task_runner_(blocking_task_runner), | |
572 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
573 } | |
574 | |
575 GDataWapiFeedLoader::~GDataWapiFeedLoader() { | |
576 } | |
577 | |
578 void GDataWapiFeedLoader::AddObserver(Observer* observer) { | |
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
580 observers_.AddObserver(observer); | |
581 } | |
582 | |
583 void GDataWapiFeedLoader::RemoveObserver(Observer* observer) { | |
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
585 observers_.RemoveObserver(observer); | |
586 } | |
587 | |
588 // Defines set of parameters sent to callback OnGetDocuments(). | |
589 // TODO(satorux): Move this to a new file: crbug.com/138268 | |
590 struct GetDocumentsParams { | |
563 GetDocumentsParams(int start_changestamp, | 591 GetDocumentsParams(int start_changestamp, |
564 int root_feed_changestamp, | 592 int root_feed_changestamp, |
565 std::vector<DocumentFeed*>* feed_list, | 593 std::vector<DocumentFeed*>* feed_list, |
566 bool should_fetch_multiple_feeds, | 594 bool should_fetch_multiple_feeds, |
567 const FilePath& search_file_path, | 595 const FilePath& search_file_path, |
568 const std::string& search_query, | 596 const std::string& search_query, |
569 const std::string& directory_resource_id, | 597 const std::string& directory_resource_id, |
570 const FindEntryCallback& callback); | 598 const FindEntryCallback& callback); |
571 ~GetDocumentsParams(); | 599 ~GetDocumentsParams(); |
572 | 600 |
573 // Changestamps are positive numbers in increasing order. The difference | 601 // Changestamps are positive numbers in increasing order. The difference |
574 // between two changestamps is proportional equal to number of items in | 602 // between two changestamps is proportional equal to number of items in |
575 // delta feed between them - bigger the difference, more likely bigger | 603 // delta feed between them - bigger the difference, more likely bigger |
576 // number of items in delta feeds. | 604 // number of items in delta feeds. |
577 int start_changestamp; | 605 int start_changestamp; |
578 int root_feed_changestamp; | 606 int root_feed_changestamp; |
579 scoped_ptr<std::vector<DocumentFeed*> > feed_list; | 607 scoped_ptr<std::vector<DocumentFeed*> > feed_list; |
580 // Should we stop after getting first feed chunk, even if there is more | 608 // Should we stop after getting first feed chunk, even if there is more |
581 // data. | 609 // data. |
582 bool should_fetch_multiple_feeds; | 610 bool should_fetch_multiple_feeds; |
583 FilePath search_file_path; | 611 FilePath search_file_path; |
584 std::string search_query; | 612 std::string search_query; |
585 std::string directory_resource_id; | 613 std::string directory_resource_id; |
586 FindEntryCallback callback; | 614 FindEntryCallback callback; |
587 }; | 615 }; |
588 | 616 |
589 GDataFileSystem::GetDocumentsParams::GetDocumentsParams( | 617 GetDocumentsParams::GetDocumentsParams( |
590 int start_changestamp, | 618 int start_changestamp, |
591 int root_feed_changestamp, | 619 int root_feed_changestamp, |
592 std::vector<DocumentFeed*>* feed_list, | 620 std::vector<DocumentFeed*>* feed_list, |
593 bool should_fetch_multiple_feeds, | 621 bool should_fetch_multiple_feeds, |
594 const FilePath& search_file_path, | 622 const FilePath& search_file_path, |
595 const std::string& search_query, | 623 const std::string& search_query, |
596 const std::string& directory_resource_id, | 624 const std::string& directory_resource_id, |
597 const FindEntryCallback& callback) | 625 const FindEntryCallback& callback) |
598 : start_changestamp(start_changestamp), | 626 : start_changestamp(start_changestamp), |
599 root_feed_changestamp(root_feed_changestamp), | 627 root_feed_changestamp(root_feed_changestamp), |
600 feed_list(feed_list), | 628 feed_list(feed_list), |
601 should_fetch_multiple_feeds(should_fetch_multiple_feeds), | 629 should_fetch_multiple_feeds(should_fetch_multiple_feeds), |
602 search_file_path(search_file_path), | 630 search_file_path(search_file_path), |
603 search_query(search_query), | 631 search_query(search_query), |
604 directory_resource_id(directory_resource_id), | 632 directory_resource_id(directory_resource_id), |
605 callback(callback) { | 633 callback(callback) { |
606 } | 634 } |
607 | 635 |
608 GDataFileSystem::GetDocumentsParams::~GetDocumentsParams() { | 636 GetDocumentsParams::~GetDocumentsParams() { |
609 STLDeleteElements(feed_list.get()); | 637 STLDeleteElements(feed_list.get()); |
610 } | 638 } |
611 | 639 |
612 // GDataFileSystem::CreateDirectoryParams struct implementation. | 640 // GDataFileSystem::CreateDirectoryParams struct implementation. |
613 struct GDataFileSystem::CreateDirectoryParams { | 641 struct GDataFileSystem::CreateDirectoryParams { |
614 CreateDirectoryParams(const FilePath& created_directory_path, | 642 CreateDirectoryParams(const FilePath& created_directory_path, |
615 const FilePath& target_directory_path, | 643 const FilePath& target_directory_path, |
616 bool is_exclusive, | 644 bool is_exclusive, |
617 bool is_recursive, | 645 bool is_recursive, |
618 const FileOperationCallback& callback); | 646 const FileOperationCallback& callback); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 // Should be created from the file browser extension API on UI thread. | 768 // Should be created from the file browser extension API on UI thread. |
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
742 } | 770 } |
743 | 771 |
744 void GDataFileSystem::Initialize() { | 772 void GDataFileSystem::Initialize() { |
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
746 | 774 |
747 documents_service_->Initialize(profile_); | 775 documents_service_->Initialize(profile_); |
748 | 776 |
749 directory_service_.reset(new GDataDirectoryService); | 777 directory_service_.reset(new GDataDirectoryService); |
778 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(), | |
779 documents_service_, | |
780 webapps_registry_, | |
781 cache_, | |
782 blocking_task_runner_)); | |
783 feed_loader_->AddObserver(this); | |
750 | 784 |
751 PrefService* pref_service = profile_->GetPrefs(); | 785 PrefService* pref_service = profile_->GetPrefs(); |
752 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 786 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
753 | 787 |
754 InitializePreferenceObserver(); | 788 InitializePreferenceObserver(); |
755 } | 789 } |
756 | 790 |
757 void GDataFileSystem::CheckForUpdates() { | 791 void GDataFileSystem::CheckForUpdates() { |
758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
759 ContentOrigin initial_origin = directory_service_->origin(); | 793 ContentOrigin initial_origin = directory_service_->origin(); |
760 if (initial_origin == FROM_SERVER) { | 794 if (initial_origin == FROM_SERVER) { |
761 directory_service_->set_origin(REFRESHING); | 795 directory_service_->set_origin(REFRESHING); |
762 ReloadFeedFromServerIfNeeded( | 796 feed_loader_->ReloadFromServerIfNeeded( |
763 initial_origin, | 797 initial_origin, |
764 directory_service_->largest_changestamp(), | 798 directory_service_->largest_changestamp(), |
765 directory_service_->root()->GetFilePath(), | 799 directory_service_->root()->GetFilePath(), |
766 base::Bind(&GDataFileSystem::OnUpdateChecked, | 800 base::Bind(&GDataFileSystem::OnUpdateChecked, |
767 weak_ptr_factory_.GetWeakPtr(), | 801 weak_ptr_factory_.GetWeakPtr(), |
achuithb
2012/08/02 01:38:25
why not ui_weak_ptr_ here?
satorux1
2012/08/02 07:22:51
Changed back to ui_weak_ptr_. I tried to delete ui
| |
768 initial_origin)); | 802 initial_origin)); |
769 } | 803 } |
770 } | 804 } |
771 | 805 |
772 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 806 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
773 GDataFileError error, | 807 GDataFileError error, |
774 GDataEntry* /* entry */) { | 808 GDataEntry* /* entry */) { |
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
776 | 810 |
777 if (error != GDATA_FILE_OK) { | 811 if (error != GDATA_FILE_OK) { |
778 directory_service_->set_origin(initial_origin); | 812 directory_service_->set_origin(initial_origin); |
779 } | 813 } |
780 } | 814 } |
781 | 815 |
782 GDataFileSystem::~GDataFileSystem() { | 816 GDataFileSystem::~GDataFileSystem() { |
783 // This should be called from UI thread, from GDataSystemService shutdown. | 817 // This should be called from UI thread, from GDataSystemService shutdown. |
784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
785 | 819 |
820 feed_loader_->RemoveObserver(this); | |
821 | |
786 // Cancel all the in-flight operations. | 822 // Cancel all the in-flight operations. |
787 // This asynchronously cancels the URL fetch operations. | 823 // This asynchronously cancels the URL fetch operations. |
788 documents_service_->CancelAll(); | 824 documents_service_->CancelAll(); |
789 } | 825 } |
790 | 826 |
791 void GDataFileSystem::AddObserver(Observer* observer) { | 827 void GDataFileSystem::AddObserver( |
828 GDataFileSystemInterface::Observer* observer) { | |
792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
793 observers_.AddObserver(observer); | 830 observers_.AddObserver(observer); |
794 } | 831 } |
795 | 832 |
796 void GDataFileSystem::RemoveObserver(Observer* observer) { | 833 void GDataFileSystem::RemoveObserver( |
834 GDataFileSystemInterface::Observer* observer) { | |
797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
798 observers_.RemoveObserver(observer); | 836 observers_.RemoveObserver(observer); |
799 } | 837 } |
800 | 838 |
801 void GDataFileSystem::StartUpdates() { | 839 void GDataFileSystem::StartUpdates() { |
802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
803 | 841 |
804 DCHECK(!update_timer_.IsRunning()); | 842 DCHECK(!update_timer_.IsRunning()); |
805 update_timer_.Start(FROM_HERE, | 843 update_timer_.Start(FROM_HERE, |
806 base::TimeDelta::FromSeconds( | 844 base::TimeDelta::FromSeconds( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 this, | 907 this, |
870 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 908 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, |
871 weak_ptr_factory_.GetWeakPtr(), | 909 weak_ptr_factory_.GetWeakPtr(), |
872 search_file_path, | 910 search_file_path, |
873 callback))); | 911 callback))); |
874 return; | 912 return; |
875 } else if (directory_service_->origin() == UNINITIALIZED) { | 913 } else if (directory_service_->origin() == UNINITIALIZED) { |
876 // Load root feed from this disk cache. Upon completion, kick off server | 914 // Load root feed from this disk cache. Upon completion, kick off server |
877 // fetching. | 915 // fetching. |
878 directory_service_->set_origin(INITIALIZING); | 916 directory_service_->set_origin(INITIALIZING); |
879 LoadRootFeedFromCache( | 917 feed_loader_->LoadFromCache( |
880 true, // should_load_from_server | 918 true, // should_load_from_server |
881 search_file_path, | 919 search_file_path, |
882 // This is the initial load, hence we'll notify when it's done. | 920 // This is the initial load, hence we'll notify when it's done. |
883 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished, | 921 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished, |
884 weak_ptr_factory_.GetWeakPtr(), | 922 weak_ptr_factory_.GetWeakPtr(), |
885 callback)); | 923 callback)); |
886 return; | 924 return; |
887 } | 925 } |
888 | 926 |
889 // Post a task to the same thread, rather than calling it here, as | 927 // Post a task to the same thread, rather than calling it here, as |
890 // FindEntryByPath() is asynchronous. | 928 // FindEntryByPath() is asynchronous. |
891 base::MessageLoopProxy::current()->PostTask( | 929 base::MessageLoopProxy::current()->PostTask( |
892 FROM_HERE, | 930 FROM_HERE, |
893 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 931 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, |
894 weak_ptr_factory_.GetWeakPtr(), | 932 weak_ptr_factory_.GetWeakPtr(), |
895 search_file_path, | 933 search_file_path, |
896 callback)); | 934 callback)); |
897 } | 935 } |
898 | 936 |
899 void GDataFileSystem::FindEntryByPathSyncOnUIThread( | 937 void GDataFileSystem::FindEntryByPathSyncOnUIThread( |
900 const FilePath& search_file_path, | 938 const FilePath& search_file_path, |
901 const FindEntryCallback& callback) { | 939 const FindEntryCallback& callback) { |
902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
903 | 941 |
904 GDataEntry* entry = directory_service_->FindEntryByPathSync( | 942 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); |
905 search_file_path); | |
906 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry); | |
907 } | 943 } |
908 | 944 |
909 void GDataFileSystem::ReloadFeedFromServerIfNeeded( | 945 void GDataWapiFeedLoader::ReloadFromServerIfNeeded( |
910 ContentOrigin initial_origin, | 946 ContentOrigin initial_origin, |
911 int local_changestamp, | 947 int local_changestamp, |
912 const FilePath& search_file_path, | 948 const FilePath& search_file_path, |
913 const FindEntryCallback& callback) { | 949 const FindEntryCallback& callback) { |
914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
915 | 951 |
916 // First fetch the latest changestamp to see if there were any new changes | 952 // First fetch the latest changestamp to see if there were any new changes |
917 // there at all. | 953 // there at all. |
918 documents_service_->GetAccountMetadata( | 954 documents_service_->GetAccountMetadata( |
919 base::Bind(&GDataFileSystem::OnGetAccountMetadata, | 955 base::Bind(&GDataWapiFeedLoader::OnGetAccountMetadata, |
920 weak_ptr_factory_.GetWeakPtr(), | 956 weak_ptr_factory_.GetWeakPtr(), |
921 initial_origin, | 957 initial_origin, |
922 local_changestamp, | 958 local_changestamp, |
923 search_file_path, | 959 search_file_path, |
924 callback)); | 960 callback)); |
925 } | 961 } |
926 | 962 |
927 void GDataFileSystem::OnGetAccountMetadata( | 963 void GDataWapiFeedLoader::OnGetAccountMetadata( |
928 ContentOrigin initial_origin, | 964 ContentOrigin initial_origin, |
929 int local_changestamp, | 965 int local_changestamp, |
930 const FilePath& search_file_path, | 966 const FilePath& search_file_path, |
931 const FindEntryCallback& callback, | 967 const FindEntryCallback& callback, |
932 GDataErrorCode status, | 968 GDataErrorCode status, |
933 scoped_ptr<base::Value> feed_data) { | 969 scoped_ptr<base::Value> feed_data) { |
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
935 | 971 |
936 GDataFileError error = GDataToGDataFileError(status); | 972 GDataFileError error = GDataToGDataFileError(status); |
937 if (error != GDATA_FILE_OK) { | 973 if (error != GDATA_FILE_OK) { |
938 // Get changes starting from the next changestamp from what we have locally. | 974 // Get changes starting from the next changestamp from what we have locally. |
939 LoadFeedFromServer(initial_origin, | 975 LoadFromServer(initial_origin, |
940 local_changestamp + 1, 0, | 976 local_changestamp + 1, 0, |
achuithb
2012/08/02 01:38:25
nit: indentation
satorux1
2012/08/02 07:22:51
Done.
| |
941 true, /* should_fetch_multiple_feeds */ | 977 true, /* should_fetch_multiple_feeds */ |
942 search_file_path, | 978 search_file_path, |
943 std::string() /* no search query */, | 979 std::string() /* no search query */, |
944 std::string() /* no directory resource ID */, | 980 std::string() /* no directory resource ID */, |
945 callback, | 981 callback, |
946 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, | 982 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
947 weak_ptr_factory_.GetWeakPtr())); | 983 weak_ptr_factory_.GetWeakPtr())); |
948 return; | 984 return; |
949 } | 985 } |
950 | 986 |
951 scoped_ptr<AccountMetadataFeed> account_metadata; | 987 scoped_ptr<AccountMetadataFeed> account_metadata; |
952 if (feed_data.get()) { | 988 if (feed_data.get()) { |
953 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); | 989 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); |
954 #ifndef NDEBUG | 990 #ifndef NDEBUG |
955 // Save account metadata feed for analysis. | 991 // Save account metadata feed for analysis. |
956 const FilePath path = | 992 const FilePath path = |
957 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( | 993 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( |
958 kAccountMetadataFile); | 994 kAccountMetadataFile); |
959 PostBlockingPoolSequencedTask( | 995 PostBlockingPoolSequencedTask( |
960 FROM_HERE, | 996 FROM_HERE, |
961 blocking_task_runner_, | 997 blocking_task_runner_, |
962 base::Bind(&SaveFeedOnBlockingPoolForDebugging, | 998 base::Bind(&SaveFeedOnBlockingPoolForDebugging, |
963 path, base::Passed(&feed_data))); | 999 path, base::Passed(&feed_data))); |
964 #endif | 1000 #endif |
965 } | 1001 } |
966 | 1002 |
967 if (!account_metadata.get()) { | 1003 if (!account_metadata.get()) { |
968 LoadFeedFromServer(initial_origin, | 1004 LoadFromServer(initial_origin, |
969 local_changestamp + 1, 0, | 1005 local_changestamp + 1, 0, |
970 true, /* should_fetch_multiple_feeds */ | 1006 true, /* should_fetch_multiple_feeds */ |
971 search_file_path, | 1007 search_file_path, |
972 std::string() /* no search query */, | 1008 std::string() /* no search query */, |
973 std::string() /* no directory resource ID */, | 1009 std::string() /* no directory resource ID */, |
974 callback, | 1010 callback, |
975 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, | 1011 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
976 weak_ptr_factory_.GetWeakPtr())); | 1012 weak_ptr_factory_.GetWeakPtr())); |
977 return; | 1013 return; |
978 } | 1014 } |
979 | 1015 |
980 webapps_registry_->UpdateFromFeed(account_metadata.get()); | 1016 webapps_registry_->UpdateFromFeed(account_metadata.get()); |
981 | 1017 |
982 bool changes_detected = true; | 1018 bool changes_detected = true; |
983 if (local_changestamp >= account_metadata->largest_changestamp()) { | 1019 if (local_changestamp >= account_metadata->largest_changestamp()) { |
984 if (local_changestamp > account_metadata->largest_changestamp()) { | 1020 if (local_changestamp > account_metadata->largest_changestamp()) { |
985 LOG(WARNING) << "Cached client feed is fresher than server, client = " | 1021 LOG(WARNING) << "Cached client feed is fresher than server, client = " |
986 << local_changestamp | 1022 << local_changestamp |
987 << ", server = " | 1023 << ", server = " |
988 << account_metadata->largest_changestamp(); | 1024 << account_metadata->largest_changestamp(); |
989 } | 1025 } |
990 // If our cache holds the latest state from the server, change the | 1026 // If our cache holds the latest state from the server, change the |
991 // state to FROM_SERVER. | 1027 // state to FROM_SERVER. |
992 directory_service_->set_origin( | 1028 directory_service_->set_origin( |
993 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); | 1029 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); |
994 changes_detected = false; | 1030 changes_detected = false; |
995 } | 1031 } |
996 | 1032 |
997 // No changes detected, continue with search as planned. | 1033 // No changes detected, continue with search as planned. |
998 if (!changes_detected) { | 1034 if (!changes_detected) { |
999 if (!callback.is_null()) | 1035 if (!callback.is_null()) { |
1000 FindEntryByPathSyncOnUIThread(search_file_path, callback); | 1036 directory_service_->FindEntryByPathAndRunSync(search_file_path, |
1037 callback); | |
1038 } | |
1001 return; | 1039 return; |
1002 } | 1040 } |
1003 | 1041 |
1004 // Load changes from the server. | 1042 // Load changes from the server. |
1005 LoadFeedFromServer(initial_origin, | 1043 LoadFromServer(initial_origin, |
1006 local_changestamp > 0 ? local_changestamp + 1 : 0, | 1044 local_changestamp > 0 ? local_changestamp + 1 : 0, |
1007 account_metadata->largest_changestamp(), | 1045 account_metadata->largest_changestamp(), |
1008 true, /* should_fetch_multiple_feeds */ | 1046 true, /* should_fetch_multiple_feeds */ |
1009 search_file_path, | 1047 search_file_path, |
1010 std::string() /* no search query */, | 1048 std::string() /* no search query */, |
1011 std::string() /* no directory resource ID */, | 1049 std::string() /* no directory resource ID */, |
1012 callback, | 1050 callback, |
1013 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, | 1051 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
1014 weak_ptr_factory_.GetWeakPtr())); | 1052 weak_ptr_factory_.GetWeakPtr())); |
1015 } | 1053 } |
1016 | 1054 |
1017 void GDataFileSystem::LoadFeedFromServer( | 1055 void GDataWapiFeedLoader::LoadFromServer( |
1018 ContentOrigin initial_origin, | 1056 ContentOrigin initial_origin, |
1019 int start_changestamp, | 1057 int start_changestamp, |
1020 int root_feed_changestamp, | 1058 int root_feed_changestamp, |
1021 bool should_fetch_multiple_feeds, | 1059 bool should_fetch_multiple_feeds, |
1022 const FilePath& search_file_path, | 1060 const FilePath& search_file_path, |
1023 const std::string& search_query, | 1061 const std::string& search_query, |
1024 const std::string& directory_resource_id, | 1062 const std::string& directory_resource_id, |
1025 const FindEntryCallback& entry_found_callback, | 1063 const FindEntryCallback& entry_found_callback, |
1026 const LoadDocumentFeedCallback& feed_load_callback) { | 1064 const LoadDocumentFeedCallback& feed_load_callback) { |
1027 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1065 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1028 | 1066 |
1029 // |feed_list| will contain the list of all collected feed updates that | 1067 // |feed_list| will contain the list of all collected feed updates that |
1030 // we will receive through calls of DocumentsService::GetDocuments(). | 1068 // we will receive through calls of DocumentsService::GetDocuments(). |
1031 scoped_ptr<std::vector<DocumentFeed*> > feed_list( | 1069 scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
1032 new std::vector<DocumentFeed*>); | 1070 new std::vector<DocumentFeed*>); |
1033 const base::TimeTicks start_time = base::TimeTicks::Now(); | 1071 const base::TimeTicks start_time = base::TimeTicks::Now(); |
1034 documents_service_->GetDocuments( | 1072 documents_service_->GetDocuments( |
1035 GURL(), // root feed start. | 1073 GURL(), // root feed start. |
1036 start_changestamp, | 1074 start_changestamp, |
1037 search_query, | 1075 search_query, |
1038 directory_resource_id, | 1076 directory_resource_id, |
1039 base::Bind(&GDataFileSystem::OnGetDocuments, | 1077 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, |
1040 weak_ptr_factory_.GetWeakPtr(), | 1078 weak_ptr_factory_.GetWeakPtr(), |
1041 initial_origin, | 1079 initial_origin, |
1042 feed_load_callback, | 1080 feed_load_callback, |
1043 base::Owned(new GetDocumentsParams(start_changestamp, | 1081 base::Owned(new GetDocumentsParams(start_changestamp, |
1044 root_feed_changestamp, | 1082 root_feed_changestamp, |
1045 feed_list.release(), | 1083 feed_list.release(), |
1046 should_fetch_multiple_feeds, | 1084 should_fetch_multiple_feeds, |
1047 search_file_path, | 1085 search_file_path, |
1048 search_query, | 1086 search_query, |
1049 directory_resource_id, | 1087 directory_resource_id, |
1050 entry_found_callback)), | 1088 entry_found_callback)), |
1051 start_time)); | 1089 start_time)); |
1052 } | 1090 } |
1053 | 1091 |
1054 void GDataFileSystem::OnFeedFromServerLoaded(GetDocumentsParams* params, | 1092 void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, |
1055 GDataFileError error) { | 1093 GDataFileError error) { |
1056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1094 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1057 | 1095 |
1058 if (error != GDATA_FILE_OK) { | 1096 if (error != GDATA_FILE_OK) { |
1059 if (!params->callback.is_null()) | 1097 if (!params->callback.is_null()) |
1060 params->callback.Run(error, NULL); | 1098 params->callback.Run(error, NULL); |
1061 return; | 1099 return; |
1062 } | 1100 } |
1063 | 1101 |
1064 error = UpdateFromFeed(*params->feed_list, | 1102 error = UpdateFromFeed(*params->feed_list, |
1065 params->start_changestamp, | 1103 params->start_changestamp, |
1066 params->root_feed_changestamp); | 1104 params->root_feed_changestamp); |
1067 | 1105 |
1068 if (error != GDATA_FILE_OK) { | 1106 if (error != GDATA_FILE_OK) { |
1069 if (!params->callback.is_null()) | 1107 if (!params->callback.is_null()) |
1070 params->callback.Run(error, NULL); | 1108 params->callback.Run(error, NULL); |
1071 | 1109 |
1072 return; | 1110 return; |
1073 } | 1111 } |
1074 | 1112 |
1075 // Save file system metadata to disk. | 1113 // Save file system metadata to disk. |
1076 SaveFileSystemAsProto(); | 1114 SaveFileSystemAsProto(); |
1077 | 1115 |
1078 // If we had someone to report this too, then this retrieval was done in a | 1116 // If we had someone to report this too, then this retrieval was done in a |
1079 // context of search... so continue search. | 1117 // context of search... so continue search. |
1080 if (!params->callback.is_null()) | 1118 if (!params->callback.is_null()) { |
1081 FindEntryByPathSyncOnUIThread(params->search_file_path, params->callback); | 1119 directory_service_->FindEntryByPathAndRunSync(params->search_file_path, |
1120 params->callback); | |
1121 } | |
1082 | 1122 |
1083 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); | 1123 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); |
1084 } | 1124 } |
1085 | 1125 |
1086 void GDataFileSystem::TransferFileFromRemoteToLocal( | 1126 void GDataFileSystem::TransferFileFromRemoteToLocal( |
1087 const FilePath& remote_src_file_path, | 1127 const FilePath& remote_src_file_path, |
1088 const FilePath& local_dest_file_path, | 1128 const FilePath& local_dest_file_path, |
1089 const FileOperationCallback& callback) { | 1129 const FileOperationCallback& callback) { |
1090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1091 | 1131 |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2307 GDataFileError error, | 2347 GDataFileError error, |
2308 scoped_ptr<GDataEntryProto> entry_proto) { | 2348 scoped_ptr<GDataEntryProto> entry_proto) { |
2309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2310 | 2350 |
2311 if (error != GDATA_FILE_OK || | 2351 if (error != GDATA_FILE_OK || |
2312 !entry_proto->file_info().is_directory()) { | 2352 !entry_proto->file_info().is_directory()) { |
2313 LOG(ERROR) << "Directory entry not found: " << file_path.value(); | 2353 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
2314 return; | 2354 return; |
2315 } | 2355 } |
2316 | 2356 |
2317 LoadFeedFromServer(directory_service_->origin(), | 2357 feed_loader_->LoadFromServer( |
2318 0, // Not delta feed. | 2358 directory_service_->origin(), |
2319 0, // Not used. | 2359 0, // Not delta feed. |
2320 true, // multiple feeds | 2360 0, // Not used. |
2321 file_path, | 2361 true, // multiple feeds |
2322 std::string(), // No search query | 2362 file_path, |
2323 entry_proto->resource_id(), | 2363 std::string(), // No search query |
2324 FindEntryCallback(), // Not used. | 2364 entry_proto->resource_id(), |
2325 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 2365 FindEntryCallback(), // Not used. |
2326 weak_ptr_factory_.GetWeakPtr())); | 2366 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
2367 ui_weak_ptr_)); | |
2327 } | 2368 } |
2328 | 2369 |
2329 void GDataFileSystem::OnRequestDirectoryRefresh( | 2370 void GDataFileSystem::OnRequestDirectoryRefresh( |
2330 GetDocumentsParams* params, | 2371 GetDocumentsParams* params, |
2331 GDataFileError error) { | 2372 GDataFileError error) { |
2332 DCHECK(params); | 2373 DCHECK(params); |
2333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2334 | 2375 |
2335 const FilePath& directory_path = params->search_file_path; | 2376 const FilePath& directory_path = params->search_file_path; |
2336 if (error != GDATA_FILE_OK) { | 2377 if (error != GDATA_FILE_OK) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2384 scoped_ptr<GDataEntry> entry(it->second); | 2425 scoped_ptr<GDataEntry> entry(it->second); |
2385 // Skip if it's not a file (i.e. directory). | 2426 // Skip if it's not a file (i.e. directory). |
2386 if (!entry->AsGDataFile()) | 2427 if (!entry->AsGDataFile()) |
2387 continue; | 2428 continue; |
2388 directory->AddEntry(entry.release()); | 2429 directory->AddEntry(entry.release()); |
2389 } | 2430 } |
2390 | 2431 |
2391 // Note that there may be no change in the directory, but it's expensive to | 2432 // Note that there may be no change in the directory, but it's expensive to |
2392 // check if the new metadata matches the existing one, so we just always | 2433 // check if the new metadata matches the existing one, so we just always |
2393 // notify that the directory is changed. | 2434 // notify that the directory is changed. |
2394 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(directory_path)); | 2435 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, |
2436 observers_, OnDirectoryChanged(directory_path)); | |
2395 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | 2437 DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
2396 } | 2438 } |
2397 | 2439 |
2398 void GDataFileSystem::UpdateFileByResourceId( | 2440 void GDataFileSystem::UpdateFileByResourceId( |
2399 const std::string& resource_id, | 2441 const std::string& resource_id, |
2400 const FileOperationCallback& callback) { | 2442 const FileOperationCallback& callback) { |
2401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2402 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2444 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2403 RunTaskOnUIThread( | 2445 RunTaskOnUIThread( |
2404 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2446 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2709 } | 2751 } |
2710 | 2752 |
2711 void GDataFileSystem::SearchAsyncOnUIThread( | 2753 void GDataFileSystem::SearchAsyncOnUIThread( |
2712 const std::string& search_query, | 2754 const std::string& search_query, |
2713 const SearchCallback& callback) { | 2755 const SearchCallback& callback) { |
2714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2715 scoped_ptr<std::vector<DocumentFeed*> > feed_list( | 2757 scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
2716 new std::vector<DocumentFeed*>); | 2758 new std::vector<DocumentFeed*>); |
2717 | 2759 |
2718 ContentOrigin initial_origin = directory_service_->origin(); | 2760 ContentOrigin initial_origin = directory_service_->origin(); |
2719 LoadFeedFromServer(initial_origin, | 2761 feed_loader_->LoadFromServer( |
2720 0, 0, // We don't use change stamps when fetching search | 2762 initial_origin, |
2721 // data; we always fetch the whole result feed. | 2763 0, 0, // We don't use change stamps when fetching search |
2722 false, // Stop fetching search results after first feed | 2764 // data; we always fetch the whole result feed. |
2723 // chunk to avoid displaying huge number of search | 2765 false, // Stop fetching search results after first feed |
2724 // results (especially since we don't cache them). | 2766 // chunk to avoid displaying huge number of search |
2725 FilePath(), // Not used. | 2767 // results (especially since we don't cache them). |
2726 search_query, | 2768 FilePath(), // Not used. |
2727 std::string(), // No directory resource ID. | 2769 search_query, |
2728 FindEntryCallback(), // Not used. | 2770 std::string(), // No directory resource ID. |
2729 base::Bind(&GDataFileSystem::OnSearch, | 2771 FindEntryCallback(), // Not used. |
2730 weak_ptr_factory_.GetWeakPtr(), | 2772 base::Bind(&GDataFileSystem::OnSearch, |
2731 callback)); | 2773 ui_weak_ptr_, callback)); |
2732 } | 2774 } |
2733 | 2775 |
2734 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin, | 2776 void GDataWapiFeedLoader::OnGetDocuments( |
2735 const LoadDocumentFeedCallback& callback, | 2777 ContentOrigin initial_origin, |
2736 GetDocumentsParams* params, | 2778 const LoadDocumentFeedCallback& callback, |
2737 base::TimeTicks start_time, | 2779 GetDocumentsParams* params, |
2738 GDataErrorCode status, | 2780 base::TimeTicks start_time, |
2739 scoped_ptr<base::Value> data) { | 2781 GDataErrorCode status, |
2782 scoped_ptr<base::Value> data) { | |
2740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2741 | 2784 |
2742 if (params->feed_list->empty()) { | 2785 if (params->feed_list->empty()) { |
2743 UMA_HISTOGRAM_TIMES("Gdata.InitialFeedLoadTime", | 2786 UMA_HISTOGRAM_TIMES("Gdata.InitialFeedLoadTime", |
2744 base::TimeTicks::Now() - start_time); | 2787 base::TimeTicks::Now() - start_time); |
2745 } | 2788 } |
2746 | 2789 |
2747 GDataFileError error = GDataToGDataFileError(status); | 2790 GDataFileError error = GDataToGDataFileError(status); |
2748 if (error == GDATA_FILE_OK && | 2791 if (error == GDATA_FILE_OK && |
2749 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { | 2792 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2798 | 2841 |
2799 // Check if we need to collect more data to complete the directory list. | 2842 // Check if we need to collect more data to complete the directory list. |
2800 if (params->should_fetch_multiple_feeds && has_next_feed_url && | 2843 if (params->should_fetch_multiple_feeds && has_next_feed_url && |
2801 !next_feed_url.is_empty()) { | 2844 !next_feed_url.is_empty()) { |
2802 // Kick of the remaining part of the feeds. | 2845 // Kick of the remaining part of the feeds. |
2803 documents_service_->GetDocuments( | 2846 documents_service_->GetDocuments( |
2804 next_feed_url, | 2847 next_feed_url, |
2805 params->start_changestamp, | 2848 params->start_changestamp, |
2806 params->search_query, | 2849 params->search_query, |
2807 params->directory_resource_id, | 2850 params->directory_resource_id, |
2808 base::Bind(&GDataFileSystem::OnGetDocuments, | 2851 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, |
2809 weak_ptr_factory_.GetWeakPtr(), | 2852 weak_ptr_factory_.GetWeakPtr(), |
2810 initial_origin, | 2853 initial_origin, |
2811 callback, | 2854 callback, |
2812 base::Owned( | 2855 base::Owned( |
2813 new GetDocumentsParams( | 2856 new GetDocumentsParams( |
2814 params->start_changestamp, | 2857 params->start_changestamp, |
2815 params->root_feed_changestamp, | 2858 params->root_feed_changestamp, |
2816 params->feed_list.release(), | 2859 params->feed_list.release(), |
2817 params->should_fetch_multiple_feeds, | 2860 params->should_fetch_multiple_feeds, |
2818 params->search_file_path, | 2861 params->search_file_path, |
2819 params->search_query, | 2862 params->search_query, |
2820 params->directory_resource_id, | 2863 params->directory_resource_id, |
2821 params->callback)), | 2864 params->callback)), |
2822 start_time)); | 2865 start_time)); |
2823 return; | 2866 return; |
2824 } | 2867 } |
2825 | 2868 |
2826 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", | 2869 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", |
2827 base::TimeTicks::Now() - start_time); | 2870 base::TimeTicks::Now() - start_time); |
2828 | 2871 |
2829 if (!callback.is_null()) | 2872 if (!callback.is_null()) |
2830 callback.Run(params, error); | 2873 callback.Run(params, error); |
2831 } | 2874 } |
2832 | 2875 |
2833 void GDataFileSystem::LoadRootFeedFromCache( | 2876 void GDataWapiFeedLoader::LoadFromCache( |
2834 bool should_load_from_server, | 2877 bool should_load_from_server, |
2835 const FilePath& search_file_path, | 2878 const FilePath& search_file_path, |
2836 const FindEntryCallback& callback) { | 2879 const FindEntryCallback& callback) { |
2837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2838 | 2881 |
2839 const FilePath path = | 2882 const FilePath path = |
2840 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( | 2883 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( |
2841 kFilesystemProtoFile); | 2884 kFilesystemProtoFile); |
2842 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, | 2885 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, |
2843 should_load_from_server, | 2886 should_load_from_server, |
2844 callback); | 2887 callback); |
2845 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 2888 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, |
2846 base::Bind(&LoadProtoOnBlockingPool, path, params), | 2889 base::Bind(&LoadProtoOnBlockingPool, path, params), |
2847 base::Bind(&GDataFileSystem::OnProtoLoaded, | 2890 base::Bind(&GDataWapiFeedLoader::OnProtoLoaded, |
2848 weak_ptr_factory_.GetWeakPtr(), | 2891 weak_ptr_factory_.GetWeakPtr(), |
2849 base::Owned(params))); | 2892 base::Owned(params))); |
2850 } | 2893 } |
2851 | 2894 |
2895 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { | |
2896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2897 | |
2898 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
2899 OnDirectoryChanged(directory_path)); | |
2900 } | |
2901 | |
2902 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { | |
2903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2904 | |
2905 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
2906 OnDocumentFeedFetched(num_accumulated_entries)); | |
2907 } | |
2908 | |
2909 void GDataFileSystem::OnFeedFromServerLoaded() { | |
2910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2911 | |
2912 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
2913 OnFeedFromServerLoaded()); | |
2914 } | |
2915 | |
2852 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2916 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2917 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2854 | 2918 |
2855 LoadRootFeedFromCache( | 2919 feed_loader_->LoadFromCache( |
2856 false, // should_load_from_server. | 2920 false, // should_load_from_server. |
2857 // search_path doesn't matter if FindEntryCallback parameter is null . | 2921 // search_path doesn't matter if FindEntryCallback parameter is null . |
2858 FilePath(), | 2922 FilePath(), |
2859 FindEntryCallback()); | 2923 FindEntryCallback()); |
2860 } | 2924 } |
2861 | 2925 |
2862 void GDataFileSystem::OnProtoLoaded(LoadRootFeedParams* params) { | 2926 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( |
2927 const std::vector<DocumentFeed*>& feed_list, | |
2928 int start_changestamp, | |
2929 int root_feed_changestamp) { | |
2930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2931 | |
2932 return feed_loader_->UpdateFromFeed(feed_list, | |
2933 start_changestamp, | |
2934 root_feed_changestamp); | |
2935 } | |
2936 | |
2937 void GDataWapiFeedLoader::OnProtoLoaded(LoadRootFeedParams* params) { | |
2863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2864 | 2939 |
2865 // If we have already received updates from the server, bail out. | 2940 // If we have already received updates from the server, bail out. |
2866 if (directory_service_->origin() == FROM_SERVER) | 2941 if (directory_service_->origin() == FROM_SERVER) |
2867 return; | 2942 return; |
2868 | 2943 |
2869 int local_changestamp = 0; | 2944 int local_changestamp = 0; |
2870 // Update directory structure only if everything is OK and we haven't yet | 2945 // Update directory structure only if everything is OK and we haven't yet |
2871 // received the feed from the server yet. | 2946 // received the feed from the server yet. |
2872 if (params->load_error == GDATA_FILE_OK) { | 2947 if (params->load_error == GDATA_FILE_OK) { |
2873 DVLOG(1) << "ParseFromString"; | 2948 DVLOG(1) << "ParseFromString"; |
2874 if (directory_service_->ParseFromString(params->proto)) { | 2949 if (directory_service_->ParseFromString(params->proto)) { |
2875 directory_service_->set_last_serialized(params->last_modified); | 2950 directory_service_->set_last_serialized(params->last_modified); |
2876 directory_service_->set_serialized_size(params->proto.size()); | 2951 directory_service_->set_serialized_size(params->proto.size()); |
2877 local_changestamp = directory_service_->largest_changestamp(); | 2952 local_changestamp = directory_service_->largest_changestamp(); |
2878 } else { | 2953 } else { |
2879 params->load_error = GDATA_FILE_ERROR_FAILED; | 2954 params->load_error = GDATA_FILE_ERROR_FAILED; |
2880 LOG(WARNING) << "Parse of cached proto file failed"; | 2955 LOG(WARNING) << "Parse of cached proto file failed"; |
2881 } | 2956 } |
2882 } | 2957 } |
2883 | 2958 |
2884 FindEntryCallback callback = params->callback; | 2959 FindEntryCallback callback = params->callback; |
2885 // If we got feed content from cache, try search over it. | 2960 // If we got feed content from cache, try search over it. |
2886 if (params->load_error == GDATA_FILE_OK && !callback.is_null()) { | 2961 if (params->load_error == GDATA_FILE_OK && !callback.is_null()) { |
2887 // Continue file content search operation if the delegate hasn't terminated | 2962 // Continue file content search operation if the delegate hasn't terminated |
2888 // this search branch already. | 2963 // this search branch already. |
2889 FindEntryByPathSyncOnUIThread(params->search_file_path, callback); | 2964 directory_service_->FindEntryByPathAndRunSync(params->search_file_path, |
2965 callback); | |
2890 callback.Reset(); | 2966 callback.Reset(); |
2891 } | 2967 } |
2892 | 2968 |
2893 if (!params->should_load_from_server) | 2969 if (!params->should_load_from_server) |
2894 return; | 2970 return; |
2895 | 2971 |
2896 // Decide the |initial_origin| to pass to ReloadFeedFromServerIfNeeded(). | 2972 // Decide the |initial_origin| to pass to ReloadFromServerIfNeeded(). |
2897 // This is used to restore directory content origin to its initial value when | 2973 // This is used to restore directory content origin to its initial value when |
2898 // we fail to retrieve the feed from server. | 2974 // we fail to retrieve the feed from server. |
2899 // By default, if directory content is not yet initialized, restore content | 2975 // By default, if directory content is not yet initialized, restore content |
2900 // origin to UNINITIALIZED in case of failure. | 2976 // origin to UNINITIALIZED in case of failure. |
2901 ContentOrigin initial_origin = UNINITIALIZED; | 2977 ContentOrigin initial_origin = UNINITIALIZED; |
2902 if (directory_service_->origin() != INITIALIZING) { | 2978 if (directory_service_->origin() != INITIALIZING) { |
2903 // If directory content is already initialized, restore content origin | 2979 // If directory content is already initialized, restore content origin |
2904 // to FROM_CACHE in case of failure. | 2980 // to FROM_CACHE in case of failure. |
2905 initial_origin = FROM_CACHE; | 2981 initial_origin = FROM_CACHE; |
2906 directory_service_->set_origin(REFRESHING); | 2982 directory_service_->set_origin(REFRESHING); |
2907 } | 2983 } |
2908 | 2984 |
2909 // Kick of the retrieval of the feed from server. If we have previously | 2985 // Kick of the retrieval of the feed from server. If we have previously |
2910 // |reported| to the original callback, then we just need to refresh the | 2986 // |reported| to the original callback, then we just need to refresh the |
2911 // content without continuing search upon operation completion. | 2987 // content without continuing search upon operation completion. |
2912 ReloadFeedFromServerIfNeeded(initial_origin, | 2988 ReloadFromServerIfNeeded(initial_origin, |
2913 local_changestamp, | 2989 local_changestamp, |
2914 params->search_file_path, | 2990 params->search_file_path, |
2915 callback); | 2991 callback); |
2916 } | 2992 } |
2917 | 2993 |
2918 void GDataFileSystem::SaveFileSystemAsProto() { | 2994 void GDataWapiFeedLoader::SaveFileSystemAsProto() { |
2919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2995 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2920 | 2996 |
2921 DVLOG(1) << "SaveFileSystemAsProto"; | 2997 DVLOG(1) << "SaveFileSystemAsProto"; |
2922 | 2998 |
2923 if (!ShouldSerializeFileSystemNow(directory_service_->serialized_size(), | 2999 if (!ShouldSerializeFileSystemNow(directory_service_->serialized_size(), |
2924 directory_service_->last_serialized())) { | 3000 directory_service_->last_serialized())) { |
2925 return; | 3001 return; |
2926 } | 3002 } |
2927 | 3003 |
2928 const FilePath path = | 3004 const FilePath path = |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3185 // through the file name de-duplication. | 3261 // through the file name de-duplication. |
3186 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 3262 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
3187 // changed, but not the file_name. TakeEntry removes the child based on the | 3263 // changed, but not the file_name. TakeEntry removes the child based on the |
3188 // old file_name, and then re-adds the child by first assigning the new title | 3264 // old file_name, and then re-adds the child by first assigning the new title |
3189 // to file_name. http://crbug.com/30157 | 3265 // to file_name. http://crbug.com/30157 |
3190 if (!entry->parent()->TakeEntry(entry)) | 3266 if (!entry->parent()->TakeEntry(entry)) |
3191 return GDATA_FILE_ERROR_FAILED; | 3267 return GDATA_FILE_ERROR_FAILED; |
3192 | 3268 |
3193 *updated_file_path = entry->GetFilePath(); | 3269 *updated_file_path = entry->GetFilePath(); |
3194 | 3270 |
3195 FOR_EACH_OBSERVER(Observer, observers_, | 3271 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3196 OnDirectoryChanged(updated_file_path->DirName())); | 3272 OnDirectoryChanged(updated_file_path->DirName())); |
3197 return GDATA_FILE_OK; | 3273 return GDATA_FILE_OK; |
3198 } | 3274 } |
3199 | 3275 |
3200 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 3276 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( |
3201 GDataEntry* entry, const FilePath& dir_path) { | 3277 GDataEntry* entry, const FilePath& dir_path) { |
3202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3203 DCHECK(entry); | 3279 DCHECK(entry); |
3204 | 3280 |
3205 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); | 3281 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); |
3206 if (!dir_entry) | 3282 if (!dir_entry) |
3207 return GDATA_FILE_ERROR_NOT_FOUND; | 3283 return GDATA_FILE_ERROR_NOT_FOUND; |
3208 | 3284 |
3209 GDataDirectory* dir = dir_entry->AsGDataDirectory(); | 3285 GDataDirectory* dir = dir_entry->AsGDataDirectory(); |
3210 if (!dir) | 3286 if (!dir) |
3211 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 3287 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
3212 | 3288 |
3213 if (!dir->TakeEntry(entry)) | 3289 if (!dir->TakeEntry(entry)) |
3214 return GDATA_FILE_ERROR_FAILED; | 3290 return GDATA_FILE_ERROR_FAILED; |
3215 | 3291 |
3216 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(dir_path)); | 3292 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3293 OnDirectoryChanged(dir_path)); | |
3217 return GDATA_FILE_OK; | 3294 return GDATA_FILE_OK; |
3218 } | 3295 } |
3219 | 3296 |
3220 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( | 3297 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( |
3221 const FilePath& file_path, const FilePath& dir_path, | 3298 const FilePath& file_path, const FilePath& dir_path, |
3222 FilePath* updated_file_path) { | 3299 FilePath* updated_file_path) { |
3223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3224 DCHECK(updated_file_path); | 3301 DCHECK(updated_file_path); |
3225 | 3302 |
3226 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 3303 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
3227 if (!entry) | 3304 if (!entry) |
3228 return GDATA_FILE_ERROR_NOT_FOUND; | 3305 return GDATA_FILE_ERROR_NOT_FOUND; |
3229 | 3306 |
3230 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); | 3307 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); |
3231 if (!dir) | 3308 if (!dir) |
3232 return GDATA_FILE_ERROR_NOT_FOUND; | 3309 return GDATA_FILE_ERROR_NOT_FOUND; |
3233 | 3310 |
3234 if (!dir->AsGDataDirectory()) | 3311 if (!dir->AsGDataDirectory()) |
3235 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 3312 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
3236 | 3313 |
3237 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); | 3314 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); |
3238 | 3315 |
3239 if (!directory_service_->root()->TakeEntry(entry)) | 3316 if (!directory_service_->root()->TakeEntry(entry)) |
3240 return GDATA_FILE_ERROR_FAILED; | 3317 return GDATA_FILE_ERROR_FAILED; |
3241 | 3318 |
3242 *updated_file_path = entry->GetFilePath(); | 3319 *updated_file_path = entry->GetFilePath(); |
3243 | 3320 |
3244 FOR_EACH_OBSERVER(Observer, observers_, | 3321 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3245 OnDirectoryChanged(updated_file_path->DirName())); | 3322 OnDirectoryChanged(updated_file_path->DirName())); |
3246 return GDATA_FILE_OK; | 3323 return GDATA_FILE_OK; |
3247 } | 3324 } |
3248 | 3325 |
3249 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( | 3326 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( |
3250 const FilePath& file_path) { | 3327 const FilePath& file_path) { |
3251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3252 | 3329 |
3253 std::string resource_id; | 3330 std::string resource_id; |
3254 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); | 3331 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); |
3255 if (error != GDATA_FILE_OK) | 3332 if (error != GDATA_FILE_OK) |
3256 return error; | 3333 return error; |
3257 | 3334 |
3258 // If resource_id is not empty, remove its corresponding file from cache. | 3335 // If resource_id is not empty, remove its corresponding file from cache. |
3259 if (!resource_id.empty()) | 3336 if (!resource_id.empty()) |
3260 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 3337 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
3261 | 3338 |
3262 return GDATA_FILE_OK; | 3339 return GDATA_FILE_OK; |
3263 } | 3340 } |
3264 | 3341 |
3265 GDataFileError GDataFileSystem::UpdateFromFeed( | 3342 GDataFileError GDataWapiFeedLoader::UpdateFromFeed( |
3266 const std::vector<DocumentFeed*>& feed_list, | 3343 const std::vector<DocumentFeed*>& feed_list, |
3267 int start_changestamp, | 3344 int start_changestamp, |
3268 int root_feed_changestamp) { | 3345 int root_feed_changestamp) { |
3269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3270 DVLOG(1) << "Updating directory with a feed"; | 3347 DVLOG(1) << "Updating directory with a feed"; |
3271 | 3348 |
3272 std::set<FilePath> changed_dirs; | 3349 std::set<FilePath> changed_dirs; |
3273 | 3350 |
3274 GDataWapiFeedProcessor feed_processor(directory_service_.get()); | 3351 GDataWapiFeedProcessor feed_processor(directory_service_); |
3275 const GDataFileError error = feed_processor.ApplyFeeds( | 3352 const GDataFileError error = feed_processor.ApplyFeeds( |
3276 feed_list, | 3353 feed_list, |
3277 start_changestamp, | 3354 start_changestamp, |
3278 root_feed_changestamp, | 3355 root_feed_changestamp, |
3279 &changed_dirs); | 3356 &changed_dirs); |
3280 | 3357 |
3281 // Don't send directory content change notification while performing | 3358 // Don't send directory content change notification while performing |
3282 // the initial content retrieval. | 3359 // the initial content retrieval. |
3283 const bool should_notify_directory_changed = (start_changestamp != 0); | 3360 const bool should_notify_directory_changed = (start_changestamp != 0); |
3284 if (should_notify_directory_changed) { | 3361 if (should_notify_directory_changed) { |
3285 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); | 3362 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); |
3286 dir_iter != changed_dirs.end(); ++dir_iter) { | 3363 dir_iter != changed_dirs.end(); ++dir_iter) { |
3287 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(*dir_iter)); | 3364 FOR_EACH_OBSERVER(Observer, observers_, |
3365 OnDirectoryChanged(*dir_iter)); | |
3288 } | 3366 } |
3289 } | 3367 } |
3290 | 3368 |
3291 return error; | 3369 return error; |
3292 } | 3370 } |
3293 | 3371 |
3294 | 3372 |
3295 // static | 3373 // static |
3296 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, | 3374 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, |
3297 GDataDirectory* parent_dir, | 3375 GDataDirectory* parent_dir, |
(...skipping 11 matching lines...) Expand all Loading... | |
3309 const FindEntryCallback& callback, | 3387 const FindEntryCallback& callback, |
3310 GDataFileError error, | 3388 GDataFileError error, |
3311 GDataEntry* entry) { | 3389 GDataEntry* entry) { |
3312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3313 | 3391 |
3314 DVLOG(1) << "Initial load finished"; | 3392 DVLOG(1) << "Initial load finished"; |
3315 if (!callback.is_null()) | 3393 if (!callback.is_null()) |
3316 callback.Run(error, entry); | 3394 callback.Run(error, entry); |
3317 | 3395 |
3318 // Notify the observers that root directory has been initialized. | 3396 // Notify the observers that root directory has been initialized. |
3319 FOR_EACH_OBSERVER(Observer, observers_, OnInitialLoadFinished()); | 3397 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3398 OnInitialLoadFinished()); | |
3320 } | 3399 } |
3321 | 3400 |
3322 GDataFileError GDataFileSystem::AddNewDirectory( | 3401 GDataFileError GDataFileSystem::AddNewDirectory( |
3323 const FilePath& directory_path, base::Value* entry_value) { | 3402 const FilePath& directory_path, base::Value* entry_value) { |
3324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3325 | 3404 |
3326 if (!entry_value) | 3405 if (!entry_value) |
3327 return GDATA_FILE_ERROR_FAILED; | 3406 return GDATA_FILE_ERROR_FAILED; |
3328 | 3407 |
3329 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | 3408 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); |
(...skipping 13 matching lines...) Expand all Loading... | |
3343 if (!parent_dir) | 3422 if (!parent_dir) |
3344 return GDATA_FILE_ERROR_FAILED; | 3423 return GDATA_FILE_ERROR_FAILED; |
3345 | 3424 |
3346 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( | 3425 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( |
3347 parent_dir, doc_entry.get(), directory_service_.get()); | 3426 parent_dir, doc_entry.get(), directory_service_.get()); |
3348 if (!new_entry) | 3427 if (!new_entry) |
3349 return GDATA_FILE_ERROR_FAILED; | 3428 return GDATA_FILE_ERROR_FAILED; |
3350 | 3429 |
3351 parent_dir->AddEntry(new_entry); | 3430 parent_dir->AddEntry(new_entry); |
3352 | 3431 |
3353 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(directory_path)); | 3432 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3433 OnDirectoryChanged(directory_path)); | |
3354 return GDATA_FILE_OK; | 3434 return GDATA_FILE_OK; |
3355 } | 3435 } |
3356 | 3436 |
3357 GDataFileSystem::FindMissingDirectoryResult | 3437 GDataFileSystem::FindMissingDirectoryResult |
3358 GDataFileSystem::FindFirstMissingParentDirectory( | 3438 GDataFileSystem::FindFirstMissingParentDirectory( |
3359 const FilePath& directory_path, | 3439 const FilePath& directory_path, |
3360 GURL* last_dir_content_url, | 3440 GURL* last_dir_content_url, |
3361 FilePath* first_missing_parent_path) { | 3441 FilePath* first_missing_parent_path) { |
3362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3363 | 3443 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3405 | 3485 |
3406 // If it's a file (only files have resource id), get its resource id so that | 3486 // If it's a file (only files have resource id), get its resource id so that |
3407 // we can remove it after releasing the auto lock. | 3487 // we can remove it after releasing the auto lock. |
3408 if (entry->AsGDataFile()) | 3488 if (entry->AsGDataFile()) |
3409 *resource_id = entry->AsGDataFile()->resource_id(); | 3489 *resource_id = entry->AsGDataFile()->resource_id(); |
3410 | 3490 |
3411 GDataDirectory* parent_dir = entry->parent(); | 3491 GDataDirectory* parent_dir = entry->parent(); |
3412 if (!parent_dir->RemoveEntry(entry)) | 3492 if (!parent_dir->RemoveEntry(entry)) |
3413 return GDATA_FILE_ERROR_NOT_FOUND; | 3493 return GDATA_FILE_ERROR_NOT_FOUND; |
3414 | 3494 |
3415 FOR_EACH_OBSERVER(Observer, observers_, | 3495 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3416 OnDirectoryChanged(parent_dir->GetFilePath())); | 3496 OnDirectoryChanged(parent_dir->GetFilePath())); |
3417 return GDATA_FILE_OK; | 3497 return GDATA_FILE_OK; |
3418 } | 3498 } |
3419 | 3499 |
3420 void GDataFileSystem::AddUploadedFile( | 3500 void GDataFileSystem::AddUploadedFile( |
3421 UploadMode upload_mode, | 3501 UploadMode upload_mode, |
3422 const FilePath& virtual_dir_path, | 3502 const FilePath& virtual_dir_path, |
3423 scoped_ptr<DocumentEntry> entry, | 3503 scoped_ptr<DocumentEntry> entry, |
3424 const FilePath& file_content_path, | 3504 const FilePath& file_content_path, |
3425 GDataCache::FileOperationType cache_operation, | 3505 GDataCache::FileOperationType cache_operation, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3483 directory_service_->GetEntryByResourceIdAsync(resource_id, | 3563 directory_service_->GetEntryByResourceIdAsync(resource_id, |
3484 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 3564 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); |
3485 } | 3565 } |
3486 | 3566 |
3487 GDataFile* file = new_entry->AsGDataFile(); | 3567 GDataFile* file = new_entry->AsGDataFile(); |
3488 DCHECK(file); | 3568 DCHECK(file); |
3489 const std::string& resource_id = file->resource_id(); | 3569 const std::string& resource_id = file->resource_id(); |
3490 const std::string& md5 = file->file_md5(); | 3570 const std::string& md5 = file->file_md5(); |
3491 parent_dir->AddEntry(new_entry.release()); | 3571 parent_dir->AddEntry(new_entry.release()); |
3492 | 3572 |
3493 FOR_EACH_OBSERVER(Observer, observers_, | 3573 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3494 OnDirectoryChanged(virtual_dir_path)); | 3574 OnDirectoryChanged(virtual_dir_path)); |
3495 | 3575 |
3496 if (upload_mode == UPLOAD_NEW_FILE) { | 3576 if (upload_mode == UPLOAD_NEW_FILE) { |
3497 // Add the file to the cache if we have uploaded a new file. | 3577 // Add the file to the cache if we have uploaded a new file. |
3498 cache_->StoreOnUIThread(resource_id, | 3578 cache_->StoreOnUIThread(resource_id, |
3499 md5, | 3579 md5, |
3500 file_content_path, | 3580 file_content_path, |
3501 cache_operation, | 3581 cache_operation, |
3502 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 3582 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
3503 callback)); | 3583 callback)); |
(...skipping 28 matching lines...) Expand all Loading... | |
3532 void GDataFileSystem::SetHideHostedDocuments(bool hide) { | 3612 void GDataFileSystem::SetHideHostedDocuments(bool hide) { |
3533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3534 | 3614 |
3535 if (hide == hide_hosted_docs_) | 3615 if (hide == hide_hosted_docs_) |
3536 return; | 3616 return; |
3537 | 3617 |
3538 hide_hosted_docs_ = hide; | 3618 hide_hosted_docs_ = hide; |
3539 const FilePath root_path = directory_service_->root()->GetFilePath(); | 3619 const FilePath root_path = directory_service_->root()->GetFilePath(); |
3540 | 3620 |
3541 // Kick off directory refresh when this setting changes. | 3621 // Kick off directory refresh when this setting changes. |
3542 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(root_path)); | 3622 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
3623 OnDirectoryChanged(root_path)); | |
3543 } | 3624 } |
3544 | 3625 |
3545 //============= GDataFileSystem: internal helper functions ===================== | 3626 //============= GDataFileSystem: internal helper functions ===================== |
3546 | 3627 |
3547 void GDataFileSystem::InitializePreferenceObserver() { | 3628 void GDataFileSystem::InitializePreferenceObserver() { |
3548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3549 | 3630 |
3550 pref_registrar_.reset(new PrefChangeRegistrar()); | 3631 pref_registrar_.reset(new PrefChangeRegistrar()); |
3551 pref_registrar_->Init(profile_->GetPrefs()); | 3632 pref_registrar_->Init(profile_->GetPrefs()); |
3552 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 3633 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3975 } | 4056 } |
3976 | 4057 |
3977 PlatformFileInfoProto entry_file_info; | 4058 PlatformFileInfoProto entry_file_info; |
3978 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4059 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3979 *entry_proto->mutable_file_info() = entry_file_info; | 4060 *entry_proto->mutable_file_info() = entry_file_info; |
3980 if (!callback.is_null()) | 4061 if (!callback.is_null()) |
3981 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4062 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3982 } | 4063 } |
3983 | 4064 |
3984 } // namespace gdata | 4065 } // namespace gdata |
OLD | NEW |