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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 // This should always match, but just in case. | 441 // This should always match, but just in case. |
442 existing_entry->parent() == parent_dir) { | 442 existing_entry->parent() == parent_dir) { |
443 parent_dir->RemoveEntry(existing_entry); | 443 parent_dir->RemoveEntry(existing_entry); |
444 } else { | 444 } else { |
445 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | 445 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 // Callback for GetEntryByResourceIdAsync. | 449 // Callback for GetEntryByResourceIdAsync. |
450 // Adds |entry| to |results|. Runs |callback| with |results| when | 450 // Adds |entry| to |results|. Runs |callback| with |results| when |
451 // |run_callback| is true. | 451 // |run_callback| is true. When |entry| is not present in our local file system |
| 452 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is |
| 453 // called. |
452 void AddEntryToSearchResults( | 454 void AddEntryToSearchResults( |
453 std::vector<SearchResultInfo>* results, | 455 std::vector<SearchResultInfo>* results, |
454 const SearchCallback& callback, | 456 const SearchCallback& callback, |
| 457 const base::Closure& entry_skipped_callback, |
455 GDataFileError error, | 458 GDataFileError error, |
456 bool run_callback, | 459 bool run_callback, |
457 GDataEntry* entry) { | 460 GDataEntry* entry) { |
458 // If a result is not present in our local file system snapshot, ignore it. | 461 // If a result is not present in our local file system snapshot, invoke |
| 462 // |entry_skipped_callback| and refreshes the snapshot with delta feed. |
459 // For example, this may happen if the entry has recently been added to the | 463 // For example, this may happen if the entry has recently been added to the |
460 // drive (and we still haven't received its delta feed). | 464 // drive (and we still haven't received its delta feed). |
461 if (entry) { | 465 if (entry) { |
462 const bool is_directory = entry->AsGDataDirectory() != NULL; | 466 const bool is_directory = entry->AsGDataDirectory() != NULL; |
463 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); | 467 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); |
| 468 } else { |
| 469 if (!entry_skipped_callback.is_null()) |
| 470 entry_skipped_callback.Run(); |
464 } | 471 } |
465 | 472 |
466 if (run_callback) { | 473 if (run_callback) { |
467 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 474 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
468 if (!callback.is_null()) | 475 if (!callback.is_null()) |
469 callback.Run(error, result_vec.Pass()); | 476 callback.Run(error, result_vec.Pass()); |
470 } | 477 } |
471 } | 478 } |
472 | 479 |
473 // Runs task on UI thread. | 480 // Runs task on UI thread. |
(...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2745 } | 2752 } |
2746 | 2753 |
2747 // We will need information about result entry to create info for callback. | 2754 // We will need information about result entry to create info for callback. |
2748 // We can't use |entry| anymore, so we have to refetch entry from file | 2755 // We can't use |entry| anymore, so we have to refetch entry from file |
2749 // system. Also, |entry| doesn't have file path set before |RefreshFile| | 2756 // system. Also, |entry| doesn't have file path set before |RefreshFile| |
2750 // call, so we can't get file path from there. | 2757 // call, so we can't get file path from there. |
2751 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, | 2758 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, |
2752 base::Bind(&AddEntryToSearchResults, | 2759 base::Bind(&AddEntryToSearchResults, |
2753 results, | 2760 results, |
2754 callback, | 2761 callback, |
| 2762 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), |
2755 error, | 2763 error, |
2756 i+1 == feed->entries().size())); | 2764 i+1 == feed->entries().size())); |
2757 } | 2765 } |
2758 } | 2766 } |
2759 | 2767 |
2760 void GDataFileSystem::Search(const std::string& search_query, | 2768 void GDataFileSystem::Search(const std::string& search_query, |
2761 const SearchCallback& callback) { | 2769 const SearchCallback& callback) { |
2762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2763 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2771 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2764 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, | 2772 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4267 } | 4275 } |
4268 | 4276 |
4269 PlatformFileInfoProto entry_file_info; | 4277 PlatformFileInfoProto entry_file_info; |
4270 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4278 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4271 *entry_proto->mutable_file_info() = entry_file_info; | 4279 *entry_proto->mutable_file_info() = entry_file_info; |
4272 if (!callback.is_null()) | 4280 if (!callback.is_null()) |
4273 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4281 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4274 } | 4282 } |
4275 | 4283 |
4276 } // namespace gdata | 4284 } // namespace gdata |
OLD | NEW |