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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/search_operation.cc

Issue 16142003: Report all Drive search results even if resource metadata is not fully loaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/drive/file_system/search_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 scoped_ptr<google_apis::ResourceList> resource_list, 32 scoped_ptr<google_apis::ResourceList> resource_list,
33 std::vector<SearchResultInfo>* result) { 33 std::vector<SearchResultInfo>* result) {
34 DCHECK(resource_metadata); 34 DCHECK(resource_metadata);
35 DCHECK(result); 35 DCHECK(result);
36 36
37 const ScopedVector<google_apis::ResourceEntry>& entries = 37 const ScopedVector<google_apis::ResourceEntry>& entries =
38 resource_list->entries(); 38 resource_list->entries();
39 result->reserve(entries.size()); 39 result->reserve(entries.size());
40 for (size_t i = 0; i < entries.size(); ++i) { 40 for (size_t i = 0; i < entries.size(); ++i) {
41 ResourceEntry entry = ConvertToResourceEntry(*entries[i]); 41 ResourceEntry entry = ConvertToResourceEntry(*entries[i]);
42 base::FilePath drive_file_path; 42 const std::string id = entry.resource_id();
43 FileError error = resource_metadata->RefreshEntry( 43 FileError error = resource_metadata->RefreshEntry(entry, NULL, &entry);
44 entry, &drive_file_path, &entry); 44 if (error == FILE_ERROR_NOT_FOUND) {
45 if (error == FILE_ERROR_OK) { 45 // The result is absent in local resource metadata. This can happen if
46 result->push_back(SearchResultInfo(drive_file_path, entry)); 46 // the metadata is not synced to the latest server state yet. In that
47 } else if (error == FILE_ERROR_NOT_FOUND) { 47 // case, we temporarily add the file to the special "drive/other"
48 // The result is absent in local resource metadata. There are two cases: 48 // directory in order to assign a path, which is needed to access the
49 // file through FileSystem API.
49 // 50 //
50 // 1) Resource metadata is not up-to-date, and the entry has recently 51 // It will be moved to the right place when the metadata gets synced
51 // been added to the drive. This is not a fatal error, so just skip to 52 // in normal loading process in ChangeListProcessor.
52 // add the result. We should soon receive XMPP update notification 53 entry.set_parent_resource_id(util::kDriveOtherDirSpecialResourceId);
53 // and refresh both the metadata and search result UI in Files.app. 54 error = resource_metadata->AddEntry(entry);
54 // 55
55 // 2) Resource metadata is not fully loaded. 56 // FILE_ERROR_EXISTS may happen if we have already added the entry to
56 // TODO(kinaba) crbug.com/181075: 57 // "drive/other" once before. That's not an error.
57 // In this case, we are doing "fast fetch" fetching directory lists on 58 if (error == FILE_ERROR_OK || error == FILE_ERROR_EXISTS)
58 // the fly to quickly deliver results to the user. However, we have no 59 error = resource_metadata->GetResourceEntryById(id, &entry);
59 // such equivalent for Search. 60 }
60 } else { 61 // Other errors are fatal. Give up to return the search result.
61 // Otherwise, it is a fatal error. Give up to return the search result. 62 if (error != FILE_ERROR_OK)
62 return error; 63 return error;
63 } 64 result->push_back(SearchResultInfo(resource_metadata->GetFilePath(id),
65 entry));
64 } 66 }
65 67
66 return FILE_ERROR_OK; 68 return FILE_ERROR_OK;
67 } 69 }
68 70
69 } // namespace 71 } // namespace
70 72
71 SearchOperation::SearchOperation( 73 SearchOperation::SearchOperation(
72 base::SequencedTaskRunner* blocking_task_runner, 74 base::SequencedTaskRunner* blocking_task_runner,
73 JobScheduler* scheduler, 75 JobScheduler* scheduler,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (error != FILE_ERROR_OK) { 161 if (error != FILE_ERROR_OK) {
160 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); 162 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >());
161 return; 163 return;
162 } 164 }
163 165
164 callback.Run(error, next_feed, result.Pass()); 166 callback.Run(error, next_feed, result.Pass());
165 } 167 }
166 168
167 } // namespace file_system 169 } // namespace file_system
168 } // namespace drive 170 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698