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

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

Issue 10352004: gdata: Implement periodic file system update checks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add 2 more DCHECKs to make sure we're not starting/stopping timer when it is already started/stoppe… Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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 <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 70 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
71 FILE_PATH_LITERAL("tmp/downloads"); 71 FILE_PATH_LITERAL("tmp/downloads");
72 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = 72 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
73 FILE_PATH_LITERAL("tmp/documents"); 73 FILE_PATH_LITERAL("tmp/documents");
74 const FilePath::CharType kAccountMetadataFile[] = 74 const FilePath::CharType kAccountMetadataFile[] =
75 FILE_PATH_LITERAL("account_metadata.json"); 75 FILE_PATH_LITERAL("account_metadata.json");
76 const FilePath::CharType kFilesystemProtoFile[] = 76 const FilePath::CharType kFilesystemProtoFile[] =
77 FILE_PATH_LITERAL("file_system.pb"); 77 FILE_PATH_LITERAL("file_system.pb");
78 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); 78 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null");
79 79
80 // GData update check interval (in seconds).
81 #ifndef NDEBUG
82 const int kGDataUpdateCheckIntervalInSec = 5;
83 #else
84 const int kGDataUpdateCheckIntervalInSec = 60;
85 #endif
86
80 // Schedule for dumping root file system proto buffers to disk depending its 87 // Schedule for dumping root file system proto buffers to disk depending its
81 // total protobuffer size in MB. 88 // total protobuffer size in MB.
82 typedef struct { 89 typedef struct {
83 double size; 90 double size;
84 int timeout; 91 int timeout;
85 } SerializationTimetable; 92 } SerializationTimetable;
86 93
87 SerializationTimetable kSerializeTimetable[] = { 94 SerializationTimetable kSerializeTimetable[] = {
88 #ifndef NDEBUG 95 #ifndef NDEBUG
89 {0.5, 0}, // Less than 0.5MB, dump immediately. 96 {0.5, 0}, // Less than 0.5MB, dump immediately.
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 // GDataFileSystem class implementatsion. 928 // GDataFileSystem class implementatsion.
922 929
923 GDataFileSystem::GDataFileSystem(Profile* profile, 930 GDataFileSystem::GDataFileSystem(Profile* profile,
924 DocumentsServiceInterface* documents_service) 931 DocumentsServiceInterface* documents_service)
925 : profile_(profile), 932 : profile_(profile),
926 documents_service_(documents_service), 933 documents_service_(documents_service),
927 on_io_completed_(new base::WaitableEvent( 934 on_io_completed_(new base::WaitableEvent(
928 true /* manual reset */, true /* initially signaled */)), 935 true /* manual reset */, true /* initially signaled */)),
929 cache_initialization_started_(false), 936 cache_initialization_started_(false),
930 num_pending_tasks_(0), 937 num_pending_tasks_(0),
938 update_timer_(true /* retain_user_task */, true /* is_repeating */),
931 hide_hosted_docs_(false), 939 hide_hosted_docs_(false),
932 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( 940 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(
933 new base::WeakPtrFactory<GDataFileSystem>(this))), 941 new base::WeakPtrFactory<GDataFileSystem>(this))),
934 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()), 942 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()),
935 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()) { 943 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()) {
936 // Should be created from the file browser extension API on UI thread. 944 // Should be created from the file browser extension API on UI thread.
937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
938 } 946 }
939 947
940 void GDataFileSystem::Initialize() { 948 void GDataFileSystem::Initialize() {
(...skipping 13 matching lines...) Expand all
954 documents_service_->Initialize(profile_); 962 documents_service_->Initialize(profile_);
955 963
956 root_.reset(new GDataRootDirectory); 964 root_.reset(new GDataRootDirectory);
957 965
958 PrefService* pref_service = profile_->GetPrefs(); 966 PrefService* pref_service = profile_->GetPrefs();
959 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 967 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
960 968
961 InitializePreferenceObserver(); 969 InitializePreferenceObserver();
962 } 970 }
963 971
972 void GDataFileSystem::CheckForUpdates() {
973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
974 ContentOrigin initial_origin = root_->origin();
975 if (initial_origin == FROM_SERVER) {
976 root_->set_origin(REFRESHING);
977 ReloadFeedFromServerIfNeeded(initial_origin,
978 root_->largest_changestamp(),
979 root_->GetFilePath(),
980 gdata::FindEntryCallback());
981 }
982 }
983
964 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { 984 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) {
965 if (cache_initialization_started_) 985 if (cache_initialization_started_)
966 return false; 986 return false;
967 cache_paths_.clear(); 987 cache_paths_.clear();
968 SetCachePaths(root_path); 988 SetCachePaths(root_path);
969 return true; 989 return true;
970 } 990 }
971 991
972 GDataFileSystem::~GDataFileSystem() { 992 GDataFileSystem::~GDataFileSystem() {
973 // This should be called from UI thread, from GDataSystemService shutdown. 993 // This should be called from UI thread, from GDataSystemService shutdown.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 } 1029 }
1010 1030
1011 void GDataFileSystem::AddObserver(Observer* observer) { 1031 void GDataFileSystem::AddObserver(Observer* observer) {
1012 observers_.AddObserver(observer); 1032 observers_.AddObserver(observer);
1013 } 1033 }
1014 1034
1015 void GDataFileSystem::RemoveObserver(Observer* observer) { 1035 void GDataFileSystem::RemoveObserver(Observer* observer) {
1016 observers_.RemoveObserver(observer); 1036 observers_.RemoveObserver(observer);
1017 } 1037 }
1018 1038
1039 void GDataFileSystem::StartUpdates() {
1040 DCHECK(!update_timer_.IsRunning());
1041 update_timer_.Start(FROM_HERE,
1042 base::TimeDelta::FromSeconds(
1043 kGDataUpdateCheckIntervalInSec),
1044 base::Bind(&GDataFileSystem::CheckForUpdates,
1045 ui_weak_ptr_));
1046 }
1047
1048 void GDataFileSystem::StopUpdates() {
1049 DCHECK(update_timer_.IsRunning());
hshi 2012/05/03 21:45:01 Ditto.
1050 update_timer_.Stop();
1051 }
1052
1019 void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) { 1053 void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) {
1020 // TokenFetcher, used in DocumentsService, must be run on UI thread. 1054 // TokenFetcher, used in DocumentsService, must be run on UI thread.
1021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1022 1056
1023 documents_service_->Authenticate(callback); 1057 documents_service_->Authenticate(callback);
1024 } 1058 }
1025 1059
1026 void GDataFileSystem::FindEntryByResourceIdSync( 1060 void GDataFileSystem::FindEntryByResourceIdSync(
1027 const std::string& resource_id, 1061 const std::string& resource_id,
1028 FindEntryDelegate* delegate) { 1062 FindEntryDelegate* delegate) {
(...skipping 30 matching lines...) Expand all
1059 callback))); 1093 callback)));
1060 return; 1094 return;
1061 } else if (root_->origin() == UNINITIALIZED) { 1095 } else if (root_->origin() == UNINITIALIZED) {
1062 // Load root feed from this disk cache. Upon completion, kick off server 1096 // Load root feed from this disk cache. Upon completion, kick off server
1063 // fetching. 1097 // fetching.
1064 root_->set_origin(INITIALIZING); 1098 root_->set_origin(INITIALIZING);
1065 LoadRootFeedFromCache(true, // should_load_from_server 1099 LoadRootFeedFromCache(true, // should_load_from_server
1066 search_file_path, 1100 search_file_path,
1067 callback); 1101 callback);
1068 return; 1102 return;
1069 } else if (root_->NeedsRefresh()) {
1070 // If content is stale or from disk from cache, fetch content from
1071 // the server.
1072 ContentOrigin initial_origin = root_->origin();
1073 root_->set_origin(REFRESHING);
1074 ReloadFeedFromServerIfNeeded(initial_origin,
1075 root_->largest_changestamp(),
1076 search_file_path,
1077 callback);
1078 return;
1079 } 1103 }
1080 1104
1081 // Post a task to the same thread, rather than calling it here, as 1105 // Post a task to the same thread, rather than calling it here, as
1082 // FindEntryByPathAsync() is asynchronous. 1106 // FindEntryByPathAsync() is asynchronous.
1083 base::MessageLoopProxy::current()->PostTask( 1107 base::MessageLoopProxy::current()->PostTask(
1084 FROM_HERE, 1108 FROM_HERE,
1085 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 1109 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
1086 ui_weak_ptr_, 1110 ui_weak_ptr_,
1087 search_file_path, 1111 search_file_path,
1088 callback)); 1112 callback));
(...skipping 3682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4771 pref_registrar_->Init(profile_->GetPrefs()); 4795 pref_registrar_->Init(profile_->GetPrefs());
4772 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4796 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4773 } 4797 }
4774 4798
4775 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4799 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4776 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4800 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4777 global_free_disk_getter_for_testing = getter; 4801 global_free_disk_getter_for_testing = getter;
4778 } 4802 }
4779 4803
4780 } // namespace gdata 4804 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698