OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
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 base::FilePath drive_file_path; |
43 FileError error = resource_metadata->RefreshEntry( | 43 FileError error = resource_metadata->RefreshEntry( |
44 entry, &drive_file_path, &entry); | 44 entry, &drive_file_path, &entry); |
45 if (error == FILE_ERROR_OK) { | 45 if (error == FILE_ERROR_NOT_FOUND) { |
46 result->push_back(SearchResultInfo(drive_file_path, entry)); | 46 // The result is absent in local resource metadata. This can happen if |
47 } else if (error == FILE_ERROR_NOT_FOUND) { | 47 // the metadata is not synced to the latest server state yet. In that |
48 // The result is absent in local resource metadata. There are two cases: | 48 // case, we temporarily add the file to the special "drive/other" |
49 // directory in order to assign a path, which is needed to access the | |
50 // file through FileSystem API. | |
49 // | 51 // |
50 // 1) Resource metadata is not up-to-date, and the entry has recently | 52 // It will be moved to the right place after |
hashimoto
2013/05/30 02:13:10
nit: Please make it clarify the timing when the ad
kinaba
2013/05/30 03:19:36
Done.
| |
51 // been added to the drive. This is not a fatal error, so just skip to | 53 entry.set_parent_resource_id(util::kDriveOtherDirSpecialResourceId); |
52 // add the result. We should soon receive XMPP update notification | 54 error = resource_metadata->AddEntry(entry); |
53 // and refresh both the metadata and search result UI in Files.app. | 55 if (error == FILE_ERROR_OK || error == FILE_ERROR_EXISTS) |
hashimoto
2013/05/30 02:13:10
IIRC, AddEntry does not return FILE_ERROR_EXISTS f
kinaba
2013/05/30 03:19:36
As chatted offline, this is for the case when the
| |
54 // | 56 resource_metadata->RefreshEntry(entry, &drive_file_path, &entry); |
hashimoto
2013/05/30 02:13:10
RefreshEntry here seems redandunt.
I think you mig
kinaba
2013/05/30 03:19:36
Done.
| |
55 // 2) Resource metadata is not fully loaded. | 57 } |
56 // TODO(kinaba) crbug.com/181075: | 58 // Otherwise, it is a fatal error. Give up to return the search result. |
57 // In this case, we are doing "fast fetch" fetching directory lists on | 59 if (error != FILE_ERROR_OK) |
58 // the fly to quickly deliver results to the user. However, we have no | |
59 // such equivalent for Search. | |
60 } else { | |
61 // Otherwise, it is a fatal error. Give up to return the search result. | |
62 return error; | 60 return error; |
63 } | 61 result->push_back(SearchResultInfo(drive_file_path, entry)); |
64 } | 62 } |
65 | 63 |
66 return FILE_ERROR_OK; | 64 return FILE_ERROR_OK; |
67 } | 65 } |
68 | 66 |
69 } // namespace | 67 } // namespace |
70 | 68 |
71 SearchOperation::SearchOperation( | 69 SearchOperation::SearchOperation( |
72 base::SequencedTaskRunner* blocking_task_runner, | 70 base::SequencedTaskRunner* blocking_task_runner, |
73 JobScheduler* scheduler, | 71 JobScheduler* scheduler, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 if (error != FILE_ERROR_OK) { | 157 if (error != FILE_ERROR_OK) { |
160 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); | 158 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); |
161 return; | 159 return; |
162 } | 160 } |
163 | 161 |
164 callback.Run(error, next_feed, result.Pass()); | 162 callback.Run(error, next_feed, result.Pass()); |
165 } | 163 } |
166 | 164 |
167 } // namespace file_system | 165 } // namespace file_system |
168 } // namespace drive | 166 } // namespace drive |
OLD | NEW |