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

Side by Side Diff: mojo/services/catalog/catalog.cc

Issue 1850543002: Add inline completion to quicklaunch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@58tv
Patch Set: . Created 4 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/services/catalog/catalog.h" 5 #include "mojo/services/catalog/catalog.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 int error = 0; 58 int error = 0;
59 std::string message; 59 std::string message;
60 // TODO(beng): probably want to do more detailed error checking. This should 60 // TODO(beng): probably want to do more detailed error checking. This should
61 // be done when figuring out if to unblock connection completion. 61 // be done when figuring out if to unblock connection completion.
62 scoped_ptr<ReadManifestResult> result(new ReadManifestResult); 62 scoped_ptr<ReadManifestResult> result(new ReadManifestResult);
63 result->manifest_root = deserializer.Deserialize(&error, &message); 63 result->manifest_root = deserializer.Deserialize(&error, &message);
64 result->package_dir = system_package_dir; 64 result->package_dir = system_package_dir;
65 return result; 65 return result;
66 } 66 }
67 67
68 void AddEntryToMap(const Entry& entry,
69 mojo::Map<mojo::String, mojom::CatalogEntryPtr>* map) {
70 mojom::CatalogEntryPtr entry_ptr(mojom::CatalogEntry::New());
71 entry_ptr->display_name = entry.display_name();
72 (*map)[entry.name()] = std::move(entry_ptr);
73 }
74
68 } // namespace 75 } // namespace
69 76
70 ReadManifestResult::ReadManifestResult() {} 77 ReadManifestResult::ReadManifestResult() {}
71 ReadManifestResult::~ReadManifestResult() {} 78 ReadManifestResult::~ReadManifestResult() {}
72 79
73 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
74 // Catalog, public: 81 // Catalog, public:
75 82
76 Catalog::Catalog(scoped_ptr<Store> store, 83 Catalog::Catalog(scoped_ptr<Store> store,
77 base::TaskRunner* file_task_runner, 84 base::TaskRunner* file_task_runner,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(), 159 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(),
153 mojo_name, callback)); 160 mojo_name, callback));
154 } 161 }
155 162
156 //////////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////////
157 // Catalog, mojom::Catalog: 164 // Catalog, mojom::Catalog:
158 165
159 void Catalog::GetEntries(mojo::Array<mojo::String> names, 166 void Catalog::GetEntries(mojo::Array<mojo::String> names,
160 const GetEntriesCallback& callback) { 167 const GetEntriesCallback& callback) {
161 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; 168 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries;
162 std::vector<mojo::String> names_vec = names.PassStorage(); 169 if (names.is_null()) {
163 for (const std::string& name : names_vec) { 170 for (const auto& entry : user_catalog_)
164 Entry* entry = nullptr; 171 AddEntryToMap(*entry.second, &entries);
165 if (user_catalog_.find(name) != user_catalog_.end()) 172 for (const auto& entry : *system_catalog_)
166 entry = user_catalog_[name].get(); 173 AddEntryToMap(*entry.second, &entries);
167 else if (system_catalog_->find(name) != system_catalog_->end()) 174 } else {
168 entry = (*system_catalog_)[name].get(); 175 std::vector<mojo::String> names_vec = names.PassStorage();
169 else 176 for (const std::string& name : names_vec) {
170 continue; 177 Entry* entry = nullptr;
171 mojom::CatalogEntryPtr entry_ptr(mojom::CatalogEntry::New()); 178 if (user_catalog_.find(name) != user_catalog_.end())
172 entry_ptr->display_name = entry->display_name(); 179 entry = user_catalog_[name].get();
173 entries[entry->name()] = std::move(entry_ptr); 180 else if (system_catalog_->find(name) != system_catalog_->end())
181 entry = (*system_catalog_)[name].get();
182 else
183 continue;
184 AddEntryToMap(*entry, &entries);
185 }
174 } 186 }
175 callback.Run(std::move(entries)); 187 callback.Run(std::move(entries));
176 } 188 }
177 189
178 //////////////////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////////////
179 // Catalog, private: 191 // Catalog, private:
180 192
181 void Catalog::DeserializeCatalog() { 193 void Catalog::DeserializeCatalog() {
182 if (!store_) 194 if (!store_)
183 return; 195 return;
(...skipping 29 matching lines...) Expand all
213 if (result->manifest_root) { 225 if (result->manifest_root) {
214 const base::DictionaryValue* dictionary = nullptr; 226 const base::DictionaryValue* dictionary = nullptr;
215 CHECK(result->manifest_root->GetAsDictionary(&dictionary)); 227 CHECK(result->manifest_root->GetAsDictionary(&dictionary));
216 entry = Entry::Deserialize(*dictionary); 228 entry = Entry::Deserialize(*dictionary);
217 } 229 }
218 entry->set_path(GetPackagePath(result->package_dir, name)); 230 entry->set_path(GetPackagePath(result->package_dir, name));
219 231
220 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry)); 232 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry));
221 if (catalog) { 233 if (catalog) {
222 catalog->AddEntryToCatalog( 234 catalog->AddEntryToCatalog(
223 std::move(entry), 235 std::move(entry), result->package_dir == catalog->system_package_dir_);
224 result->package_dir == catalog->system_package_dir_);
225 } 236 }
226 } 237 }
227 238
228 void Catalog::AddEntryToCatalog(scoped_ptr<Entry> entry, 239 void Catalog::AddEntryToCatalog(scoped_ptr<Entry> entry,
229 bool is_system_catalog) { 240 bool is_system_catalog) {
230 DCHECK(entry); 241 DCHECK(entry);
231 EntryCache* catalog = is_system_catalog ? system_catalog_ : &user_catalog_; 242 EntryCache* catalog = is_system_catalog ? system_catalog_ : &user_catalog_;
232 if (catalog->end() != catalog->find(entry->name())) 243 if (catalog->end() != catalog->find(entry->name()))
233 return; 244 return;
234 for (auto child : entry->applications()) 245 for (auto child : entry->applications())
235 AddEntryToCatalog(make_scoped_ptr(child), is_system_catalog); 246 AddEntryToCatalog(make_scoped_ptr(child), is_system_catalog);
236 (*catalog)[entry->name()] = std::move(entry); 247 (*catalog)[entry->name()] = std::move(entry);
237 SerializeCatalog(); 248 SerializeCatalog();
238 } 249 }
239 250
240 } // namespace catalog 251 } // namespace catalog
OLDNEW
« no previous file with comments | « mash/quick_launch/quick_launch_application.cc ('k') | mojo/services/catalog/public/interfaces/catalog.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698