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 <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 const base::Closure& task) { | 398 const base::Closure& task) { |
399 if (relay_proxy->BelongsToCurrentThread()) { | 399 if (relay_proxy->BelongsToCurrentThread()) { |
400 task.Run(); | 400 task.Run(); |
401 } else { | 401 } else { |
402 const bool posted = relay_proxy->PostTask(FROM_HERE, task); | 402 const bool posted = relay_proxy->PostTask(FROM_HERE, task); |
403 DCHECK(posted); | 403 DCHECK(posted); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 // Callback for GetEntryByResourceIdAsync. | 407 // Callback for GetEntryByResourceIdAsync. |
408 // Removes stale entry upon upload of file. | |
409 void RemoveStaleEntryOnUpload(const std::string& resource_id, | |
410 GDataDirectory* parent_dir, | |
411 GDataEntry* existing_entry) { | |
412 if (existing_entry && | |
413 // This should always match, but just in case. | |
414 existing_entry->parent() == parent_dir) { | |
415 parent_dir->RemoveEntry(existing_entry); | |
416 } else { | |
417 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | |
418 } | |
419 } | |
420 | |
421 // Callback for GetEntryByResourceIdAsync. | |
422 // Adds |entry| to |results|. Runs |callback| with |results| when | 408 // Adds |entry| to |results|. Runs |callback| with |results| when |
423 // |run_callback| is true. | 409 // |run_callback| is true. |
424 void AddEntryToSearchResults( | 410 void AddEntryToSearchResults( |
425 std::vector<SearchResultInfo>* results, | 411 std::vector<SearchResultInfo>* results, |
426 const SearchCallback& callback, | 412 const SearchCallback& callback, |
427 GDataFileError error, | 413 GDataFileError error, |
428 bool run_callback, | 414 bool run_callback, |
429 GDataEntry* entry) { | 415 GDataEntry* entry) { |
430 // If a result is not present in our local file system snapshot, ignore it. | 416 // If a result is not present in our local file system snapshot, ignore it. |
431 // For example, this may happen if the entry has recently been added to the | 417 // For example, this may happen if the entry has recently been added to the |
(...skipping 3012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3444 DCHECK(file_map->empty()); | 3430 DCHECK(file_map->empty()); |
3445 | 3431 |
3446 if (should_notify_directory_changed) { | 3432 if (should_notify_directory_changed) { |
3447 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); | 3433 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); |
3448 dir_iter != changed_dirs.end(); ++dir_iter) { | 3434 dir_iter != changed_dirs.end(); ++dir_iter) { |
3449 NotifyDirectoryChanged(*dir_iter); | 3435 NotifyDirectoryChanged(*dir_iter); |
3450 } | 3436 } |
3451 } | 3437 } |
3452 } | 3438 } |
3453 | 3439 |
3454 // Helper function for adding new |file| from the feed into |directory|. It | |
3455 // checks the type of file and updates |changed_dirs| if this file adding | |
3456 // operation needs to raise directory notification update. If file is being | |
3457 // added to |orphaned_dir_service| such notifications are not raised since | |
3458 // we ignore such files and don't add them to the file system now. | |
3459 // static | 3440 // static |
3460 void GDataFileSystem::AddEntryToDirectoryAndCollectChangedDirectories( | 3441 void GDataFileSystem::AddEntryToDirectoryAndCollectChangedDirectories( |
3461 GDataEntry* entry, | 3442 GDataEntry* entry, |
3462 GDataDirectory* directory, | 3443 GDataDirectory* directory, |
3463 GDataDirectoryService* orphaned_dir_service, | 3444 GDataDirectoryService* orphaned_dir_service, |
3464 std::set<FilePath>* changed_dirs) { | 3445 std::set<FilePath>* changed_dirs) { |
3465 directory->AddEntry(entry); | 3446 directory->AddEntry(entry); |
3466 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root()) | 3447 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root()) |
3467 changed_dirs->insert(entry->GetFilePath()); | 3448 changed_dirs->insert(entry->GetFilePath()); |
3468 } | 3449 } |
3469 | 3450 |
3470 // Helper function for removing |entry| from |directory|. If |entry| is a | |
3471 // directory too, it will collect all its children file paths into | |
3472 // |changed_dirs| as well. | |
3473 // static | 3451 // static |
3474 void GDataFileSystem::RemoveEntryFromDirectoryAndCollectChangedDirectories( | 3452 void GDataFileSystem::RemoveEntryFromDirectoryAndCollectChangedDirectories( |
3475 GDataDirectory* directory, | 3453 GDataDirectory* directory, |
3476 GDataEntry* entry, | 3454 GDataEntry* entry, |
3477 std::set<FilePath>* changed_dirs) { | 3455 std::set<FilePath>* changed_dirs) { |
3478 // Get the list of all sub-directory paths, so we can notify their listeners | 3456 // Get the list of all sub-directory paths, so we can notify their listeners |
3479 // that they are smoked. | 3457 // that they are smoked. |
3480 GetChildDirectoryPaths(entry, changed_dirs); | 3458 GetChildDirectoryPaths(entry, changed_dirs); |
3481 directory->RemoveEntry(entry); | 3459 directory->RemoveEntry(entry); |
3482 } | 3460 } |
3483 | 3461 |
| 3462 // static |
| 3463 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, |
| 3464 GDataDirectory* parent_dir, |
| 3465 GDataEntry* existing_entry) { |
| 3466 if (existing_entry && |
| 3467 // This should always match, but just in case. |
| 3468 existing_entry->parent() == parent_dir) { |
| 3469 parent_dir->RemoveEntry(existing_entry); |
| 3470 } else { |
| 3471 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
| 3472 } |
| 3473 } |
| 3474 |
3484 GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( | 3475 GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( |
3485 GDataEntry* new_entry, | 3476 GDataEntry* new_entry, |
3486 const FileResourceIdMap& file_map, | 3477 const FileResourceIdMap& file_map, |
3487 GDataDirectoryService* orphaned_dir_service) { | 3478 GDataDirectoryService* orphaned_dir_service) { |
3488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3489 GDataDirectory* dir = NULL; | 3480 GDataDirectory* dir = NULL; |
3490 // Added file. | 3481 // Added file. |
3491 const std::string& parent_id = new_entry->parent_resource_id(); | 3482 const std::string& parent_id = new_entry->parent_resource_id(); |
3492 if (parent_id.empty()) { | 3483 if (parent_id.empty()) { |
3493 dir = directory_service_->root(); | 3484 dir = directory_service_->root(); |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4269 } | 4260 } |
4270 | 4261 |
4271 PlatformFileInfoProto entry_file_info; | 4262 PlatformFileInfoProto entry_file_info; |
4272 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4263 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4273 *entry_proto->mutable_file_info() = entry_file_info; | 4264 *entry_proto->mutable_file_info() = entry_file_info; |
4274 if (!callback.is_null()) | 4265 if (!callback.is_null()) |
4275 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4266 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4276 } | 4267 } |
4277 | 4268 |
4278 } // namespace gdata | 4269 } // namespace gdata |
OLD | NEW |