| 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 <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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 GDataEntry* entry, | 440 GDataEntry* entry, |
| 441 std::set<FilePath>* changed_dirs) { | 441 std::set<FilePath>* changed_dirs) { |
| 442 // Get the list of all sub-directory paths, so we can notify their listeners | 442 // Get the list of all sub-directory paths, so we can notify their listeners |
| 443 // that they are smoked. | 443 // that they are smoked. |
| 444 GetChildDirectoryPaths(entry, changed_dirs); | 444 GetChildDirectoryPaths(entry, changed_dirs); |
| 445 directory->RemoveEntry(entry); | 445 directory->RemoveEntry(entry); |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Helper function for adding new |file| from the feed into |directory|. It | 448 // Helper function for adding new |file| from the feed into |directory|. It |
| 449 // checks the type of file and updates |changed_dirs| if this file adding | 449 // checks the type of file and updates |changed_dirs| if this file adding |
| 450 // opertation needs to raise directory notification update. If file is being | 450 // operation needs to raise directory notification update. If file is being |
| 451 // added to |orphaned_entries_dir| such notifications are not raised since | 451 // added to |orphaned_entries_dir| such notifications are not raised since |
| 452 // we ignore such files and don't add them to the file system now. | 452 // we ignore such files and don't add them to the file system now. |
| 453 void AddEntryToDirectoryAndCollectChangedDirectories( | 453 void AddEntryToDirectoryAndCollectChangedDirectories( |
| 454 GDataEntry* entry, | 454 GDataEntry* entry, |
| 455 GDataDirectory* directory, | 455 GDataDirectory* directory, |
| 456 GDataRootDirectory* orphaned_entries_dir, | 456 GDataRootDirectory* orphaned_entries_dir, |
| 457 std::set<FilePath>* changed_dirs) { | 457 std::set<FilePath>* changed_dirs) { |
| 458 directory->AddEntry(entry); | 458 directory->AddEntry(entry); |
| 459 if (entry->AsGDataDirectory() && directory != orphaned_entries_dir) | 459 if (entry->AsGDataDirectory() && directory != orphaned_entries_dir) |
| 460 changed_dirs->insert(entry->GetFilePath()); | 460 changed_dirs->insert(entry->GetFilePath()); |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 resource_id(resource_id), | 960 resource_id(resource_id), |
| 961 md5(md5), | 961 md5(md5), |
| 962 mime_type(mime_type), | 962 mime_type(mime_type), |
| 963 get_file_callback(get_file_callback), | 963 get_file_callback(get_file_callback), |
| 964 get_download_data_callback(get_download_data_callback) { | 964 get_download_data_callback(get_download_data_callback) { |
| 965 } | 965 } |
| 966 | 966 |
| 967 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() { | 967 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() { |
| 968 } | 968 } |
| 969 | 969 |
| 970 // GDataFileSystem class implementatsion. | 970 // GDataFileSystem class implementation. |
| 971 | 971 |
| 972 GDataFileSystem::GDataFileSystem(Profile* profile, | 972 GDataFileSystem::GDataFileSystem(Profile* profile, |
| 973 DocumentsServiceInterface* documents_service) | 973 DocumentsServiceInterface* documents_service) |
| 974 : profile_(profile), | 974 : profile_(profile), |
| 975 documents_service_(documents_service), | 975 documents_service_(documents_service), |
| 976 on_io_completed_(new base::WaitableEvent( | 976 on_io_completed_(new base::WaitableEvent( |
| 977 true /* manual reset */, true /* initially signaled */)), | 977 true /* manual reset */, true /* initially signaled */)), |
| 978 num_pending_tasks_(0), | 978 num_pending_tasks_(0), |
| 979 update_timer_(true /* retain_user_task */, true /* is_repeating */), | 979 update_timer_(true /* retain_user_task */, true /* is_repeating */), |
| 980 hide_hosted_docs_(false), | 980 hide_hosted_docs_(false), |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 params->directory_resource_id); | 2642 params->directory_resource_id); |
| 2643 if (!directory_entry || !directory_entry->AsGDataDirectory()) { | 2643 if (!directory_entry || !directory_entry->AsGDataDirectory()) { |
| 2644 LOG(ERROR) << "Directory entry is gone: " << directory_path.value() | 2644 LOG(ERROR) << "Directory entry is gone: " << directory_path.value() |
| 2645 << ": " << params->directory_resource_id; | 2645 << ": " << params->directory_resource_id; |
| 2646 return; | 2646 return; |
| 2647 } | 2647 } |
| 2648 GDataDirectory* directory = directory_entry->AsGDataDirectory(); | 2648 GDataDirectory* directory = directory_entry->AsGDataDirectory(); |
| 2649 | 2649 |
| 2650 // Remove the existing files. | 2650 // Remove the existing files. |
| 2651 directory->RemoveChildFiles(); | 2651 directory->RemoveChildFiles(); |
| 2652 // Go through all entires generated by the feed and add files. | 2652 // Go through all entries generated by the feed and add files. |
| 2653 for (FileResourceIdMap::const_iterator it = file_map.begin(); | 2653 for (FileResourceIdMap::const_iterator it = file_map.begin(); |
| 2654 it != file_map.end(); ++it) { | 2654 it != file_map.end(); ++it) { |
| 2655 scoped_ptr<GDataEntry> entry(it->second); | 2655 scoped_ptr<GDataEntry> entry(it->second); |
| 2656 // Skip if it's not a file (i.e. directory). | 2656 // Skip if it's not a file (i.e. directory). |
| 2657 if (!entry->AsGDataFile()) | 2657 if (!entry->AsGDataFile()) |
| 2658 continue; | 2658 continue; |
| 2659 directory->AddEntry(entry.release()); | 2659 directory->AddEntry(entry.release()); |
| 2660 } | 2660 } |
| 2661 | 2661 |
| 2662 // Note that there may be no change in the directory, but it's expensive to | 2662 // Note that there may be no change in the directory, but it's expensive to |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3685 std::set<FilePath> changed_dirs; | 3685 std::set<FilePath> changed_dirs; |
| 3686 | 3686 |
| 3687 if (!is_delta_feed) { // Full update. | 3687 if (!is_delta_feed) { // Full update. |
| 3688 root_->RemoveChildren(); | 3688 root_->RemoveChildren(); |
| 3689 changed_dirs.insert(root_->GetFilePath()); | 3689 changed_dirs.insert(root_->GetFilePath()); |
| 3690 } | 3690 } |
| 3691 root_->set_largest_changestamp(feed_changestamp); | 3691 root_->set_largest_changestamp(feed_changestamp); |
| 3692 | 3692 |
| 3693 scoped_ptr<GDataRootDirectory> orphaned_entries_dir( | 3693 scoped_ptr<GDataRootDirectory> orphaned_entries_dir( |
| 3694 new GDataRootDirectory); | 3694 new GDataRootDirectory); |
| 3695 // Go through all entires generated by the feed and apply them to the local | 3695 // Go through all entries generated by the feed and apply them to the local |
| 3696 // snapshot of the file system. | 3696 // snapshot of the file system. |
| 3697 for (FileResourceIdMap::iterator it = file_map->begin(); | 3697 for (FileResourceIdMap::iterator it = file_map->begin(); |
| 3698 it != file_map->end();) { | 3698 it != file_map->end();) { |
| 3699 // Ensure that the entry is deleted, unless the ownership is explicitly | 3699 // Ensure that the entry is deleted, unless the ownership is explicitly |
| 3700 // transferred by entry.release(). | 3700 // transferred by entry.release(). |
| 3701 scoped_ptr<GDataEntry> entry(it->second); | 3701 scoped_ptr<GDataEntry> entry(it->second); |
| 3702 DCHECK_EQ(it->first, entry->resource_id()); | 3702 DCHECK_EQ(it->first, entry->resource_id()); |
| 3703 // Erase the entry so the deleted entry won't be referenced. | 3703 // Erase the entry so the deleted entry won't be referenced. |
| 3704 file_map->erase(it++); | 3704 file_map->erase(it++); |
| 3705 | 3705 |
| (...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4847 if (!cache_entry.get() || | 4847 if (!cache_entry.get() || |
| 4848 cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { | 4848 cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { |
| 4849 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" | 4849 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" |
| 4850 << resource_id | 4850 << resource_id |
| 4851 << ", md5=" << md5; | 4851 << ", md5=" << md5; |
| 4852 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 4852 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 4853 return; | 4853 return; |
| 4854 } | 4854 } |
| 4855 | 4855 |
| 4856 // If a file is not dirty (it should have been marked dirty via | 4856 // If a file is not dirty (it should have been marked dirty via |
| 4857 // MarkDirtyInCache), commiting it dirty is an invalid operation. | 4857 // MarkDirtyInCache), committing it dirty is an invalid operation. |
| 4858 if (!cache_entry->IsDirty()) { | 4858 if (!cache_entry->IsDirty()) { |
| 4859 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" | 4859 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" |
| 4860 << resource_id | 4860 << resource_id |
| 4861 << ", md5=" << md5; | 4861 << ", md5=" << md5; |
| 4862 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 4862 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 4863 return; | 4863 return; |
| 4864 } | 4864 } |
| 4865 | 4865 |
| 4866 // Dirty files must be in persistent dir. | 4866 // Dirty files must be in persistent dir. |
| 4867 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); | 4867 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5239 pref_registrar_->Init(profile_->GetPrefs()); | 5239 pref_registrar_->Init(profile_->GetPrefs()); |
| 5240 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 5240 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 5241 } | 5241 } |
| 5242 | 5242 |
| 5243 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 5243 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 5244 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 5244 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 5245 global_free_disk_getter_for_testing = getter; | 5245 global_free_disk_getter_for_testing = getter; |
| 5246 } | 5246 } |
| 5247 | 5247 |
| 5248 } // namespace gdata | 5248 } // namespace gdata |
| OLD | NEW |