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

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

Issue 10825120: gdata: Introduce GDataWapiFeedProcessor class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 const GetEntryInfoWithFilePathCallback& callback, 561 const GetEntryInfoWithFilePathCallback& callback,
562 const FilePath& path, 562 const FilePath& path,
563 GDataFileError error, 563 GDataFileError error,
564 scoped_ptr<GDataEntryProto> entry_proto) { 564 scoped_ptr<GDataEntryProto> entry_proto) {
565 if (!callback.is_null()) 565 if (!callback.is_null())
566 callback.Run(error, path, entry_proto.Pass()); 566 callback.Run(error, path, entry_proto.Pass());
567 } 567 }
568 568
569 } // namespace 569 } // namespace
570 570
571 // Struct used to record UMA stats with FeedToFileResourceMap().
572 //
573 // TODO(satorux): Move this to a new file. crbug.com/130669
574 struct FeedToFileResourceMapUmaStats {
575 FeedToFileResourceMapUmaStats()
576 : num_regular_files(0),
577 num_hosted_documents(0) {}
578
579 typedef std::map<DocumentEntry::EntryKind, int> EntryKindToCountMap;
580 int num_regular_files;
581 int num_hosted_documents;
582 EntryKindToCountMap num_files_with_entry_kind;
583 };
584
585 // GDataWapiFeedProcessor is used to process feeds from WAPI (codename for
586 // Documents List API).
587 //
588 // TODO(satorux): Move this into a new file. crbug.com/130669
589 class GDataWapiFeedProcessor {
590 public:
591 explicit GDataWapiFeedProcessor(GDataDirectoryService* directory_service)
592 : directory_service_(directory_service) {
593 }
594
595 // Applies the documents feeds to the file system using |directory_service_|.
596 //
597 // |start_changestamp| determines the type of feed to process. The value is
598 // set to zero for the root feeds, every other value is for the delta feeds.
599 //
600 // In the case of processing the root feeds |root_feed_changestamp| is used
601 // as its initial changestamp value. The value comes from
602 // AccountMetadataFeed.
603 GDataFileError ApplyFeeds(const std::vector<DocumentFeed*>& feed_list,
604 int start_changestamp,
605 int root_feed_changestamp,
606 std::set<FilePath>* changed_dirs);
607
achuithb 2012/08/01 00:00:14 nit: unnecessary newline
satorux1 2012/08/01 00:56:52 Done.
608
609 // Converts list of document feeds from collected feeds into
610 // FileResourceIdMap.
611 GDataFileError FeedToFileResourceMap(
612 const std::vector<DocumentFeed*>& feed_list,
613 FileResourceIdMap* file_map,
614 int* feed_changestamp,
615 FeedToFileResourceMapUmaStats* uma_stats);
616
617 private:
618 // Updates UMA histograms about file counts.
619 void UpdateFileCountUmaHistograms(
620 const FeedToFileResourceMapUmaStats& uma_stats) const;
621
622 // Applies the pre-processed feed from |file_map| map onto the file system.
623 // All entries in |file_map| will be erased (i.e. the map becomes empty),
624 // and values are deleted.
625 void ApplyFeedFromFileUrlMap(bool is_delta_feed,
626 int feed_changestamp,
627 FileResourceIdMap* file_map,
628 std::set<FilePath>* changed_dirs);
629
630 // Helper function for adding new |file| from the feed into |directory|. It
631 // checks the type of file and updates |changed_dirs| if this file adding
632 // operation needs to raise directory notification update. If file is being
633 // added to |orphaned_dir_service| such notifications are not raised since
634 // we ignore such files and don't add them to the file system now.
635 static void AddEntryToDirectoryAndCollectChangedDirectories(
636 GDataEntry* entry,
637 GDataDirectory* directory,
638 GDataDirectoryService* orphaned_dir_service,
639 std::set<FilePath>* changed_dirs);
640
641 // Helper function for removing |entry| from |directory|. If |entry| is a
642 // directory too, it will collect all its children file paths into
643 // |changed_dirs| as well.
644 static void RemoveEntryFromDirectoryAndCollectChangedDirectories(
645 GDataDirectory* directory,
646 GDataEntry* entry,
647 std::set<FilePath>* changed_dirs);
648
649 // Finds directory where new |file| should be added to during feed processing.
650 // |orphaned_entries_dir| collects files/dirs that don't have a parent in
651 // either locally cached file system or in this new feed.
652 GDataDirectory* FindDirectoryForNewEntry(
653 GDataEntry* new_entry,
654 const FileResourceIdMap& file_map,
655 GDataDirectoryService* orphaned_dir_service);
656
657 GDataDirectoryService* directory_service_;
658 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedProcessor);
659 };
660
571 // GDataFileSystem::GetDocumentsParams struct implementation. 661 // GDataFileSystem::GetDocumentsParams struct implementation.
572 struct GDataFileSystem::GetDocumentsParams { 662 struct GDataFileSystem::GetDocumentsParams {
573 GetDocumentsParams(int start_changestamp, 663 GetDocumentsParams(int start_changestamp,
574 int root_feed_changestamp, 664 int root_feed_changestamp,
575 std::vector<DocumentFeed*>* feed_list, 665 std::vector<DocumentFeed*>* feed_list,
576 bool should_fetch_multiple_feeds, 666 bool should_fetch_multiple_feeds,
577 const FilePath& search_file_path, 667 const FilePath& search_file_path,
578 const std::string& search_query, 668 const std::string& search_query,
579 const std::string& directory_resource_id, 669 const std::string& directory_resource_id,
580 const FindEntryCallback& callback); 670 const FindEntryCallback& callback);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 resource_id(resource_id), 798 resource_id(resource_id),
709 md5(md5), 799 md5(md5),
710 mime_type(mime_type), 800 mime_type(mime_type),
711 get_file_callback(get_file_callback), 801 get_file_callback(get_file_callback),
712 get_download_data_callback(get_download_data_callback) { 802 get_download_data_callback(get_download_data_callback) {
713 } 803 }
714 804
715 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() { 805 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() {
716 } 806 }
717 807
718 // GDataFileSystem::FeedToFileResourceMapUmaStats implementation.
719 struct GDataFileSystem::FeedToFileResourceMapUmaStats {
720 FeedToFileResourceMapUmaStats()
721 : num_regular_files(0),
722 num_hosted_documents(0) {}
723
724 typedef std::map<DocumentEntry::EntryKind, int> EntryKindToCountMap;
725 int num_regular_files;
726 int num_hosted_documents;
727 EntryKindToCountMap num_files_with_entry_kind;
728 };
729
730 // GDataFileSystem::StartFileUploadParams implementation. 808 // GDataFileSystem::StartFileUploadParams implementation.
731 struct GDataFileSystem::StartFileUploadParams { 809 struct GDataFileSystem::StartFileUploadParams {
732 StartFileUploadParams(const FilePath& in_local_file_path, 810 StartFileUploadParams(const FilePath& in_local_file_path,
733 const FilePath& in_remote_file_path, 811 const FilePath& in_remote_file_path,
734 const FileOperationCallback& in_callback) 812 const FileOperationCallback& in_callback)
735 : local_file_path(in_local_file_path), 813 : local_file_path(in_local_file_path),
736 remote_file_path(in_remote_file_path), 814 remote_file_path(in_remote_file_path),
737 callback(in_callback) {} 815 callback(in_callback) {}
738 816
739 const FilePath local_file_path; 817 const FilePath local_file_path;
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 const FilePath& directory_path = params->search_file_path; 2433 const FilePath& directory_path = params->search_file_path;
2356 if (error != GDATA_FILE_OK) { 2434 if (error != GDATA_FILE_OK) {
2357 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() 2435 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value()
2358 << ": " << error; 2436 << ": " << error;
2359 return; 2437 return;
2360 } 2438 }
2361 2439
2362 int unused_delta_feed_changestamp = 0; 2440 int unused_delta_feed_changestamp = 0;
2363 FeedToFileResourceMapUmaStats unused_uma_stats; 2441 FeedToFileResourceMapUmaStats unused_uma_stats;
2364 FileResourceIdMap file_map; 2442 FileResourceIdMap file_map;
2365 error = FeedToFileResourceMap(*params->feed_list, 2443 GDataWapiFeedProcessor feed_processor(directory_service_.get());
2366 &file_map, 2444 error = feed_processor.FeedToFileResourceMap(
2367 &unused_delta_feed_changestamp, 2445 *params->feed_list,
2368 &unused_uma_stats); 2446 &file_map,
2447 &unused_delta_feed_changestamp,
2448 &unused_uma_stats);
2369 if (error != GDATA_FILE_OK) { 2449 if (error != GDATA_FILE_OK) {
2370 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() 2450 LOG(ERROR) << "Failed to convert feed: " << directory_path.value()
2371 << ": " << error; 2451 << ": " << error;
2372 return; 2452 return;
2373 } 2453 }
2374 2454
2375 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, 2455 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id,
2376 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, 2456 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry,
2377 ui_weak_ptr_, 2457 ui_weak_ptr_,
2378 directory_path, 2458 directory_path,
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
3272 return GDATA_FILE_OK; 3352 return GDATA_FILE_OK;
3273 } 3353 }
3274 3354
3275 GDataFileError GDataFileSystem::UpdateFromFeed( 3355 GDataFileError GDataFileSystem::UpdateFromFeed(
3276 const std::vector<DocumentFeed*>& feed_list, 3356 const std::vector<DocumentFeed*>& feed_list,
3277 int start_changestamp, 3357 int start_changestamp,
3278 int root_feed_changestamp) { 3358 int root_feed_changestamp) {
3279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3280 DVLOG(1) << "Updating directory with a feed"; 3360 DVLOG(1) << "Updating directory with a feed";
3281 3361
3362 std::set<FilePath> changed_dirs;
3363
3364 GDataWapiFeedProcessor feed_processor(directory_service_.get());
3365 const GDataFileError error = feed_processor.ApplyFeeds(
3366 feed_list,
3367 start_changestamp,
3368 root_feed_changestamp,
3369 &changed_dirs);
3370
3371 // Don't send directory content change notification while performing
3372 // the initial content retrieval.
3373 const bool should_notify_directory_changed = (start_changestamp != 0);
3374 if (should_notify_directory_changed) {
3375 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin();
3376 dir_iter != changed_dirs.end(); ++dir_iter) {
3377 NotifyDirectoryChanged(*dir_iter);
3378 }
3379 }
3380
3381 return error;
3382 }
3383
3384 GDataFileError GDataWapiFeedProcessor::ApplyFeeds(
3385 const std::vector<DocumentFeed*>& feed_list,
3386 int start_changestamp,
3387 int root_feed_changestamp,
3388 std::set<FilePath>* changed_dirs) {
3282 bool is_delta_feed = start_changestamp != 0; 3389 bool is_delta_feed = start_changestamp != 0;
3283 3390
3284 directory_service_->set_origin(FROM_SERVER); 3391 directory_service_->set_origin(FROM_SERVER);
3285 3392
3286 int delta_feed_changestamp = 0; 3393 int delta_feed_changestamp = 0;
3287 FeedToFileResourceMapUmaStats uma_stats; 3394 FeedToFileResourceMapUmaStats uma_stats;
3288 FileResourceIdMap file_map; 3395 FileResourceIdMap file_map;
3289 GDataFileError error = FeedToFileResourceMap(feed_list, 3396 GDataFileError error = FeedToFileResourceMap(feed_list,
3290 &file_map, 3397 &file_map,
3291 &delta_feed_changestamp, 3398 &delta_feed_changestamp,
3292 &uma_stats); 3399 &uma_stats);
3293 if (error != GDATA_FILE_OK) 3400 if (error != GDATA_FILE_OK)
3294 return error; 3401 return error;
3295 3402
3296 ApplyFeedFromFileUrlMap( 3403 ApplyFeedFromFileUrlMap(
3297 is_delta_feed, 3404 is_delta_feed,
3298 is_delta_feed ? delta_feed_changestamp : root_feed_changestamp, 3405 is_delta_feed ? delta_feed_changestamp : root_feed_changestamp,
3299 &file_map); 3406 &file_map,
3407 changed_dirs);
3300 3408
3301 // Shouldn't record histograms when processing delta feeds. 3409 // Shouldn't record histograms when processing delta feeds.
3302 if (!is_delta_feed) 3410 if (!is_delta_feed)
3303 UpdateFileCountUmaHistograms(uma_stats); 3411 UpdateFileCountUmaHistograms(uma_stats);
3304 3412
3305 return GDATA_FILE_OK; 3413 return GDATA_FILE_OK;
3306 } 3414 }
3307 3415
3308 void GDataFileSystem::UpdateFileCountUmaHistograms( 3416 void GDataWapiFeedProcessor::UpdateFileCountUmaHistograms(
3309 const FeedToFileResourceMapUmaStats& uma_stats) const { 3417 const FeedToFileResourceMapUmaStats& uma_stats) const {
3310 const int num_total_files = 3418 const int num_total_files =
3311 uma_stats.num_hosted_documents + uma_stats.num_regular_files; 3419 uma_stats.num_hosted_documents + uma_stats.num_regular_files;
3312 UMA_HISTOGRAM_COUNTS("GData.NumberOfRegularFiles", 3420 UMA_HISTOGRAM_COUNTS("GData.NumberOfRegularFiles",
3313 uma_stats.num_regular_files); 3421 uma_stats.num_regular_files);
3314 UMA_HISTOGRAM_COUNTS("GData.NumberOfHostedDocuments", 3422 UMA_HISTOGRAM_COUNTS("GData.NumberOfHostedDocuments",
3315 uma_stats.num_hosted_documents); 3423 uma_stats.num_hosted_documents);
3316 UMA_HISTOGRAM_COUNTS("GData.NumberOfTotalFiles", num_total_files); 3424 UMA_HISTOGRAM_COUNTS("GData.NumberOfTotalFiles", num_total_files);
3317 const std::vector<int> all_entry_kinds = DocumentEntry::GetAllEntryKinds(); 3425 const std::vector<int> all_entry_kinds = DocumentEntry::GetAllEntryKinds();
3318 for (FeedToFileResourceMapUmaStats::EntryKindToCountMap::const_iterator iter = 3426 for (FeedToFileResourceMapUmaStats::EntryKindToCountMap::const_iterator iter =
3319 uma_stats.num_files_with_entry_kind.begin(); 3427 uma_stats.num_files_with_entry_kind.begin();
3320 iter != uma_stats.num_files_with_entry_kind.end(); 3428 iter != uma_stats.num_files_with_entry_kind.end();
3321 ++iter) { 3429 ++iter) {
3322 const DocumentEntry::EntryKind kind = iter->first; 3430 const DocumentEntry::EntryKind kind = iter->first;
3323 const int count = iter->second; 3431 const int count = iter->second;
3324 for (int i = 0; i < count; ++i) { 3432 for (int i = 0; i < count; ++i) {
3325 UMA_HISTOGRAM_CUSTOM_ENUMERATION( 3433 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
3326 "GData.EntryKind", kind, all_entry_kinds); 3434 "GData.EntryKind", kind, all_entry_kinds);
3327 } 3435 }
3328 } 3436 }
3329 } 3437 }
3330 3438
3331 void GDataFileSystem::ApplyFeedFromFileUrlMap( 3439 void GDataWapiFeedProcessor::ApplyFeedFromFileUrlMap(
3332 bool is_delta_feed, 3440 bool is_delta_feed,
3333 int feed_changestamp, 3441 int feed_changestamp,
3334 FileResourceIdMap* file_map) { 3442 FileResourceIdMap* file_map,
3443 std::set<FilePath>* changed_dirs) {
3335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3336 3445 DCHECK(changed_dirs);
3337 // Don't send directory content change notification while performing
3338 // the initial content retrieval.
3339 const bool should_notify_directory_changed = is_delta_feed;
3340
3341 std::set<FilePath> changed_dirs;
3342 3446
3343 if (!is_delta_feed) { // Full update. 3447 if (!is_delta_feed) { // Full update.
3344 directory_service_->root()->RemoveChildren(); 3448 directory_service_->root()->RemoveChildren();
3345 changed_dirs.insert(directory_service_->root()->GetFilePath()); 3449 changed_dirs->insert(directory_service_->root()->GetFilePath());
3346 } 3450 }
3347 directory_service_->set_largest_changestamp(feed_changestamp); 3451 directory_service_->set_largest_changestamp(feed_changestamp);
3348 3452
3349 scoped_ptr<GDataDirectoryService> orphaned_dir_service( 3453 scoped_ptr<GDataDirectoryService> orphaned_dir_service(
3350 new GDataDirectoryService); 3454 new GDataDirectoryService);
3351 // Go through all entries generated by the feed and apply them to the local 3455 // Go through all entries generated by the feed and apply them to the local
3352 // snapshot of the file system. 3456 // snapshot of the file system.
3353 for (FileResourceIdMap::iterator it = file_map->begin(); 3457 for (FileResourceIdMap::iterator it = file_map->begin();
3354 it != file_map->end();) { 3458 it != file_map->end();) {
3355 // Ensure that the entry is deleted, unless the ownership is explicitly 3459 // Ensure that the entry is deleted, unless the ownership is explicitly
(...skipping 10 matching lines...) Expand all
3366 DVLOG(1) << "Removing file " << entry->base_name(); 3470 DVLOG(1) << "Removing file " << entry->base_name();
3367 if (!old_entry) 3471 if (!old_entry)
3368 continue; 3472 continue;
3369 3473
3370 dest_dir = old_entry->parent(); 3474 dest_dir = old_entry->parent();
3371 if (!dest_dir) { 3475 if (!dest_dir) {
3372 NOTREACHED(); 3476 NOTREACHED();
3373 continue; 3477 continue;
3374 } 3478 }
3375 RemoveEntryFromDirectoryAndCollectChangedDirectories( 3479 RemoveEntryFromDirectoryAndCollectChangedDirectories(
3376 dest_dir, old_entry, &changed_dirs); 3480 dest_dir, old_entry, changed_dirs);
3377 } else if (old_entry) { // Change or move of existing entry. 3481 } else if (old_entry) { // Change or move of existing entry.
3378 // Please note that entry rename is just a special case of change here 3482 // Please note that entry rename is just a special case of change here
3379 // since name is just one of the properties that can change. 3483 // since name is just one of the properties that can change.
3380 DVLOG(1) << "Changed file " << entry->base_name(); 3484 DVLOG(1) << "Changed file " << entry->base_name();
3381 dest_dir = old_entry->parent(); 3485 dest_dir = old_entry->parent();
3382 if (!dest_dir) { 3486 if (!dest_dir) {
3383 NOTREACHED(); 3487 NOTREACHED();
3384 continue; 3488 continue;
3385 } 3489 }
3386 // Move children files over if we are dealing with directories. 3490 // Move children files over if we are dealing with directories.
3387 if (old_entry->AsGDataDirectory() && entry->AsGDataDirectory()) { 3491 if (old_entry->AsGDataDirectory() && entry->AsGDataDirectory()) {
3388 entry->AsGDataDirectory()->TakeOverEntries( 3492 entry->AsGDataDirectory()->TakeOverEntries(
3389 old_entry->AsGDataDirectory()); 3493 old_entry->AsGDataDirectory());
3390 } 3494 }
3391 // Remove the old instance of this entry. 3495 // Remove the old instance of this entry.
3392 RemoveEntryFromDirectoryAndCollectChangedDirectories( 3496 RemoveEntryFromDirectoryAndCollectChangedDirectories(
3393 dest_dir, old_entry, &changed_dirs); 3497 dest_dir, old_entry, changed_dirs);
3394 // Did we actually move the new file to another directory? 3498 // Did we actually move the new file to another directory?
3395 if (dest_dir->resource_id() != entry->parent_resource_id()) { 3499 if (dest_dir->resource_id() != entry->parent_resource_id()) {
3396 changed_dirs.insert(dest_dir->GetFilePath()); 3500 changed_dirs->insert(dest_dir->GetFilePath());
3397 dest_dir = FindDirectoryForNewEntry(entry.get(), 3501 dest_dir = FindDirectoryForNewEntry(entry.get(),
3398 *file_map, 3502 *file_map,
3399 orphaned_dir_service.get()); 3503 orphaned_dir_service.get());
3400 } 3504 }
3401 DCHECK(dest_dir); 3505 DCHECK(dest_dir);
3402 AddEntryToDirectoryAndCollectChangedDirectories( 3506 AddEntryToDirectoryAndCollectChangedDirectories(
3403 entry.release(), 3507 entry.release(),
3404 dest_dir, 3508 dest_dir,
3405 orphaned_dir_service.get(), 3509 orphaned_dir_service.get(),
3406 &changed_dirs); 3510 changed_dirs);
3407 } else { // Adding a new file. 3511 } else { // Adding a new file.
3408 dest_dir = FindDirectoryForNewEntry(entry.get(), 3512 dest_dir = FindDirectoryForNewEntry(entry.get(),
3409 *file_map, 3513 *file_map,
3410 orphaned_dir_service.get()); 3514 orphaned_dir_service.get());
3411 DCHECK(dest_dir); 3515 DCHECK(dest_dir);
3412 AddEntryToDirectoryAndCollectChangedDirectories( 3516 AddEntryToDirectoryAndCollectChangedDirectories(
3413 entry.release(), 3517 entry.release(),
3414 dest_dir, 3518 dest_dir,
3415 orphaned_dir_service.get(), 3519 orphaned_dir_service.get(),
3416 &changed_dirs); 3520 changed_dirs);
3417 } 3521 }
3418 3522
3419 // Record changed directory if this was a delta feed and the parent 3523 // Record changed directory if this was a delta feed and the parent
3420 // directory is already properly rooted within its parent. 3524 // directory is already properly rooted within its parent.
3421 if (dest_dir && (dest_dir->parent() || 3525 if (dest_dir && (dest_dir->parent() ||
3422 dest_dir == directory_service_->root()) && 3526 dest_dir == directory_service_->root()) &&
3423 dest_dir != orphaned_dir_service->root() && is_delta_feed) { 3527 dest_dir != orphaned_dir_service->root() && is_delta_feed) {
3424 changed_dirs.insert(dest_dir->GetFilePath()); 3528 changed_dirs->insert(dest_dir->GetFilePath());
3425 } 3529 }
3426 } 3530 }
3427 // All entry must be erased from the map. 3531 // All entry must be erased from the map.
3428 DCHECK(file_map->empty()); 3532 DCHECK(file_map->empty());
3429
3430 if (should_notify_directory_changed) {
3431 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin();
3432 dir_iter != changed_dirs.end(); ++dir_iter) {
3433 NotifyDirectoryChanged(*dir_iter);
3434 }
3435 }
3436 } 3533 }
3437 3534
3438 // static 3535 // static
3439 void GDataFileSystem::AddEntryToDirectoryAndCollectChangedDirectories( 3536 void GDataWapiFeedProcessor::AddEntryToDirectoryAndCollectChangedDirectories(
3440 GDataEntry* entry, 3537 GDataEntry* entry,
3441 GDataDirectory* directory, 3538 GDataDirectory* directory,
3442 GDataDirectoryService* orphaned_dir_service, 3539 GDataDirectoryService* orphaned_dir_service,
3443 std::set<FilePath>* changed_dirs) { 3540 std::set<FilePath>* changed_dirs) {
3444 directory->AddEntry(entry); 3541 directory->AddEntry(entry);
3445 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root()) 3542 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root())
3446 changed_dirs->insert(entry->GetFilePath()); 3543 changed_dirs->insert(entry->GetFilePath());
3447 } 3544 }
3448 3545
3449 // static 3546 // static
3450 void GDataFileSystem::RemoveEntryFromDirectoryAndCollectChangedDirectories( 3547 void GDataWapiFeedProcessor::
3548 RemoveEntryFromDirectoryAndCollectChangedDirectories(
3451 GDataDirectory* directory, 3549 GDataDirectory* directory,
3452 GDataEntry* entry, 3550 GDataEntry* entry,
3453 std::set<FilePath>* changed_dirs) { 3551 std::set<FilePath>* changed_dirs) {
3454 // Get the list of all sub-directory paths, so we can notify their listeners 3552 // Get the list of all sub-directory paths, so we can notify their listeners
3455 // that they are smoked. 3553 // that they are smoked.
3456 GetChildDirectoryPaths(entry, changed_dirs); 3554 GetChildDirectoryPaths(entry, changed_dirs);
3457 directory->RemoveEntry(entry); 3555 directory->RemoveEntry(entry);
3458 } 3556 }
3459 3557
3460 // static 3558 // static
3461 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, 3559 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id,
3462 GDataDirectory* parent_dir, 3560 GDataDirectory* parent_dir,
3463 GDataEntry* existing_entry) { 3561 GDataEntry* existing_entry) {
3464 if (existing_entry && 3562 if (existing_entry &&
3465 // This should always match, but just in case. 3563 // This should always match, but just in case.
3466 existing_entry->parent() == parent_dir) { 3564 existing_entry->parent() == parent_dir) {
3467 parent_dir->RemoveEntry(existing_entry); 3565 parent_dir->RemoveEntry(existing_entry);
3468 } else { 3566 } else {
3469 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; 3567 LOG(ERROR) << "Entry for the existing file not found: " << resource_id;
3470 } 3568 }
3471 } 3569 }
3472 3570
3473 GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( 3571 GDataDirectory* GDataWapiFeedProcessor::FindDirectoryForNewEntry(
3474 GDataEntry* new_entry, 3572 GDataEntry* new_entry,
3475 const FileResourceIdMap& file_map, 3573 const FileResourceIdMap& file_map,
3476 GDataDirectoryService* orphaned_dir_service) { 3574 GDataDirectoryService* orphaned_dir_service) {
3477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3478 GDataDirectory* dir = NULL; 3576 GDataDirectory* dir = NULL;
3479 // Added file. 3577 // Added file.
3480 const std::string& parent_id = new_entry->parent_resource_id(); 3578 const std::string& parent_id = new_entry->parent_resource_id();
3481 if (parent_id.empty()) { 3579 if (parent_id.empty()) {
3482 dir = directory_service_->root(); 3580 dir = directory_service_->root();
3483 DVLOG(1) << "Root parent for " << new_entry->base_name(); 3581 DVLOG(1) << "Root parent for " << new_entry->base_name();
(...skipping 12 matching lines...) Expand all
3496 << " in file_map " << parent_id; 3594 << " in file_map " << parent_id;
3497 } else { 3595 } else {
3498 DVLOG(1) << "Adding orphan " << new_entry->GetFilePath().value(); 3596 DVLOG(1) << "Adding orphan " << new_entry->GetFilePath().value();
3499 dir = orphaned_dir_service->root(); 3597 dir = orphaned_dir_service->root();
3500 } 3598 }
3501 } 3599 }
3502 } 3600 }
3503 return dir; 3601 return dir;
3504 } 3602 }
3505 3603
3506 GDataFileError GDataFileSystem::FeedToFileResourceMap( 3604 GDataFileError GDataWapiFeedProcessor::FeedToFileResourceMap(
3507 const std::vector<DocumentFeed*>& feed_list, 3605 const std::vector<DocumentFeed*>& feed_list,
3508 FileResourceIdMap* file_map, 3606 FileResourceIdMap* file_map,
3509 int* feed_changestamp, 3607 int* feed_changestamp,
3510 FeedToFileResourceMapUmaStats* uma_stats) { 3608 FeedToFileResourceMapUmaStats* uma_stats) {
3511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3512 DCHECK(uma_stats); 3610 DCHECK(uma_stats);
3513 3611
3514 GDataFileError error = GDATA_FILE_OK; 3612 GDataFileError error = GDATA_FILE_OK;
3515 uma_stats->num_regular_files = 0; 3613 uma_stats->num_regular_files = 0;
3516 uma_stats->num_hosted_documents = 0; 3614 uma_stats->num_hosted_documents = 0;
(...skipping 11 matching lines...) Expand all
3528 root_feed_upload_link->href()); 3626 root_feed_upload_link->href());
3529 *feed_changestamp = feed->largest_changestamp(); 3627 *feed_changestamp = feed->largest_changestamp();
3530 DCHECK_GE(*feed_changestamp, 0); 3628 DCHECK_GE(*feed_changestamp, 0);
3531 } 3629 }
3532 3630
3533 for (ScopedVector<DocumentEntry>::const_iterator iter = 3631 for (ScopedVector<DocumentEntry>::const_iterator iter =
3534 feed->entries().begin(); 3632 feed->entries().begin();
3535 iter != feed->entries().end(); ++iter) { 3633 iter != feed->entries().end(); ++iter) {
3536 DocumentEntry* doc = *iter; 3634 DocumentEntry* doc = *iter;
3537 GDataEntry* entry = GDataEntry::FromDocumentEntry( 3635 GDataEntry* entry = GDataEntry::FromDocumentEntry(
3538 NULL, doc, directory_service_.get()); 3636 NULL, doc, directory_service_);
3539 // Some document entries don't map into files (i.e. sites). 3637 // Some document entries don't map into files (i.e. sites).
3540 if (!entry) 3638 if (!entry)
3541 continue; 3639 continue;
3542 // Count the number of files. 3640 // Count the number of files.
3543 GDataFile* as_file = entry->AsGDataFile(); 3641 GDataFile* as_file = entry->AsGDataFile();
3544 if (as_file) { 3642 if (as_file) {
3545 if (as_file->is_hosted_document()) 3643 if (as_file->is_hosted_document())
3546 ++uma_stats->num_hosted_documents; 3644 ++uma_stats->num_hosted_documents;
3547 else 3645 else
3548 ++uma_stats->num_regular_files; 3646 ++uma_stats->num_regular_files;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
4258 } 4356 }
4259 4357
4260 PlatformFileInfoProto entry_file_info; 4358 PlatformFileInfoProto entry_file_info;
4261 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 4359 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
4262 *entry_proto->mutable_file_info() = entry_file_info; 4360 *entry_proto->mutable_file_info() = entry_file_info;
4263 if (!callback.is_null()) 4361 if (!callback.is_null())
4264 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 4362 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4265 } 4363 }
4266 4364
4267 } // namespace gdata 4365 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698