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

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

Issue 10383248: gdata: Add ability to fetch documents in a particular directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the build 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 | 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 <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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 903
904 // GDataFileSystem::GetDocumentsParams struct implementation. 904 // GDataFileSystem::GetDocumentsParams struct implementation.
905 905
906 GDataFileSystem::GetDocumentsParams::GetDocumentsParams( 906 GDataFileSystem::GetDocumentsParams::GetDocumentsParams(
907 int start_changestamp, 907 int start_changestamp,
908 int root_feed_changestamp, 908 int root_feed_changestamp,
909 std::vector<DocumentFeed*>* feed_list, 909 std::vector<DocumentFeed*>* feed_list,
910 bool should_fetch_multiple_feeds, 910 bool should_fetch_multiple_feeds,
911 const FilePath& search_file_path, 911 const FilePath& search_file_path,
912 const std::string& search_query, 912 const std::string& search_query,
913 const std::string& directory_resource_id,
913 const FindEntryCallback& callback) 914 const FindEntryCallback& callback)
914 : start_changestamp(start_changestamp), 915 : start_changestamp(start_changestamp),
915 root_feed_changestamp(root_feed_changestamp), 916 root_feed_changestamp(root_feed_changestamp),
916 feed_list(feed_list), 917 feed_list(feed_list),
917 should_fetch_multiple_feeds(should_fetch_multiple_feeds), 918 should_fetch_multiple_feeds(should_fetch_multiple_feeds),
918 search_file_path(search_file_path), 919 search_file_path(search_file_path),
919 search_query(search_query), 920 search_query(search_query),
921 directory_resource_id(directory_resource_id),
920 callback(callback) { 922 callback(callback) {
921 } 923 }
922 924
923 GDataFileSystem::GetDocumentsParams::~GetDocumentsParams() { 925 GDataFileSystem::GetDocumentsParams::~GetDocumentsParams() {
924 STLDeleteElements(feed_list.get()); 926 STLDeleteElements(feed_list.get());
925 } 927 }
926 928
927 // GDataFileSystem::CreateDirectoryParams struct implementation. 929 // GDataFileSystem::CreateDirectoryParams struct implementation.
928 930
929 GDataFileSystem::CreateDirectoryParams::CreateDirectoryParams( 931 GDataFileSystem::CreateDirectoryParams::CreateDirectoryParams(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1198 1200
1199 base::PlatformFileError error = GDataToPlatformError(status); 1201 base::PlatformFileError error = GDataToPlatformError(status);
1200 if (error != base::PLATFORM_FILE_OK) { 1202 if (error != base::PLATFORM_FILE_OK) {
1201 // Get changes starting from the next changestamp from what we have locally. 1203 // Get changes starting from the next changestamp from what we have locally.
1202 LoadFeedFromServer(initial_origin, 1204 LoadFeedFromServer(initial_origin,
1203 local_changestamp + 1, 0, 1205 local_changestamp + 1, 0,
1204 true, /* should_fetch_multiple_feeds */ 1206 true, /* should_fetch_multiple_feeds */
1205 search_file_path, 1207 search_file_path,
1206 std::string() /* no search query */, 1208 std::string() /* no search query */,
1209 std::string() /* no directory resource ID */,
1207 callback, 1210 callback,
1208 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1211 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1209 ui_weak_ptr_)); 1212 ui_weak_ptr_));
1210 return; 1213 return;
1211 } 1214 }
1212 1215
1213 scoped_ptr<AccountMetadataFeed> account_metadata; 1216 scoped_ptr<AccountMetadataFeed> account_metadata;
1214 if (feed_data.get()) 1217 if (feed_data.get())
1215 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); 1218 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data);
1216 1219
1217 if (!account_metadata.get()) { 1220 if (!account_metadata.get()) {
1218 LoadFeedFromServer(initial_origin, 1221 LoadFeedFromServer(initial_origin,
1219 local_changestamp + 1, 0, 1222 local_changestamp + 1, 0,
1220 true, /* should_fetch_multiple_feeds */ 1223 true, /* should_fetch_multiple_feeds */
1221 search_file_path, 1224 search_file_path,
1222 std::string() /* no search query */, 1225 std::string() /* no search query */,
1226 std::string() /* no directory resource ID */,
1223 callback, 1227 callback,
1224 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1228 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1225 ui_weak_ptr_)); 1229 ui_weak_ptr_));
1226 return; 1230 return;
1227 } 1231 }
1228 1232
1229 GDataSystemService* service = 1233 GDataSystemService* service =
1230 GDataSystemServiceFactory::GetForProfile(profile_); 1234 GDataSystemServiceFactory::GetForProfile(profile_);
1231 service->webapps_registry()->UpdateFromFeed(account_metadata.get()); 1235 service->webapps_registry()->UpdateFromFeed(account_metadata.get());
1232 1236
(...skipping 24 matching lines...) Expand all
1257 1261
1258 SaveFeed(feed_data.Pass(), FilePath(kAccountMetadataFile)); 1262 SaveFeed(feed_data.Pass(), FilePath(kAccountMetadataFile));
1259 1263
1260 // Load changes from the server. 1264 // Load changes from the server.
1261 LoadFeedFromServer(initial_origin, 1265 LoadFeedFromServer(initial_origin,
1262 local_changestamp > 0 ? local_changestamp + 1 : 0, 1266 local_changestamp > 0 ? local_changestamp + 1 : 0,
1263 account_metadata->largest_changestamp(), 1267 account_metadata->largest_changestamp(),
1264 true, /* should_fetch_multiple_feeds */ 1268 true, /* should_fetch_multiple_feeds */
1265 search_file_path, 1269 search_file_path,
1266 std::string() /* no search query */, 1270 std::string() /* no search query */,
1271 std::string() /* no directory resource ID */,
1267 callback, 1272 callback,
1268 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1273 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1269 ui_weak_ptr_)); 1274 ui_weak_ptr_));
1270 } 1275 }
1271 1276
1272 void GDataFileSystem::LoadFeedFromServer( 1277 void GDataFileSystem::LoadFeedFromServer(
1273 ContentOrigin initial_origin, 1278 ContentOrigin initial_origin,
1274 int start_changestamp, 1279 int start_changestamp,
1275 int root_feed_changestamp, 1280 int root_feed_changestamp,
1276 bool should_fetch_multiple_feeds, 1281 bool should_fetch_multiple_feeds,
1277 const FilePath& search_file_path, 1282 const FilePath& search_file_path,
1278 const std::string& search_query, 1283 const std::string& search_query,
1284 const std::string& directory_resource_id,
1279 const FindEntryCallback& entry_found_callback, 1285 const FindEntryCallback& entry_found_callback,
1280 const LoadDocumentFeedCallback& feed_load_callback) { 1286 const LoadDocumentFeedCallback& feed_load_callback) {
1281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1282 1288
1283 // ...then also kick off document feed fetching from the server as well. 1289 // ...then also kick off document feed fetching from the server as well.
1284 // |feed_list| will contain the list of all collected feed updates that 1290 // |feed_list| will contain the list of all collected feed updates that
1285 // we will receive through calls of DocumentsService::GetDocuments(). 1291 // we will receive through calls of DocumentsService::GetDocuments().
1286 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 1292 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
1287 new std::vector<DocumentFeed*>); 1293 new std::vector<DocumentFeed*>);
1288 // Kick off document feed fetching here if we don't have complete data 1294 // Kick off document feed fetching here if we don't have complete data
1289 // to finish this call. 1295 // to finish this call.
1290 documents_service_->GetDocuments( 1296 documents_service_->GetDocuments(
1291 GURL(), // root feed start. 1297 GURL(), // root feed start.
1292 start_changestamp, 1298 start_changestamp,
1293 search_query, 1299 search_query,
1300 directory_resource_id,
1294 base::Bind(&GDataFileSystem::OnGetDocuments, 1301 base::Bind(&GDataFileSystem::OnGetDocuments,
1295 ui_weak_ptr_, 1302 ui_weak_ptr_,
1296 initial_origin, 1303 initial_origin,
1297 feed_load_callback, 1304 feed_load_callback,
1298 base::Owned(new GetDocumentsParams(start_changestamp, 1305 base::Owned(new GetDocumentsParams(start_changestamp,
1299 root_feed_changestamp, 1306 root_feed_changestamp,
1300 feed_list.release(), 1307 feed_list.release(),
1301 should_fetch_multiple_feeds, 1308 should_fetch_multiple_feeds,
1302 search_file_path, 1309 search_file_path,
1303 search_query, 1310 search_query,
1311 directory_resource_id,
1304 entry_found_callback)))); 1312 entry_found_callback))));
1305 } 1313 }
1306 1314
1307 void GDataFileSystem::OnFeedFromServerLoaded(GetDocumentsParams* params, 1315 void GDataFileSystem::OnFeedFromServerLoaded(GetDocumentsParams* params,
1308 base::PlatformFileError error) { 1316 base::PlatformFileError error) {
1309 if (error != base::PLATFORM_FILE_OK) { 1317 if (error != base::PLATFORM_FILE_OK) {
1310 if (!params->callback.is_null()) { 1318 if (!params->callback.is_null()) {
1311 params->callback.Run(error, FilePath(), 1319 params->callback.Run(error, FilePath(),
1312 reinterpret_cast<GDataEntry*>(NULL)); 1320 reinterpret_cast<GDataEntry*>(NULL));
1313 } 1321 }
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 base::AutoLock lock(lock_); 2997 base::AutoLock lock(lock_);
2990 ContentOrigin initial_origin = root_->origin(); 2998 ContentOrigin initial_origin = root_->origin();
2991 LoadFeedFromServer(initial_origin, 2999 LoadFeedFromServer(initial_origin,
2992 0, 0, // We don't use change stamps when fetching search 3000 0, 0, // We don't use change stamps when fetching search
2993 // data; we always fetch the whole result feed. 3001 // data; we always fetch the whole result feed.
2994 false, // Stop fetching search results after first feed 3002 false, // Stop fetching search results after first feed
2995 // chunk to avoid displaying huge number of search 3003 // chunk to avoid displaying huge number of search
2996 // results (especially since we don't cache them). 3004 // results (especially since we don't cache them).
2997 FilePath(), // Not used. 3005 FilePath(), // Not used.
2998 search_query, 3006 search_query,
3007 std::string(), // No directory resource ID.
2999 FindEntryCallback(), // Not used. 3008 FindEntryCallback(), // Not used.
3000 base::Bind(&GDataFileSystem::OnSearch, 3009 base::Bind(&GDataFileSystem::OnSearch,
3001 ui_weak_ptr_, callback)); 3010 ui_weak_ptr_, callback));
3002 } 3011 }
3003 3012
3004 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin, 3013 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin,
3005 const LoadDocumentFeedCallback& callback, 3014 const LoadDocumentFeedCallback& callback,
3006 GetDocumentsParams* params, 3015 GetDocumentsParams* params,
3007 GDataErrorCode status, 3016 GDataErrorCode status,
3008 scoped_ptr<base::Value> data) { 3017 scoped_ptr<base::Value> data) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3058 NotifyDocumentFeedFetched(num_accumulated_entries); 3067 NotifyDocumentFeedFetched(num_accumulated_entries);
3059 3068
3060 // Check if we need to collect more data to complete the directory list. 3069 // Check if we need to collect more data to complete the directory list.
3061 if (params->should_fetch_multiple_feeds && has_next_feed_url && 3070 if (params->should_fetch_multiple_feeds && has_next_feed_url &&
3062 !next_feed_url.is_empty()) { 3071 !next_feed_url.is_empty()) {
3063 // Kick of the remaining part of the feeds. 3072 // Kick of the remaining part of the feeds.
3064 documents_service_->GetDocuments( 3073 documents_service_->GetDocuments(
3065 next_feed_url, 3074 next_feed_url,
3066 params->start_changestamp, 3075 params->start_changestamp,
3067 params->search_query, 3076 params->search_query,
3077 params->directory_resource_id,
3068 base::Bind(&GDataFileSystem::OnGetDocuments, 3078 base::Bind(&GDataFileSystem::OnGetDocuments,
3069 ui_weak_ptr_, 3079 ui_weak_ptr_,
3070 initial_origin, 3080 initial_origin,
3071 callback, 3081 callback,
3072 base::Owned( 3082 base::Owned(
3073 new GetDocumentsParams( 3083 new GetDocumentsParams(
3074 params->start_changestamp, 3084 params->start_changestamp,
3075 params->root_feed_changestamp, 3085 params->root_feed_changestamp,
3076 params->feed_list.release(), 3086 params->feed_list.release(),
3077 params->should_fetch_multiple_feeds, 3087 params->should_fetch_multiple_feeds,
3078 params->search_file_path, 3088 params->search_file_path,
3079 params->search_query, 3089 params->search_query,
3090 params->directory_resource_id,
3080 params->callback)))); 3091 params->callback))));
3081 return; 3092 return;
3082 } 3093 }
3083 3094
3084 if (!callback.is_null()) 3095 if (!callback.is_null())
3085 callback.Run(params, error); 3096 callback.Run(params, error);
3086 } 3097 }
3087 3098
3088 void GDataFileSystem::LoadRootFeedFromCache( 3099 void GDataFileSystem::LoadRootFeedFromCache(
3089 bool should_load_from_server, 3100 bool should_load_from_server,
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after
5138 pref_registrar_->Init(profile_->GetPrefs()); 5149 pref_registrar_->Init(profile_->GetPrefs());
5139 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 5150 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
5140 } 5151 }
5141 5152
5142 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 5153 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
5143 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 5154 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
5144 global_free_disk_getter_for_testing = getter; 5155 global_free_disk_getter_for_testing = getter;
5145 } 5156 }
5146 5157
5147 } // namespace gdata 5158 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698