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

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