Chromium Code Reviews| 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. |
|
satorux1
2012/07/30 10:17:18
please document about the new parameters.
kinaba
2012/07/31 08:46:04
Done.
| |
| 452 void AddEntryToSearchResults( | 452 void AddEntryToSearchResults( |
| 453 std::vector<SearchResultInfo>* results, | 453 std::vector<SearchResultInfo>* results, |
| 454 bool* entry_skipped, | |
| 454 const SearchCallback& callback, | 455 const SearchCallback& callback, |
| 456 const base::Closure& entry_skipped_callback, | |
| 455 GDataFileError error, | 457 GDataFileError error, |
| 456 bool run_callback, | 458 bool run_callback, |
| 457 GDataEntry* entry) { | 459 GDataEntry* entry) { |
| 458 // If a result is not present in our local file system snapshot, ignore it. | 460 DCHECK(entry_skipped); |
| 461 | |
| 462 // If a result is not present in our local file system snapshot, invoke | |
| 463 // |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 | 464 // 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). | 465 // drive (and we still haven't received its delta feed). |
| 461 if (entry) { | 466 if (entry) { |
| 462 const bool is_directory = entry->AsGDataDirectory() != NULL; | 467 const bool is_directory = entry->AsGDataDirectory() != NULL; |
| 463 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); | 468 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); |
| 469 } else { | |
| 470 *entry_skipped = true; | |
| 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()); |
| 477 | |
| 478 if (*entry_skipped) { | |
| 479 delete entry_skipped; | |
|
satorux1
2012/07/30 10:17:18
does this mean |entry_skipped| will be leaked, if
tbarzic
2012/07/30 23:32:33
agree, I don't really see the point of using bool*
kinaba
2012/07/31 08:46:04
Done. Removed the boolean variable.
The leak is c
tbarzic
2012/07/31 17:43:25
yeah, I figured the leak was not intentional :)
I
| |
| 480 if (!entry_skipped_callback.is_null()) | |
| 481 entry_skipped_callback.Run(); | |
| 482 } | |
| 470 } | 483 } |
| 471 } | 484 } |
| 472 | 485 |
| 473 // Runs task on UI thread. | 486 // Runs task on UI thread. |
| 474 void RunTaskOnUIThread(const base::Closure& task) { | 487 void RunTaskOnUIThread(const base::Closure& task) { |
| 475 RunTaskOnThread( | 488 RunTaskOnThread( |
| 476 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task); | 489 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task); |
| 477 } | 490 } |
| 478 | 491 |
| 479 // RelayCallback relays arguments for callback running on the given thread. | 492 // RelayCallback relays arguments for callback running on the given thread. |
| (...skipping 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2716 if (error != GDATA_FILE_OK) { | 2729 if (error != GDATA_FILE_OK) { |
| 2717 if (!callback.is_null()) | 2730 if (!callback.is_null()) |
| 2718 callback.Run(error, scoped_ptr<std::vector<SearchResultInfo> >()); | 2731 callback.Run(error, scoped_ptr<std::vector<SearchResultInfo> >()); |
| 2719 return; | 2732 return; |
| 2720 } | 2733 } |
| 2721 | 2734 |
| 2722 // The search results will be returned using virtual directory. | 2735 // The search results will be returned using virtual directory. |
| 2723 // The directory is not really part of the file system, so it has no parent or | 2736 // The directory is not really part of the file system, so it has no parent or |
| 2724 // root. | 2737 // root. |
| 2725 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); | 2738 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); |
| 2739 bool* entry_skipped(new bool(false)); | |
| 2726 | 2740 |
| 2727 DCHECK_EQ(1u, params->feed_list->size()); | 2741 DCHECK_EQ(1u, params->feed_list->size()); |
| 2728 DocumentFeed* feed = params->feed_list->at(0); | 2742 DocumentFeed* feed = params->feed_list->at(0); |
| 2729 | 2743 |
| 2730 if (feed->entries().empty()) { | 2744 if (feed->entries().empty()) { |
| 2731 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 2745 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
| 2732 if (!callback.is_null()) | 2746 if (!callback.is_null()) |
| 2733 callback.Run(error, result_vec.Pass()); | 2747 callback.Run(error, result_vec.Pass()); |
| 2734 return; | 2748 return; |
| 2735 } | 2749 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2757 DCHECK(!entry.get()); | 2771 DCHECK(!entry.get()); |
| 2758 } | 2772 } |
| 2759 | 2773 |
| 2760 // We will need information about result entry to create info for callback. | 2774 // We will need information about result entry to create info for callback. |
| 2761 // We can't use |entry| anymore, so we have to refetch entry from file | 2775 // We can't use |entry| anymore, so we have to refetch entry from file |
| 2762 // system. Also, |entry| doesn't have file path set before |RefreshFile| | 2776 // system. Also, |entry| doesn't have file path set before |RefreshFile| |
| 2763 // call, so we can't get file path from there. | 2777 // call, so we can't get file path from there. |
| 2764 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, | 2778 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, |
| 2765 base::Bind(&AddEntryToSearchResults, | 2779 base::Bind(&AddEntryToSearchResults, |
| 2766 results, | 2780 results, |
| 2781 entry_skipped, | |
| 2767 callback, | 2782 callback, |
| 2783 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), | |
| 2768 error, | 2784 error, |
| 2769 i+1 == feed->entries().size())); | 2785 i+1 == feed->entries().size())); |
| 2770 } | 2786 } |
| 2771 } | 2787 } |
| 2772 | 2788 |
| 2773 void GDataFileSystem::Search(const std::string& search_query, | 2789 void GDataFileSystem::Search(const std::string& search_query, |
| 2774 const SearchCallback& callback) { | 2790 const SearchCallback& callback) { |
| 2775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2791 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2776 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2792 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2777 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, | 2793 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, |
| (...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4279 } | 4295 } |
| 4280 | 4296 |
| 4281 PlatformFileInfoProto entry_file_info; | 4297 PlatformFileInfoProto entry_file_info; |
| 4282 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4298 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 4283 *entry_proto->mutable_file_info() = entry_file_info; | 4299 *entry_proto->mutable_file_info() = entry_file_info; |
| 4284 if (!callback.is_null()) | 4300 if (!callback.is_null()) |
| 4285 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4301 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 4286 } | 4302 } |
| 4287 | 4303 |
| 4288 } // namespace gdata | 4304 } // namespace gdata |
| OLD | NEW |